Search in sources :

Example 31 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method replaceTagsThrowsIfDeviceIDIsNull.

@Test(expected = IllegalArgumentException.class)
public void replaceTagsThrowsIfDeviceIDIsNull() throws Exception {
    //arrange
    final String connectionString = "testString";
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = null;
        }
    };
    //act
    testTwin.replaceTags(mockedDevice);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) NonStrictExpectations(mockit.NonStrictExpectations) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 32 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method constructorRejectsNonHttpsUrl.

// Tests_SRS_HTTPSCONNECTION_11_022: [If the URI given does not use the HTTPS protocol, the constructor shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void constructorRejectsNonHttpsUrl() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "http";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
        }
    };
    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) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 33 with NonStrictExpectations

use of mockit.NonStrictExpectations 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 {
    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) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 34 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class HttpsConnectionTest method setSSLContextSetsContext.

//Tests_SRS_HTTPSCONNECTION_25_024: [**The function shall set the the SSL context with the given value.**]**
@Test
public void setSSLContextSetsContext(@Mocked final SSLContext mockedContext) throws IOException {
    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();
        }
    };
    final HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    Deencapsulation.invoke(conn, "setSSLContext", mockedContext);
    new Verifications() {

        {
            mockUrlConn.setSSLSocketFactory(mockedContext.getSocketFactory());
            times = 1;
        }
    };
}
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 35 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class HttpsIotHubConnectionTest method receiveMessageThrowsIOExceptionIfRequestFails.

// Tests_SRS_HTTPSIOTHUBCONNECTION_11_023: [If the IoT Hub could not be reached, the function shall throw an IOException.]
@Test(expected = IOException.class)
public void receiveMessageThrowsIOExceptionIfRequestFails(@Mocked final IotHubMessageUri mockUri) throws IOException {
    new NonStrictExpectations() {

        {
            mockRequest.send();
            result = new IOException();
        }
    };
    HttpsIotHubConnection conn = new HttpsIotHubConnection(mockConfig);
    conn.receiveMessage();
}
Also used : IOException(java.io.IOException) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

NonStrictExpectations (mockit.NonStrictExpectations)492 Test (org.junit.Test)472 Verifications (mockit.Verifications)154 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)77 IOException (java.io.IOException)64 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)51 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)51 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)47 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)32 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)31 HttpConnection (com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection)26 HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)26 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)26 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)26 HashMap (java.util.HashMap)26 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)25 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)17 Date (java.util.Date)16 HashSet (java.util.HashSet)16 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)15