Search in sources :

Example 11 with Pair

use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair 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 12 with Pair

use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair 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 13 with Pair

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

the class DeviceTwinDeviceTest method tagsToStringReturnsTags.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_016: [** This method shall convert the tags map to string (if present) and return **]**
     */
@Test
public void tagsToStringReturnsTags() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testTags = new HashSet<>();
    testTags.add(new Pair("testTag1", "tagObject1"));
    testTags.add(new Pair("testTag2", "tagObject2"));
    testDevice.setTags(testTags);
    //act
    String testDeviceString = testDevice.tagsToString();
    //assert
    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 14 with Pair

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

the class DeviceTwinDeviceTest method getReportedPropGets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_005: [** This method shall convert the reported properties map to a set of pairs and return with it. **]**
     */
@Test
public void getReportedPropGets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> repMap = new HashMap<>();
    repMap.put("testRep", "repObject");
    Deencapsulation.setField(testDevice, "reportedProperties", repMap);
    //act
    Set<Pair> actualRepProp = testDevice.getReportedProperties();
    //assert
    assertEquals(repMap.size(), actualRepProp.size());
    for (Pair test : actualRepProp) {
        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) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 15 with Pair

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

the class DeviceTwinDeviceTest method desiredToStringReturnsDesired.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_018: [** This method shall convert the desiredProperties map to string (if present) and return **]**
     */
@Test
public void desiredToStringReturnsDesired() {
    //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);
    //act
    String testDeviceString = testDevice.desiredPropertiesToString();
    //assert
    assertTrue(testDeviceString.contains("testDes1"));
    assertTrue(testDeviceString.contains("desObject1"));
    assertTrue(testDeviceString.contains("testDes2"));
    assertTrue(testDeviceString.contains("desObject2"));
}
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)

Aggregations

Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)32 Test (org.junit.Test)23 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)20 HashSet (java.util.HashSet)10 HashMap (java.util.HashMap)5 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)3 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 ExecutorService (java.util.concurrent.ExecutorService)1 DeviceConnectionString (tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString)1