Search in sources :

Example 1 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method toStringReturnsAll.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_015: [** This method shall append device id, tags, desired and reported properties to string (if present) and return **]**
    */
@Test
public void toStringReturnsAll() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testDesProp = new HashSet<>();
    testDesProp.add(new Pair("testDes1", "desObject1"));
    testDesProp.add(new Pair("testDes2", "desObject2"));
    testDevice.setDesiredProperties(testDesProp);
    Set<Pair> testTags = new HashSet<>();
    testTags.add(new Pair("testTag1", "tagObject1"));
    testTags.add(new Pair("testTag2", "tagObject2"));
    testDevice.setTags(testTags);
    //act
    String testDeviceString = testDevice.toString();
    //assert
    assertTrue(testDeviceString.contains("testDes1"));
    assertTrue(testDeviceString.contains("desObject1"));
    assertTrue(testDeviceString.contains("testDes2"));
    assertTrue(testDeviceString.contains("desObject2"));
    assertTrue(testDeviceString.contains("testTag1"));
    assertTrue(testDeviceString.contains("tagObject1"));
    assertTrue(testDeviceString.contains("testTag2"));
    assertTrue(testDeviceString.contains("tagObject2"));
}
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 2 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method setTagsSets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_007: [** This method shall convert the set of pairs of tags to a map and save it. **]**
     */
@Test
public void setTagsSets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testTags = new HashSet<>();
    testTags.add(new Pair("testTag", "tagObject"));
    //act
    testDevice.setTags(testTags);
    //assert
    Set<Pair> actualTags = testDevice.getTags();
    assertEquals(testTags.size(), actualTags.size());
    for (Pair test : actualTags) {
        assertTrue(test.getKey().equals("testTag"));
        assertTrue(test.getValue().equals("tagObject"));
    }
}
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 3 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method clearClearsMapsDes.

@Test
public void clearClearsMapsDes() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRep = new HashMap<>();
    testRep.put("testRep", "repObject");
    Deencapsulation.invoke(testDevice, "setDesiredProperties", testRep);
    //act
    testDevice.clearDesiredProperties();
    //assert
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getDesiredMap");
    assertNull(actualTags);
    Set<Pair> actualTagsSet = testDevice.getDesiredProperties();
    assertTrue(actualTagsSet.size() == 0);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) HashMap(java.util.HashMap) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 4 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method gettersAlwaysCreatesNewSets.

@Test
public void gettersAlwaysCreatesNewSets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testDesProp = new HashSet<>();
    testDesProp.add(new Pair("testDes", "desObject"));
    testDevice.setDesiredProperties(testDesProp);
    //act
    Set<Pair> actualDesProp = testDevice.getDesiredProperties();
    //assert
    assertEquals(testDesProp.size(), actualDesProp.size());
    assertNotEquals(testDesProp, actualDesProp);
}
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 5 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method setterSetsMapsTags.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_024: [** This method shall save the tags map**]**
     */
@Test
public void setterSetsMapsTags() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testTags = new HashMap<>();
    testTags.put("testTag", "tagObject");
    //act
    Deencapsulation.invoke(testDevice, "setTags", testTags);
    //assert
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getTagsMap");
    assertEquals(testTags.size(), actualTags.size());
    for (Map.Entry<String, Object> test : actualTags.entrySet()) {
        assertTrue(test.getKey().equals("testTag"));
        assertTrue(test.getValue().equals("tagObject"));
    }
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) 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