Search in sources :

Example 6 with DeviceMethodMessage

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.

the class DeviceMethodMessageTest method constructorSucceeds.

/*
    **Tests_SRS_DEVICEMETHODMESSAGE_25_001: [**The constructor shall save the message body by calling super with the body as parameter.**]**
    **Tests_SRS_DEVICEMETHODMESSAGE_25_002: [**If the message body is null, the constructor shall throw an IllegalArgumentException thrown by base constructor.**]**
    */
@Test
public void constructorSucceeds() {
    //act
    DeviceMethodMessage testDMMessage = new DeviceMethodMessage(new byte[0]);
    //assert
    assertTrue(testDMMessage.getMessageType() == MessageType.DeviceMethods);
}
Also used : DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) Test(org.junit.Test)

Example 7 with DeviceMethodMessage

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.

the class DeviceMethodMessageTest method setMethodNameSets.

/*
    **Tests_SRS_DEVICEMETHODMESSAGE_25_003: [**This method shall set the methodName.**]**
     */
@Test
public void setMethodNameSets() {
    //arrange
    DeviceMethodMessage testDMMessage = new DeviceMethodMessage(new byte[0]);
    //act
    testDMMessage.setMethodName("TestName");
    //assert
    assertEquals(testDMMessage.getMethodName(), "TestName");
}
Also used : DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) Test(org.junit.Test)

Example 8 with DeviceMethodMessage

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.

the class DeviceMethodMessageTest method setMethodNameThrowsOnNull.

/*
    **Tests_SRS_DEVICEMETHODMESSAGE_25_004: [**This method shall throw IllegalArgumentException if the methodName is null.**]**
     */
@Test(expected = IllegalArgumentException.class)
public void setMethodNameThrowsOnNull() {
    //arrange
    DeviceMethodMessage testDMMessage = new DeviceMethodMessage(new byte[0]);
    //act
    testDMMessage.setMethodName(null);
}
Also used : DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) Test(org.junit.Test)

Example 9 with DeviceMethodMessage

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.

the class MqttDeviceMethodTest method sendSucceedsCallsSubscribe.

/*
    Tests_SRS_MqttDeviceMethod_25_004: [**parseTopic shall look for the method topic($iothub/methods) prefix from received message queue as per spec and if found shall return it as string.**]**

    Tests_SRS_MqttDeviceMethod_25_005: [**If none of the topics from the received queue match the methods topic prefix then this method shall return null string .**]**

    Tests_SRS_MqttDeviceMethod_25_006: [**If received messages queue is empty then parseTopic shall return null string.**]**

    Tests_SRS_MqttDeviceMethod_25_020: [**send method shall subscribe to topic from spec ($iothub/methods/POST/#) if the operation is of type DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST.**]**
     */
@Test
public void sendSucceedsCallsSubscribe() throws IOException {
    //arrange
    final String actualSubscribeTopic = "$iothub/methods/POST/#";
    byte[] actualPayload = "TestMessage".getBytes();
    DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
    testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST);
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    testMethod.start();
    //act
    testMethod.send(testMessage);
    //assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedMqtt, "subscribe", actualSubscribeTopic);
            maxTimes = 1;
        }
    };
}
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 10 with DeviceMethodMessage

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.

the class MqttDeviceMethodTest method sendSucceedsCallsPublish.

/*
    Tests_SRS_MqttDeviceMethod_25_022: [**send method shall build the publish topic of the format mentioned in spec ($iothub/methods/res/{status}/?$rid={request id}) and publish if the operation is of type DEVICE_OPERATION_METHOD_SEND_RESPONSE.**]**
     */
@Test
public void sendSucceedsCallsPublish() throws IOException {
    final byte[] actualPayload = "TestMessage".getBytes();
    final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
    testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SEND_RESPONSE);
    testMessage.setRequestId("ReqId");
    testMessage.setStatus("testStatus");
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    Map<String, DeviceOperations> testRequestMap = new HashMap<>();
    testRequestMap.put("ReqId", DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
    Deencapsulation.setField(testMethod, "requestMap", testRequestMap);
    testMethod.start();
    //act
    testMethod.send(testMessage);
    //assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedMqtt, "publish", anyString, actualPayload);
            maxTimes = 1;
        }
    };
    assertTrue(testRequestMap.isEmpty());
}
Also used : HashMap(java.util.HashMap) DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) 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)

Aggregations

DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)15 Test (org.junit.Test)15 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)10 Verifications (mockit.Verifications)4 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)2 Message (com.microsoft.azure.sdk.iot.device.Message)2 HashMap (java.util.HashMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)1 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)1 NonStrictExpectations (mockit.NonStrictExpectations)1