Search in sources :

Example 6 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method setStatusIdSets.

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

Example 7 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method getVersionRetrievesVersion.

/*
    **Tests_SRS_DEVICETWINMESSAGE_25_004: [**The function shall return the value of the version either set by the setter or the default (null) if unset so far.**]**
     */
@Test
public void getVersionRetrievesVersion() {
    //arrange
    final byte[] actualData = {};
    DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
    msg.setVersion("12");
    //act
    String version = msg.getVersion();
    //assert
    assertEquals(version, "12");
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) Test(org.junit.Test)

Example 8 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method getRequestIdGets.

/*
    **Tests_SRS_DEVICETWINMESSAGE_25_006: [**The function shall return the value of the request id either set by the setter or the default (null) if unset so far.**]**
     */
@Test
public void getRequestIdGets() {
    //arrange
    final byte[] actualData = {};
    DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
    msg.setRequestId("12");
    //act
    String requestId = msg.getRequestId();
    //assert
    assertEquals(requestId, "12");
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) Test(org.junit.Test)

Example 9 with DeviceTwinMessage

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

the class DeviceTwinMessageTest method getStatusGets.

/*
    **Tests_SRS_DEVICETWINMESSAGE_25_008: [**The function shall return the value of the status either set by the setter or the default (null) if unset so far.**]**
     */
@Test
public void getStatusGets() {
    //arrange
    final byte[] actualData = {};
    DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
    msg.setStatus("12");
    //act
    String status = msg.getStatus();
    //assert
    assertEquals(status, "12");
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) Test(org.junit.Test)

Example 10 with DeviceTwinMessage

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

the class MqttDeviceTwinTest method receiveParsesPatchTopicForDesiredPropertiesNotificationSucceeds.

/*
    **Tests_SRS_MQTTDEVICETWIN_25_042: [**If the topic is of type patch for desired properties then this method shall parse further to look for version which if found is set by calling setVersion**]**
     */
@Test
public void receiveParsesPatchTopicForDesiredPropertiesNotificationSucceeds(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] actualPayload = "UpdateDesiredPropertiesNotificationData".getBytes();
    final String expectedTopic = "$iothub/twin/PATCH/properties/desired/" + "?$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
        assertNotNull(receivedMessage);
        assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
        assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
        assertTrue(receivedMessage.getVersion().equals(mockVersion));
        assertTrue(receivedMessage.getRequestId() == null);
        assertTrue(receivedMessage.getStatus() == null);
    }
}
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