Search in sources :

Example 21 with MqttTransport

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

the class MqttTransportTest method handleMessageFailsIfTransportNeverOpened.

// Tests_SRS_MQTTTRANSPORT_15_018: [If the MQTT connection is closed,
// the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void handleMessageFailsIfTransportNeverOpened() throws IOException {
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.handleMessage();
}
Also used : MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Example 22 with MqttTransport

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

the class MqttTransportTest method openDoesNothingIfAlreadyOpened.

// SRS_MQTTTRANSPORT_15_004: [If the MQTT connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfAlreadyOpened() throws IOException {
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.open();
    final MqttIotHubConnection expectedConnection = mockConnection;
    new Verifications() {

        {
            expectedConnection.open();
            times = 1;
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Example 23 with MqttTransport

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

the class MqttTransportTest method openOpensMqttConnection.

// Tests_SRS_MQTTTRANSPORT_15_003: [The function shall establish an MQTT connection
// with IoT Hub given in the configuration.]
@Test
public void openOpensMqttConnection() throws IOException, NoSuchFieldException, IllegalAccessException {
    new NonStrictExpectations() {

        {
            new MqttIotHubConnection(mockConfig);
            result = mockConnection;
        }
    };
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    final MqttIotHubConnection expectedConnection = mockConnection;
    new Verifications() {

        {
            expectedConnection.open();
        }
    };
    Field sendMessagesLock = transport.getClass().getDeclaredField("sendMessagesLock");
    sendMessagesLock.setAccessible(true);
    assertNotNull(sendMessagesLock.get(transport));
    Field handleMessageLock = transport.getClass().getDeclaredField("handleMessageLock");
    handleMessageLock.setAccessible(true);
    assertNotNull(handleMessageLock.get(transport));
}
Also used : Field(java.lang.reflect.Field) MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Example 24 with MqttTransport

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

the class MqttTransportTest method invokeCallbacksFailsIfTransportNeverOpened.

// Tests_SRS_MQTTTRANSPORT_15_014: [If the transport is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void invokeCallbacksFailsIfTransportNeverOpened() throws IOException {
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.invokeCallbacks();
}
Also used : MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Example 25 with MqttTransport

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

the class MqttTransportTest method closeClosesMqttConnection.

// Tests_SRS_MQTTTRANSPORT_15_005: [The function shall close the MQTT connection
// with the IoT Hub given in the configuration.]
@Test
public void closeClosesMqttConnection() throws IOException {
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.close();
    final MqttIotHubConnection expectedConnection = mockConnection;
    new Verifications() {

        {
            expectedConnection.close();
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Aggregations

MqttTransport (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport)26 Test (org.junit.Test)26 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)12 HashMap (java.util.HashMap)12 IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)4 Queue (java.util.Queue)3 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)1 Field (java.lang.reflect.Field)1 AssertionFailedError (junit.framework.AssertionFailedError)1