Search in sources :

Example 31 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method getterGetsMapsDes.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_027: [** This method shall return the desiredProperties map**]**
     */
@Test
public void getterGetsMapsDes() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRep = new HashMap<>();
    testRep.put("testRep", "repObject");
    Deencapsulation.invoke(testDevice, "setDesiredProperties", testRep);
    //act
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getDesiredMap");
    //assert
    assertEquals(testRep.size(), actualTags.size());
    for (Map.Entry<String, Object> test : actualTags.entrySet()) {
        assertTrue(test.getKey().equals("testRep"));
        assertTrue(test.getValue().equals("repObject"));
    }
}
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)

Example 32 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method settersAlwaysCreatesNewMaps.

@Test
public void settersAlwaysCreatesNewMaps() {
    //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());
    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 33 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method setTagsThrowsIsNullInput.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_008: [** If the tags Set is null then this method shall throw IllegalArgumentException.**]**
     */
@Test(expected = IllegalArgumentException.class)
public void setTagsThrowsIsNullInput() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testTags = null;
    //act
    testDevice.setTags(testTags);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 34 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method clearTwinClears.

@Test
public void clearTwinClears() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRep = new HashMap<>();
    testRep.put("testKey", "testObject");
    Deencapsulation.invoke(testDevice, "setDesiredProperties", testRep);
    Deencapsulation.invoke(testDevice, "setTags", testRep);
    //act
    testDevice.clearTwin();
    //assert
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getTagsMap");
    Map<String, Object> actualDes = Deencapsulation.invoke(testDevice, "getDesiredMap");
    assertNull(actualTags);
    assertNull(actualDes);
    Set<Pair> actualTagsSet = testDevice.getTags();
    assertTrue(actualTagsSet.size() == 0);
    Set<Pair> actualDesSet = testDevice.getDesiredProperties();
    assertTrue(actualDesSet.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 35 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method setterSetsMapsDes.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_023: [** This method shall save the desiredProperties map**]**
     */
@Test
public void setterSetsMapsDes() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRep = new HashMap<>();
    testRep.put("testRep", "repObject");
    //act
    Deencapsulation.invoke(testDevice, "setDesiredProperties", testRep);
    //assert
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getDesiredMap");
    assertEquals(testRep.size(), actualTags.size());
    for (Map.Entry<String, Object> test : actualTags.entrySet()) {
        assertTrue(test.getKey().equals("testRep"));
        assertTrue(test.getValue().equals("repObject"));
    }
}
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