Search in sources :

Example 56 with HttpResponse

use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.

the class HttpsResponseTest method getHeaderFieldRejectsInvalidFieldName.

// Tests_SRS_SERVICE_SDK_JAVA_HTTPSRESPONSE_12_006: [If a value could not be found for the given header field name, the function shall throw an IllegalArgumentException.]
// Assert
@Test(expected = IllegalArgumentException.class)
public void getHeaderFieldRejectsInvalidFieldName() throws IllegalArgumentException {
    // 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";
    // Act
    HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
    response.getHeaderField(field);
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 57 with HttpResponse

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

Aggregations

HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)57 Test (org.junit.Test)44 HashMap (java.util.HashMap)28 List (java.util.List)28 URL (java.net.URL)26 HttpRequest (com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest)16 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)10 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)9 LinkedList (java.util.LinkedList)8 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)7 IOException (java.io.IOException)7 IotHubBadFormatException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubBadFormatException)4 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 IotHubExceptionManager (com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager)2 MethodParser (com.microsoft.azure.sdk.iot.deps.serializer.MethodParser)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1