use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorThrowsIoExceptionIfCannotSetupConnection.
// Tests_SRS_HTTPSREQUEST_11_005: [If an IOException occurs in setting up the HTTPS connection, the function shall throw an IOException.]
@Test(expected = IOException.class)
public void constructorThrowsIoExceptionIfCannotSetupConnection(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
new HttpsConnection(mockUrl, httpsMethod);
result = new IOException();
}
};
new HttpsRequest(mockUrl, httpsMethod, body);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod 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.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setSSLContextSetsSSLContext.
//Tests_SRS_HTTPSREQUEST_25_016: [The function shall set the SSL context for the IotHub.]
@Test
public void setSSLContextSetsSSLContext(@Mocked final HttpsConnection mockConn, @Mocked final IotHubSSLContext mockedContext) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
request.setSSLContext(mockedContext);
new Verifications() {
{
Deencapsulation.invoke(mockConn, "setSSLContext", mockedContext.getIotHubSSlContext());
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod 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));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorWritesBodyToConnection.
// Tests_SRS_HTTPSREQUEST_11_002: [The function shall write the body to the connection.]
@Test
public void constructorWritesBodyToConnection(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
new HttpsRequest(mockUrl, httpsMethod, body);
final byte[] expectedBody = body;
new Verifications() {
{
new HttpsConnection(mockUrl, (HttpsMethod) any).writeOutput(expectedBody);
}
};
}
Aggregations