Search in sources :

Example 71 with HttpsConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method constructorThrowsIoExceptionIfCannotOpenConnection.

// Tests_SRS_HTTPSCONNECTION_11_002: [The constructor shall throw a TransportException if the connection was unable to be opened.]
@Test(expected = TransportException.class)
public void constructorThrowsIoExceptionIfCannotOpenConnection() throws IOException, TransportException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = new IOException();
        }
    };
    new HttpsConnection(mockUrl, httpsMethod);
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) IOException(java.io.IOException) Test(org.junit.Test)

Example 72 with HttpsConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method connectUsesCorrectUrl.

// Tests_SRS_HTTPSCONNECTION_11_003: [The function shall send a request to the URL given in the constructor.]
@Test
public void connectUsesCorrectUrl() throws IOException, TransportException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.connect();
    new Verifications() {

        {
            mockUrl.openConnection().connect();
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Test(org.junit.Test)

Example 73 with HttpsConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method readInputClosesInputStream.

// Tests_SRS_HTTPSCONNECTION_11_019: [The function shall close the input stream after it has been completely read.]
@Test
public void readInputClosesInputStream(@Mocked final InputStream mockIs) throws IOException, TransportException {
    final HttpsMethod httpsMethod = HttpsMethod.GET;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
            mockUrlConn.getInputStream();
            result = mockIs;
            mockIs.read();
            result = -1;
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.connect();
    conn.readInput();
    new Verifications() {

        {
            mockIs.close();
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Test(org.junit.Test)

Example 74 with HttpsConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method readErrorFailsIfCannotAccessErrorStream.

// Tests_SRS_HTTPSCONNECTION_11_014: [The function shall throw a TransportException if the error stream could not be accessed.]
@Test(expected = TransportException.class)
public void readErrorFailsIfCannotAccessErrorStream() throws IOException, TransportException {
    final HttpsMethod httpsMethod = HttpsMethod.GET;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
            mockUrlConn.getErrorStream();
            result = new IOException();
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.connect();
    conn.readError();
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) IOException(java.io.IOException) Test(org.junit.Test)

Example 75 with HttpsConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method setReadTimeoutSetsRequestTimeout.

// Tests_SRS_HTTPSCONNECTION_11_023: [The function shall set the read timeout to the given value.]
@Test
public void setReadTimeoutSetsRequestTimeout() throws IOException, TransportException {
    final HttpsMethod httpsMethod = HttpsMethod.POST;
    final String field = "test-field";
    final String value = "test-value";
    final int timeout = 1;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.setReadTimeout(timeout);
    new Verifications() {

        {
            mockUrl.openConnection().setReadTimeout(timeout);
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Test(org.junit.Test)

Aggregations

HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)75 Test (org.junit.Test)75 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)73 NonStrictExpectations (mockit.NonStrictExpectations)26 HttpsRequest (com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest)13 IOException (java.io.IOException)13 Verifications (mockit.Verifications)10 URL (java.net.URL)9 TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 HttpProxySocketFactory (com.microsoft.azure.sdk.iot.device.transport.HttpProxySocketFactory)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1