Search in sources :

Example 11 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method desToStringReturnsEmptyIfTagsEmpty.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_019: [** This method shall return an empty string if desiredProperties map is empty or null and return **]**
     */
@Test
public void desToStringReturnsEmptyIfTagsEmpty() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    //act
    String testDeviceString = testDevice.desiredPropertiesToString();
    //assert
    assertTrue(testDeviceString.length() == 0);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Test(org.junit.Test)

Example 12 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method getDesiredPropGets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_013: [** This method shall convert the desiredProperties map to a set of pairs and return with it. **]**
     */
@Test
public void getDesiredPropGets() {
    //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());
    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 13 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method clearClearsMapsTags.

@Test
public void clearClearsMapsTags() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testTags = new HashMap<>();
    testTags.put("testTag", "tagObject");
    Deencapsulation.invoke(testDevice, "setTags", testTags);
    //act
    testDevice.clearTags();
    //assert
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getDesiredMap");
    assertNull(actualTags);
    Set<Pair> actualTagsSet = testDevice.getTags();
    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 14 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method getDeviceIdGets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_004: [** This method shall return the device id **]**
     */
@Test
public void getDeviceIdGets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    //act
    String devId = testDevice.getDeviceId();
    //assert
    assertTrue(devId.equals("testDevice"));
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Test(org.junit.Test)

Example 15 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method getterGetsMapsTags.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_025: [** This method shall return the tags map**]**
     */
@Test
public void getterGetsMapsTags() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testTags = new HashMap<>();
    testTags.put("testTag", "tagObject");
    Deencapsulation.invoke(testDevice, "setTags", testTags);
    //act
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getTagsMap");
    //assert
    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