Search in sources :

Example 1 with HttpsIotHubConnection

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

the class HttpsTransportManagerTest method openSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_003: [The open shall create and store a new transport connection `HttpsIotHubConnection`.] */
@Test
public void openSucceed() {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
            result = httpsIotHubConnection;
            times = 1;
        }
    };
    // act
    Deencapsulation.invoke(httpsTransportManager, "open");
    // assert
    assertNotNull(Deencapsulation.getField(httpsTransportManager, "httpsIotHubConnection"));
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) Test(org.junit.Test)

Example 2 with HttpsIotHubConnection

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

the class HttpsTransportManagerTest method openWithTopicsSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_004: [The open shall create and store a new transport connection `HttpsIotHubConnection`.] */
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_005: [The open shall ignore the parameter `topics`.] */
@Test
public void openWithTopicsSucceed() {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    final String[] topics = new String[] { "a", "b" };
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
            result = httpsIotHubConnection;
            times = 1;
        }
    };
    // act
    Deencapsulation.invoke(httpsTransportManager, "open", new Class<?>[] { String[].class }, (Object) topics);
    // assert
    assertNotNull(Deencapsulation.getField(httpsTransportManager, "httpsIotHubConnection"));
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) Test(org.junit.Test)

Example 3 with HttpsIotHubConnection

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

the class HttpsTransportManagerTest method sendSendHttpsMessageThrows.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_014: [If `sendHttpsMessage` failed, the send shall bypass the exception.] */
@Test(expected = IOException.class)
public void sendSendHttpsMessageThrows() throws IOException, TransportException {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    final String uriPath = "/files/notifications";
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
            result = httpsIotHubConnection;
            Deencapsulation.invoke(HttpsSingleMessage.class, "parseHttpsJsonMessage", new Class[] { Message.class }, mockTransportMsg);
            result = mockHttpsMessage;
            mockTransportMsg.getIotHubMethod();
            result = IotHubMethod.POST;
            mockTransportMsg.getUriPath();
            result = uriPath;
            httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, (HttpsMethod) any, (String) any, (Map) any);
            result = new IOException();
        }
    };
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    Deencapsulation.invoke(httpsTransportManager, "open");
    // act
    Deencapsulation.invoke(httpsTransportManager, "send", new Class[] { IotHubTransportMessage.class, Map.class }, mockTransportMsg, new HashMap<String, String>());
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with HttpsIotHubConnection

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

the class HttpsTransportManagerTest method closeSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_006: [The close shall destroy the transport connection `HttpsIotHubConnection`.] */
@Test
public void closeSucceed() {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    // act
    Deencapsulation.invoke(httpsTransportManager, "close");
    // assert
    assertNull(Deencapsulation.getField(httpsTransportManager, "httpsIotHubConnection"));
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) Test(org.junit.Test)

Example 5 with HttpsIotHubConnection

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

the class HttpsTransportManagerTest method sendCreateHttpMessageSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_007: [The send shall create a new instance of the `HttpMessage`, by parsing the Message with `parseHttpsJsonMessage` from `HttpsSingleMessage`.] */
@Test
public void sendCreateHttpMessageSucceed() throws IOException, TransportException {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    final String uriPath = "/files/notifications";
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
            result = httpsIotHubConnection;
            Deencapsulation.invoke(HttpsSingleMessage.class, "parseHttpsJsonMessage", new Class[] { Message.class }, mockTransportMsg);
            result = mockHttpsMessage;
            mockTransportMsg.getIotHubMethod();
            result = IotHubMethod.POST;
            mockTransportMsg.getUriPath();
            result = uriPath;
            httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, (HttpsMethod) any, (String) any, (Map) any);
            result = mockResponseMessage;
        }
    };
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    Deencapsulation.invoke(httpsTransportManager, "open");
    // act
    Deencapsulation.invoke(httpsTransportManager, "send", new Class[] { IotHubTransportMessage.class, Map.class }, mockTransportMsg, new HashMap<String, String>());
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(HttpsSingleMessage.class, "parseHttpsJsonMessage", new Class[] { Message.class }, mockTransportMsg);
            times = 1;
        }
    };
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) Test(org.junit.Test)

Aggregations

HttpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection)13 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)12 Test (org.junit.Test)12 IOException (java.io.IOException)2 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)1 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)1