Search in sources :

Example 21 with HttpResponse

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));
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with HttpResponse

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)));
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 23 with HttpResponse

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));
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with HttpResponse

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));
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 25 with HttpResponse

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;
}
Also used : HttpResponse(com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)

Aggregations

HttpResponse (com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)26 Test (org.junit.Test)12 HttpRequest (com.microsoft.azure.sdk.iot.deps.transport.http.HttpRequest)10 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)8 List (java.util.List)8 ProvisioningServiceClientServiceException (com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientServiceException)7 IOException (java.io.IOException)7 HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)6 URL (java.net.URL)4 UrlPathBuilder (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.UrlPathBuilder)3 ResponseData (com.microsoft.azure.sdk.iot.provisioning.device.internal.task.ResponseData)3 DeviceRegistrationParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser)2 EnrollmentGroup (com.microsoft.azure.sdk.iot.provisioning.service.configs.EnrollmentGroup)2 TpmRegistrationResultParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.TpmRegistrationResultParser)1 ProvisioningConnectionString (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString)1 ProvisioningSasToken (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken)1 AttestationMechanism (com.microsoft.azure.sdk.iot.provisioning.service.configs.AttestationMechanism)1 DeviceRegistrationState (com.microsoft.azure.sdk.iot.provisioning.service.configs.DeviceRegistrationState)1 QueryResult (com.microsoft.azure.sdk.iot.provisioning.service.configs.QueryResult)1