use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair 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.Pair 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.Pair 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.Pair 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.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinIT method testSubscribeToDesiredPropertiesMultiThreaded.
@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testSubscribeToDesiredPropertiesMultiThreaded() throws IOException, InterruptedException, IotHubException {
// arrange
ExecutorService executor = Executors.newFixedThreadPool(MAX_PROPERTIES_TO_TEST);
for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) {
PropertyState propertyState = new PropertyState();
propertyState.callBackTriggered = false;
propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE);
deviceUnderTest.dCDeviceForTwin.propertyStateList.add(propertyState);
deviceUnderTest.dCDeviceForTwin.setDesiredPropertyCallback(propertyState.property, deviceUnderTest.dCDeviceForTwin, propertyState);
}
// act
deviceClient.subscribeToDesiredProperties(deviceUnderTest.dCDeviceForTwin.getDesiredProp());
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) {
final int index = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
Set<Pair> desiredProperties = new HashSet<>();
desiredProperties.add(new Pair(PROPERTY_KEY + index, PROPERTY_VALUE_UPDATE + UUID.randomUUID()));
deviceUnderTest.sCDeviceForTwin.setDesiredProperties(desiredProperties);
sCDeviceTwin.updateTwin(deviceUnderTest.sCDeviceForTwin);
} catch (IotHubException | IOException e) {
assertTrue(e.getMessage(), true);
}
}
});
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
}
executor.shutdown();
if (!executor.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
executor.shutdownNow();
}
// assert
for (PropertyState propertyState : deviceUnderTest.dCDeviceForTwin.propertyStateList) {
assertTrue(propertyState.property.toString(), propertyState.callBackTriggered);
assertTrue(((String) propertyState.propertyNewValue).startsWith(PROPERTY_VALUE_UPDATE));
assertEquals(deviceUnderTest.deviceTwinStatus, STATUS.SUCCESS);
}
}
Aggregations