Search in sources :

Example 1 with IotHubExceptionManager

use of com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager in project azure-iot-sdk-java by Azure.

the class IotHubExceptionManagerTest method httpResponseVerification_300.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_012: [The function shall return without exception if the response status equal or less than 300]
@Test
public void httpResponseVerification_300() throws IotHubException {
    // Arrange
    final int status = 300;
    final byte[] body = { 1 };
    final Map<String, List<String>> headerFields = new HashMap<>();
    final byte[] errorReason = { 123, 125 };
    HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
    // Act
    IotHubExceptionManager.httpResponseVerification(response);
    IotHubException iotHubException = new IotHubException();
    IotHubExceptionManager iotHubExceptionManager = new IotHubExceptionManager();
    // Assert
    assertNotEquals(null, iotHubException);
    assertNotEquals(null, iotHubExceptionManager);
}
Also used : IotHubExceptionManager(com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager) HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse) List(java.util.List) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 2 with IotHubExceptionManager

use of com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager in project azure-iot-sdk-java by Azure.

the class IotHubExceptionManagerTest method httpResponseVerification_301_withErrorReason.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_21_013: [If the httpresponse contains a reason message, the function must print this reason in the error message]
// Assert
@Test
public void httpResponseVerification_301_withErrorReason() throws IotHubException {
    // Arrange
    final int status = 301;
    final byte[] body = { 1 };
    final Map<String, List<String>> headerFields = new HashMap<>();
    final byte[] errorReason = "{\"ExceptionMessage\":\"This is the error message\"}".getBytes();
    HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
    // Act
    try {
        IotHubExceptionManager.httpResponseVerification(response);
        assert true;
    } catch (IotHubException expected) {
        // Expected throw.
        assertThat(expected.getMessage(), is("This is the error message"));
    }
    IotHubException iotHubException = new IotHubException("error message");
    IotHubExceptionManager iotHubExceptionManager = new IotHubExceptionManager();
    // Assert
    assertNotEquals(null, iotHubException);
    assertNotEquals(null, iotHubExceptionManager);
}
Also used : IotHubExceptionManager(com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager) HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse) List(java.util.List) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Aggregations

IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 IotHubExceptionManager (com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager)2 HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2