Search in sources :

Example 16 with DeviceTwinDevice

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

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

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

the class DeviceTwinDeviceTest method getterGetsMapsRep.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_026: [** This method shall return the reportedProperties map**]**
     */
@Test
public void getterGetsMapsRep() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRep = new HashMap<>();
    testRep.put("testRep", "repObject");
    Deencapsulation.invoke(testDevice, "setReportedProperties", testRep);
    //act
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getReportedMap");
    //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 19 with DeviceTwinDevice

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

the class DeviceTwinDeviceTest method setterSetsMapsRep.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_022: [** This method shall save the reportedProperties map**]**
     */
@Test
public void setterSetsMapsRep() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Map<String, Object> testRep = new HashMap<>();
    testRep.put("testRep", "repObject");
    //act
    Deencapsulation.invoke(testDevice, "setReportedProperties", testRep);
    //assert
    Map<String, Object> actualTags = Deencapsulation.invoke(testDevice, "getReportedMap");
    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 20 with DeviceTwinDevice

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

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