Search in sources :

Example 6 with DeviceTwinDevice

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice in project azure-iot-sdk-java by Azure.

the class DeviceTwinDeviceTest method reportedToStringReturnsReported.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_020: [** This method shall convert the reportedProperties map to string (if present) and return **]**
     */
@Test
public void reportedToStringReturnsReported() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRepProp = new HashMap<>();
    testRepProp.put("testRep1", "repObject1");
    testRepProp.put("testRep2", "repObject2");
    Deencapsulation.invoke(testDevice, "setReportedProperties", testRepProp);
    //act
    String testDeviceString = testDevice.reportedPropertiesToString();
    //assert
    assertTrue(testDeviceString.contains("testRep1"));
    assertTrue(testDeviceString.contains("repObject1"));
    assertTrue(testDeviceString.contains("testRep2"));
    assertTrue(testDeviceString.contains("repObject2"));
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with DeviceTwinDevice

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice in project azure-iot-sdk-java by Azure.

the class DeviceTwinDeviceTest method getTwinObjectGets.

/*
    Tests_SRS_DEVICETWINDEVICE_25_028: [ This method shall return the twinObject for this device]
     */
@Test
public void getTwinObjectGets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    //act
    TwinParser testDeviceTwinParserObject = Deencapsulation.invoke(testDevice, "getTwinParser");
    //assert
    assertNotNull(testDeviceTwinParserObject);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) Test(org.junit.Test)

Example 8 with DeviceTwinDevice

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice in project azure-iot-sdk-java by Azure.

the class DeviceTwinDeviceTest method getTwinObjectUniquePerDevice.

@Test
public void getTwinObjectUniquePerDevice() {
    //arrange
    DeviceTwinDevice testDevice1 = new DeviceTwinDevice("testDevice1");
    DeviceTwinDevice testDevice2 = new DeviceTwinDevice("testDevice2");
    //act
    TwinParser testDeviceTwinParserObject1 = Deencapsulation.invoke(testDevice1, "getTwinParser");
    TwinParser testDeviceTwinParserObject2 = Deencapsulation.invoke(testDevice2, "getTwinParser");
    //assert
    assertNotEquals(testDeviceTwinParserObject1, testDeviceTwinParserObject2);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) Test(org.junit.Test)

Example 9 with DeviceTwinDevice

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice in project azure-iot-sdk-java by Azure.

the class DeviceTwinDeviceTest method setDesiredPropSets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_011: [** This method shall convert the set of pairs of desiredProperties to a map and save it. **]**
     */
@Test
public void setDesiredPropSets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testDesProp = new HashSet<>();
    testDesProp.add(new Pair("testDes", "desObject"));
    //act
    testDevice.setDesiredProperties(testDesProp);
    //assert
    Set<Pair> actualDesProp = testDevice.getDesiredProperties();
    assertEquals(testDesProp.size(), actualDesProp.size());
    for (Pair test : actualDesProp) {
        assertTrue(test.getKey().equals("testDes"));
        assertTrue(test.getValue().equals("desObject"));
    }
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) HashSet(java.util.HashSet) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 10 with DeviceTwinDevice

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice in project azure-iot-sdk-java by Azure.

the class DeviceTwinDeviceTest method getTagsGetsEmptyIfNotPresent.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_010: [** If the tags map is null then this method shall return empty set of pairs.**]**
     */
@Test
public void getTagsGetsEmptyIfNotPresent() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    //act
    Set<Pair> actualTags = testDevice.getTags();
    //assert
    assertNotNull(actualTags);
    assertTrue(actualTags.size() == 0);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Aggregations

DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)35 Test (org.junit.Test)33 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)20 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)10 Map (java.util.Map)6 TwinParser (com.microsoft.azure.sdk.iot.deps.serializer.TwinParser)2 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)1 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)1 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)1 Random (java.util.Random)1