Search in sources :

Example 11 with MqttDeviceMethod

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

the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInTwin.

@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInTwin() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            result = mockToken;
            new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
            result = mockDeviceMessaging;
            new MqttDeviceMethod();
            result = mockDeviceMethods;
            new MqttDeviceTwin();
            result = new IOException(anyString);
        }
    };
    try {
        MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
        connection.open();
    } catch (Exception e) {
        new Verifications() {

            {
                mockDeviceMessaging.stop();
                times = 1;
                mockDeviceMethods.stop();
                times = 1;
            }
        };
        throw e;
    }
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IOException(java.io.IOException) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) IOException(java.io.IOException) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 12 with MqttDeviceMethod

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

the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInMethod.

@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInMethod() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            result = mockToken;
            new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
            result = mockDeviceMessaging;
            new MqttDeviceMethod();
            result = new IOException(anyString);
        }
    };
    try {
        MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
        connection.open();
    } catch (Exception e) {
        new Verifications() {

            {
                mockDeviceMessaging.stop();
                times = 1;
            }
        };
        throw e;
    }
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IOException(java.io.IOException) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with MqttDeviceMethod

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

the class MqttDeviceMethodTest method receiveReturnsNullMessageIfTopicWasNotPost.

// Tests_SRS_MqttDeviceMethod_34_027: [This method shall parse message to look for Post topic ($iothub/methods/POST/) and return null other wise.]
@Test
public void receiveReturnsNullMessageIfTopicWasNotPost() throws TransportException {
    // arrange
    String topic = "$iothub/methods/Not_POST/testMethod/?$rid=10";
    byte[] actualPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
    Queue<Pair<String, byte[]>> testreceivedMessages = new ConcurrentLinkedQueue<>();
    testreceivedMessages.add(new MutablePair<>(topic, actualPayload));
    MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    testMethod.start();
    // act
    Message actualMessage = testMethod.receive();
    // assert
    assertNull(actualMessage);
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 14 with MqttDeviceMethod

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

the class MqttDeviceMethodTest method receiveThrowsIfRIDCouldNotBeParsed.

/*
    Tests_SRS_MqttDeviceMethod_25_031: [**If request id is not found or is null then receive shall throw TransportException **]**
     */
@Test(expected = TransportException.class)
public void receiveThrowsIfRIDCouldNotBeParsed() throws TransportException {
    // arrange
    String topic = "$iothub/methods/POST/testMethod/";
    byte[] actualPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
    testreceivedMessages.add(new MutablePair<>(topic, actualPayload));
    MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    Deencapsulation.setField(testMethod, "receivedMessages", testreceivedMessages);
    testMethod.start();
    // act
    testMethod.receive();
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 15 with MqttDeviceMethod

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

the class MqttDeviceMethodTest method startSucceedsCalls.

/*
    Tests_SRS_MqttDeviceMethod_25_014: [**start method shall just mark that this class is ready to start.**]**
     */
@Test
public void startSucceedsCalls(@Mocked final Mqtt mockMqtt) throws TransportException {
    // arrange
    final MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    // act
    testMethod.start();
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(testMethod, "subscribe", anyString);
            times = 0;
        }
    };
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)41 Test (org.junit.Test)41 Message (com.microsoft.azure.sdk.iot.device.Message)22 Verifications (mockit.Verifications)17 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)16 MutablePair (org.apache.commons.lang3.tuple.MutablePair)16 Pair (org.apache.commons.lang3.tuple.Pair)16 DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)14 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)6 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)4 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)3 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)3 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)2 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)2 State (com.microsoft.azure.sdk.iot.device.transport.State)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 NonStrictExpectations (mockit.NonStrictExpectations)2