use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getStatusReturnsStatus.
// Tests_SRS_HTTPSRESPONSE_25_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_25_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 = {};
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
int testStatus = response.getStatus();
// Assert
assertThat(testStatus, is(status));
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getBodyReturnsCopyOfBody.
// Tests_SRS_HTTPSRESPONSE_25_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_25_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 = {};
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
byte[] testBody = response.getBody();
// Assert
assertThat(testBody, is(body));
testBody[0] = 3;
assertThat(testBody, is(not(body)));
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getHeaderFieldReturnsHeaderField.
// Tests_SRS_HTTPSRESPONSE_25_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_25_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.deps.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class HttpsResponseTest method getErrorReasonReturnsErrorReason.
// Tests_SRS_HTTPSRESPONSE_25_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_25_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 };
// Act
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
byte[] testErrorReason = response.getErrorReason();
// Assert
assertThat(testErrorReason, is(errorReason));
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class ContractAPIHttp method sendRequest.
private HttpResponse sendRequest(HttpRequest request) throws ProvisioningDeviceHubException, IOException {
HttpResponse response = request.send();
log.trace("Provisioning device client received http response with status {}", response.getStatus());
ProvisioningDeviceClientExceptionManager.verifyHttpResponse(response);
return response;
}
Aggregations