Search in sources :

Example 11 with HttpsMethod

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

the class HttpsConnectionTest method readErrorReturnsEmptyErrorReasonIfNoErrorReason.

// Tests_SRS_HTTPSCONNECTION_11_013: [The function shall read from the error stream and return the response.]
@Test
public void readErrorReturnsEmptyErrorReasonIfNoErrorReason() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.GET;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
            mockUrlConn.getErrorStream();
            result = null;
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.connect();
    byte[] testError = conn.readError();
    byte[] expectedError = {};
    assertThat(testError, is(expectedError));
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 12 with HttpsMethod

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

the class HttpsConnectionTest method constructorOpensConnection.

// Tests_SRS_HTTPSCONNECTION_11_001: [The constructor shall open a connection to the given URL.]
@Test
public void constructorOpensConnection() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

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

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

Example 13 with HttpsMethod

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

the class HttpsConnectionTest method setRequestHeaderSetsRequestHeader.

// Tests_SRS_HTTPSCONNECTION_11_008: [The function shall set the given request header field.]
@Test
public void setRequestHeaderSetsRequestHeader() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.POST;
    final String field = "test-field";
    final String value = "test-value";
    new NonStrictExpectations() {

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

        {
            mockUrl.openConnection().setRequestProperty(field, value);
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 14 with HttpsMethod

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

the class HttpsConnectionTest method constructorSetsRequestMethod.

// Tests_SRS_HTTPSCONNECTION_11_021: [The constructor shall set the HTTPS method to the given method.]
@Test
public void constructorSetsRequestMethod() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

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

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

Example 15 with HttpsMethod

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

the class HttpsConnectionTest method readErrorFailsIfCannotAccessErrorStream.

// Tests_SRS_HTTPSCONNECTION_11_014: [The function shall throw an IOException if the error stream could not be accessed.]
@Test(expected = IOException.class)
public void readErrorFailsIfCannotAccessErrorStream() throws IOException {
    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) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)45 Test (org.junit.Test)45 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)30 NonStrictExpectations (mockit.NonStrictExpectations)26 HttpsRequest (com.microsoft.azure.sdk.iot.device.transport.https.HttpsRequest)19 IOException (java.io.IOException)11 Verifications (mockit.Verifications)10 HttpsResponse (com.microsoft.azure.sdk.iot.device.transport.https.HttpsResponse)7 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 URL (java.net.URL)4 Map (java.util.Map)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1