Search in sources :

Example 6 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 stopSucceedsDoesNotCallUnSubscribeIfStopped.

@Test
public void stopSucceedsDoesNotCallUnSubscribeIfStopped() throws IOException {
    //arrange
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    testMethod.start();
    testMethod.stop();
    //act
    testMethod.stop();
    //assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
            maxTimes = 1;
        }
    };
}
Also used : MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 7 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 sendDoesNotSendOnDifferentMessageType.

/*
    Tests_SRS_MqttDeviceMethod_25_017: [**send method shall return if the message is not of Type DeviceMethod.**]**
     */
@Test
public void sendDoesNotSendOnDifferentMessageType() throws IOException {
    final byte[] actualPayload = "TestMessage".getBytes();
    final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
    testMessage.setMessageType(MessageType.DeviceTwin);
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    testMethod.start();
    //act
    testMethod.send(testMessage);
    //assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedMqtt, "publish", anyString, actualPayload);
            maxTimes = 0;
            Deencapsulation.invoke(mockedMqtt, "subscribe", anyString);
            maxTimes = 0;
        }
    };
}
Also used : DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 8 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 startSucceedsDoesNotCallsSubscribeIfStarted.

@Test
public void startSucceedsDoesNotCallsSubscribeIfStarted() throws IOException {
    //arrange
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    testMethod.start();
    //act
    testMethod.start();
    //assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedMqtt, "subscribe", anyString);
            maxTimes = 0;
        }
    };
}
Also used : MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 9 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 sendThrowsOnNullRequestID.

/*
    Tests_SRS_MqttDeviceMethod_25_021: [**send method shall throw an IoException if message contains a null or empty request id if the operation is of type DEVICE_OPERATION_METHOD_SEND_RESPONSE.**]**
     */
@Test(expected = IOException.class)
public void sendThrowsOnNullRequestID() throws IOException {
    final byte[] actualPayload = "TestMessage".getBytes();
    final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
    testMessage.setMessageType(MessageType.DeviceMethods);
    testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SEND_RESPONSE);
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    testMethod.start();
    //act
    testMethod.send(testMessage);
}
Also used : DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Test(org.junit.Test)

Example 10 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() throws IOException {
    //arrange
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    //act
    testMethod.start();
    //assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedMqtt, "subscribe", anyString);
            times = 0;
        }
    };
}
Also used : MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) 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