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"));
}
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"));
}
}
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);
}
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);
}
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"));
}
}
Aggregations