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));
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getErrorReasonReturnsErrorReason.
// 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_007: [The function shall return the error reason given in the constructor.]
@Test
public void getErrorReasonReturnsErrorReason() {
// Arrange
final int status = 200;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = { 2, 3, 4, 5 };
final byte[] expectedErrorReason = errorReason;
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
byte[] testErrorReason = response.getErrorReason();
// Assert
assertThat(testErrorReason, is(expectedErrorReason));
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getBodyReturnsCopyOfBody.
// 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_003: [The function shall return a copy of the body given in the constructor.]
@Test
public void getBodyReturnsCopyOfBody() {
// Arrange
final int status = 200;
final byte[] body = { 1, 2, 3, 4 };
final Map<String, List<String>> headerFields = new HashMap<>();
byte[] errorReason = {};
final byte[] expectedBody = body;
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
byte[] testBody = response.getBody();
// Assert
assertThat(testBody, is(expectedBody));
testBody[0] = 3;
assertThat(testBody, is(not(expectedBody)));
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_404.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_004: [The function shall throw IotHubNotFoundException if the Http response status equal 404]
// Assert
@Test(expected = IotHubNotFoundException.class)
public void httpResponseVerification_404() throws IotHubException {
// Arrange
final int status = 404;
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);
}
Aggregations