use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorOpensConnection.
// Tests_SRS_HTTPSREQUEST_11_001: [The function shall open a connection with the given URL as the endpoint.]
@Test
public void constructorOpensConnection(@Mocked final HttpsConnection mockConn) throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
final URL mockUrl = new URL("https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body, "");
request.send();
new Verifications() {
{
new HttpsConnection(mockUrl, (HttpsMethod) any, null, true);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest 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 SSLContext mockedContext, @Mocked final URL mockUrl) throws TransportException {
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);
request.send();
new Verifications() {
{
Deencapsulation.invoke(mockConn, "setSSLContext", mockedContext);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setSSLContextThrowsOnNull.
// Tests_SRS_HTTPSREQUEST_25_015: [The function shall throw IllegalArgumentException if argument is null.]
@Test(expected = IllegalArgumentException.class)
public void setSSLContextThrowsOnNull(@Mocked final HttpsConnection mockConn) throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
final URL mockUrl = new URL("https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body, "");
request.setSSLContext(null);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendHasCorrectHttpsMethod.
// Tests_SRS_HTTPSREQUEST_11_008: [The function shall send an HTTPS request as formatted in the constructor.]
@Test
public void sendHasCorrectHttpsMethod() throws TransportException, MalformedURLException {
final HttpsMethod expectedMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
URL mockUrl = new URL("https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, expectedMethod, body, "");
request.send();
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest 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 (if 200 status code), header fields, and error reason (if any).]
@Test
public void sendReturnsBody(@Mocked final HttpsConnection mockConn) throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] requestBody = new byte[0];
final byte[] responseBody = { 1, 2, 3, 0, 4 };
final URL mockUrl = new URL("https://www.microsoft.com");
new NonStrictExpectations() {
{
mockConn.readInput();
result = responseBody;
mockConn.getResponseStatus();
result = 200;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, requestBody, "");
HttpsResponse response = request.send();
byte[] testBody = response.getBody();
assertThat(testBody, is(responseBody));
}
Aggregations