Search in sources :

Example 6 with HttpsResponse

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.

the class HttpsResponseTest method getHeaderFieldMatchesCaseInsensitive.

// Tests_SRS_HTTPSRESPONSE_11_008: [The function shall match the header field name in a case-insensitive manner.]
@Test
public void getHeaderFieldMatchesCaseInsensitive() {
    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";
    values.add(value0);
    values.add(value1);
    headerFields.put(field, values);
    HttpsResponse response = new HttpsResponse(status, body, headerFields, errorReason);
    String differentCaseField = "Test-Field";
    String testValues = response.getHeaderField(differentCaseField);
    final String expectedValues = value0 + "," + value1;
    assertThat(testValues, is(expectedValues));
}
Also used : HashMap(java.util.HashMap) HttpsResponse(com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with HttpsResponse

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.

the class HttpsResponseTest method getHeaderFieldRejectsInvalidFieldName.

// Tests_SRS_HTTPSRESPONSE_11_006: [If a value could not be found for the given header field name, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void getHeaderFieldRejectsInvalidFieldName() throws IllegalArgumentException {
    final int status = 200;
    final byte[] body = { 1 };
    final byte[] errorReason = {};
    final Map<String, List<String>> headerFields = new HashMap<>();
    final String field = "test-field";
    HttpsResponse response = new HttpsResponse(status, body, headerFields, errorReason);
    response.getHeaderField(field);
}
Also used : HashMap(java.util.HashMap) HttpsResponse(com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 8 with HttpsResponse

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.

the class HttpsResponseTest method getStatusReturnsStatus.

// Tests_SRS_HTTPSRESPONSE_11_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_11_002: [The function shall return the status code given in the constructor.]
@Test
public void getStatusReturnsStatus() {
    final int status = 200;
    final byte[] body = { 1 };
    final Map<String, List<String>> headerFields = new HashMap<>();
    final byte[] errorReason = {};
    HttpsResponse response = new HttpsResponse(status, body, headerFields, errorReason);
    int testStatus = response.getStatus();
    final int expectedStatus = status;
    assertThat(testStatus, is(expectedStatus));
}
Also used : HashMap(java.util.HashMap) HttpsResponse(com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with HttpsResponse

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.

the class HttpsResponseTest method getErrorReasonReturnsErrorReason.

// Tests_SRS_HTTPSRESPONSE_11_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_11_007: [The function shall return the error reason given in the constructor.]
@Test
public void getErrorReasonReturnsErrorReason() {
    final int status = 200;
    final byte[] body = { 1 };
    final Map<String, List<String>> headerFields = new HashMap<>();
    final byte[] errorReason = { 2, 3, 4, 5 };
    HttpsResponse response = new HttpsResponse(status, body, headerFields, errorReason);
    byte[] testErrorReason = response.getErrorReason();
    final byte[] expectedErrorReason = errorReason;
    assertThat(testErrorReason, is(expectedErrorReason));
}
Also used : HashMap(java.util.HashMap) HttpsResponse(com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with HttpsResponse

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.

the class HttpsResponseTest method getBodyReturnsCopyOfBody.

// Tests_SRS_HTTPSRESPONSE_11_001: [The constructor shall store the input arguments so that the getters can return them later.]
// Tests_SRS_HTTPSRESPONSE_11_003: [The function shall return a copy of the body given in the constructor.]
@Test
public void getBodyReturnsCopyOfBody() {
    final int status = 200;
    final byte[] body = { 1, 2, 3, 4 };
    final Map<String, List<String>> headerFields = new HashMap<>();
    byte[] errorReason = {};
    HttpsResponse response = new HttpsResponse(status, body, headerFields, errorReason);
    byte[] testBody = response.getBody();
    final byte[] expectedBody = body;
    assertThat(testBody, is(expectedBody));
    testBody[0] = 3;
    assertThat(testBody, is(not(expectedBody)));
}
Also used : HashMap(java.util.HashMap) HttpsResponse(com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

HttpsResponse (com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 List (java.util.List)8 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)7 HttpsRequest (com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest)7 IOException (java.io.IOException)3 URL (java.net.URL)1