use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_503.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_009: [The function shall throw IotHubServerBusyException if the Http response status equal 503]
// Assert
@Test(expected = IotHubServerBusyException.class)
public void httpResponseVerification_503() throws IotHubException {
// Arrange
final int status = 503;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = { 2, 3, 4, 5 };
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
// Act
IotHubExceptionManager.httpResponseVerification(response);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_400.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_001: [The function shall throw IotHubBadFormatException if the Http response status equal 400]
// Assert
@Test(expected = IotHubBadFormatException.class)
public void httpResponseVerification_400() throws IotHubException {
// Arrange
final int status = 400;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = { 2, 3, 4, 5 };
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
// Act
IotHubExceptionManager.httpResponseVerification(response);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_400_withEmptyErrorReason.
// 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_400_withEmptyErrorReason() throws IotHubException {
// Arrange
final int status = 400;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = "{\"ExceptionMessage\":}".getBytes();
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
// Act
try {
IotHubExceptionManager.httpResponseVerification(response);
assert true;
} catch (IotHubBadFormatException expected) {
// Expected throw.
assertThat(expected.getMessage(), is("Bad message format!"));
}
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_500.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_007: [The function shall throw IotHubInternalServerErrorException if the Http response status equal 500]
// Assert
@Test(expected = IotHubInternalServerErrorException.class)
public void httpResponseVerification_500() throws IotHubException {
// Arrange
final int status = 500;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = { 2, 3, 4, 5 };
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
// Act
IotHubExceptionManager.httpResponseVerification(response);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getStatusReturnsStatus.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSRESPONSE_12_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSRESPONSE_12_002: [The function shall return the status code given in the constructor.]
@Test
public void getStatusReturnsStatus() {
// Arrange
final int status = 200;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = {};
final int expectedStatus = status;
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
int testStatus = response.getStatus();
// Assert
assertThat(testStatus, is(expectedStatus));
}
Aggregations