Search in sources :

Example 16 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method gettersGetDefaultsIfNotSet.

@Test
public void gettersGetDefaultsIfNotSet() {
    //arrange
    final byte[] actualData = {};
    DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
    //act
    String testVersion = msg.getVersion();
    String testRequestId = msg.getRequestId();
    String testStatus = msg.getStatus();
    DeviceOperations testOpType = msg.getDeviceOperationType();
    //assert
    String actualVersion = Deencapsulation.getField(msg, "version");
    String actualRequestId = Deencapsulation.getField(msg, "requestId");
    String actualStatus = Deencapsulation.getField(msg, "status");
    DeviceOperations operationType = Deencapsulation.getField(msg, "operationType");
    assertEquals(actualRequestId, testRequestId);
    assertEquals(actualStatus, testStatus);
    assertEquals(actualVersion, testVersion);
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) Test(org.junit.Test)

Example 17 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method setRequestIdSets.

/*
    **Tests_SRS_DEVICETWINMESSAGE_25_005: [**The function shall save the request id.**]**
     */
@Test
public void setRequestIdSets() {
    //arrange
    final byte[] actualData = {};
    DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
    //act
    msg.setRequestId("12");
    //assert
    assertEquals(msg.getRequestId(), "12");
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) Test(org.junit.Test)

Example 18 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method setVersionSetsCorrectVersion.

/*
    **Tests_SRS_DEVICETWINMESSAGE_25_003: [**The function shall set the version.**]**
     */
@Test
public void setVersionSetsCorrectVersion() {
    //arrange
    final byte[] actualData = {};
    DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
    //act
    msg.setVersion("12");
    //assert
    assertEquals(msg.getVersion(), "12");
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) Test(org.junit.Test)

Example 19 with DeviceTwinMessage

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

the class MqttDeviceTwinTest method receiveSetsReqIdOnResTopic.

/*
    **Tests_SRS_MQTTDEVICETWIN_25_040: [**If the topic is of type response topic then this method shall parse further to look for request id which if found is set by calling setRequestId**]**
     */
@Test
public void receiveSetsReqIdOnResTopic(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] actualPayload = "GetTwinResponseDataContainingDesiredAndReportedPropertiesDocument".getBytes();
    final String expectedTopic = "$iothub/twin/res/" + "200" + "/?$rid=" + mockReqId;
    DeviceTwinMessage receivedMessage = null;
    try {
        //arrange
        MqttDeviceTwin testTwin = new MqttDeviceTwin();
        String insertTopic = expectedTopic;
        ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
        testMap.put(insertTopic, actualPayload);
        Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
        Map<String, DeviceOperations> requestMap = new HashMap<>();
        requestMap.put(mockReqId, DEVICE_OPERATION_TWIN_GET_REQUEST);
        Deencapsulation.setField(testTwin, "requestMap", requestMap);
        //act
        receivedMessage = (DeviceTwinMessage) testTwin.receive();
    } finally {
        //assert
        assertNotNull(receivedMessage);
        assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
        assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_GET_RESPONSE);
        assertTrue(receivedMessage.getRequestId().equals(mockReqId));
        assertTrue(receivedMessage.getStatus().equals("200"));
        assertTrue(receivedMessage.getVersion() == null);
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) HashMap(java.util.HashMap) DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 20 with DeviceTwinMessage

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

the class MqttDeviceTwinTest method receiveThrowsUnsupportedExceptionOnAnythingOtherThenPatchDesiredProp.

/*
    **Tests_SRS_MQTTDEVICETWIN_25_043: [**If the topic is not of type response for desired properties then this method shall throw unsupportedoperation exception**]**
     */
@Test(expected = UnsupportedOperationException.class)
public void receiveThrowsUnsupportedExceptionOnAnythingOtherThenPatchDesiredProp(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] actualPayload = "NotificationResponseDataContainingDesiredPropertiesDocument".getBytes();
    final String expectedTopic = "$iothub/twin/PATCH/properties/" + "?$version=" + mockVersion;
    DeviceTwinMessage receivedMessage = null;
    try {
        //arrange
        MqttDeviceTwin testTwin = new MqttDeviceTwin();
        String insertTopic = expectedTopic;
        ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
        testMap.put(insertTopic, actualPayload);
        Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
        //act
        receivedMessage = (DeviceTwinMessage) testTwin.receive();
    } finally {
        //assert
        assertNull(receivedMessage);
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Aggregations

DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)30 Test (org.junit.Test)28 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)17 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)17 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)11 HashMap (java.util.HashMap)8 IOException (java.io.IOException)2 DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)1 IotHubStatusCode (com.microsoft.azure.sdk.iot.device.IotHubStatusCode)1 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Verifications (mockit.Verifications)1