Search in sources :

Example 31 with HttpsRequest

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);
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) HttpsRequest(com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest) URL(java.net.URL) Test(org.junit.Test)

Example 32 with HttpsRequest

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);
        }
    };
}
Also used : HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) HttpsRequest(com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest) Test(org.junit.Test)

Example 33 with HttpsRequest

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);
}
Also used : HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) HttpsRequest(com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest) URL(java.net.URL) Test(org.junit.Test)

Example 34 with HttpsRequest

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();
}
Also used : HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) HttpsRequest(com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest) URL(java.net.URL) Test(org.junit.Test)

Example 35 with HttpsRequest

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));
}
Also used : HttpsResponse(com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) HttpsRequest(com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest) URL(java.net.URL) Test(org.junit.Test)

Aggregations

HttpsRequest (com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest)40 Test (org.junit.Test)39 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)35 URL (java.net.URL)23 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)13 HttpsResponse (com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse)11 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 ProxySettings (com.microsoft.azure.sdk.iot.device.ProxySettings)2 Map (java.util.Map)1