use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getHeaderFieldReturnsHeaderField.
// 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_004: [The function shall return a comma-separated list of the values associated with the header field name.]
@Test
public void getHeaderFieldReturnsHeaderField() {
// Arrange
final int status = 200;
final byte[] body = { 1 };
final byte[] errorReason = {};
final Map<String, List<String>> headerFields = new HashMap<>();
final String field = "test-field";
final List<String> values = new LinkedList<>();
final String value0 = "test-field-value0";
final String value1 = "test-field-value1";
final String expectedValues = value0 + "," + value1;
values.add(value0);
values.add(value1);
headerFields.put(field, values);
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
String testValues = response.getHeaderField(field);
// Assert
assertThat(testValues, is(expectedValues));
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_403.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_003: [The function shall throw IotHubTooManyDevicesException if the Http response status equal 403]
// Assert
@Test(expected = IotHubTooManyDevicesException.class)
public void httpResponseVerification_403() throws IotHubException {
// Arrange
final int status = 403;
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_412.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_005: [The function shall throw IotHubPreconditionFailedException if the Http response status equal 412]
// Assert
@Test(expected = IotHubPreconditionFailedException.class)
public void httpResponseVerification_412() throws IotHubException {
// Arrange
final int status = 412;
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_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);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class IotHubExceptionManagerTest method httpResponseVerification_429.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_006: [The function shall throw IotHubTooManyRequestsException if the Http response status equal 429]
// Assert
@Test(expected = IotHubTooManyRequestsException.class)
public void httpResponseVerification_429() throws IotHubException {
// Arrange
final int status = 429;
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