use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendReturnsError.
// Tests_SRS_HTTPSREQUEST_11_009: [The function shall return the HTTPS response received, including the status code, body, header fields, and error reason (if any).]
// Tests_SRS_HTTPSREQUEST_11_012: [If an I/O exception occurs because of a bad response status code, the function shall attempt to flush or read the error stream so that the underlying HTTPS connection can be reused.]
@Test
public void sendReturnsError(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
final byte[] error = { 5, 6, 7, 0, 1 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockConn.connect();
result = new IOException();
mockConn.readError();
result = error;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
HttpsResponse response = request.send();
byte[] testError = response.getErrorReason();
final byte[] expectedError = error;
assertThat(testError, is(expectedError));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendReturnsBody.
// Tests_SRS_HTTPSREQUEST_11_009: [The function shall return the HTTPS response received, including the status code, body, header fields, and error reason (if any).]
@Test
public void sendReturnsBody(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] requestBody = new byte[0];
final byte[] responseBody = { 1, 2, 3, 0, 4 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockConn.readInput();
result = responseBody;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, requestBody);
HttpsResponse response = request.send();
byte[] testBody = response.getBody();
final byte[] expectedBody = responseBody;
assertThat(testBody, is(expectedBody));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendReturnsHeaderFields.
// Tests_SRS_HTTPSREQUEST_11_009: [The function shall return the HTTPS response received, including the status code, body, header fields, and error reason (if any).]
@Test
public void sendReturnsHeaderFields(@Mocked final HttpsConnection mockConn) throws IOException {
final Map<String, List<String>> headerFields = new HashMap<>();
final String field = "test-field";
final List<String> values = new LinkedList<>();
final String value0 = "test-value0";
final String value1 = "test-value1";
values.add(value0);
values.add(value1);
headerFields.put(field, values);
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockConn.getResponseHeaders();
result = headerFields;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
HttpsResponse response = request.send();
String testValues = response.getHeaderField(field);
final String expectedValues = value0 + "," + value1;
assertThat(testValues, is(expectedValues));
}
Aggregations