use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinIT method testSubscribeToDesiredProperties.
@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testSubscribeToDesiredProperties() throws IOException, InterruptedException, IotHubException {
// arrange
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);
Set<Pair> desiredProperties = new HashSet<>();
for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) {
desiredProperties.add(new Pair(PROPERTY_KEY + i, PROPERTY_VALUE_UPDATE + UUID.randomUUID()));
}
deviceUnderTest.sCDeviceForTwin.setDesiredProperties(desiredProperties);
sCDeviceTwin.updateTwin(deviceUnderTest.sCDeviceForTwin);
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
// assert
assertEquals(deviceUnderTest.deviceTwinStatus, STATUS.SUCCESS);
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);
}
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinIT method readReportedProperties.
private int readReportedProperties(DeviceState deviceState, String startsWithKey, String startsWithValue) throws IOException, IotHubException, InterruptedException {
int totalCount = 0;
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
sCDeviceTwin.getTwin(deviceState.sCDeviceForTwin);
Set<Pair> repProperties = deviceState.sCDeviceForTwin.getReportedProperties();
for (Pair p : repProperties) {
String val = (String) p.getValue();
if (p.getKey().startsWith(startsWithKey) && val.startsWith(startsWithValue)) {
totalCount++;
}
}
return totalCount;
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinIT method testGetTwinUpdates.
@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testGetTwinUpdates() throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException {
addMultipleDevices();
// Add tag and desired for multiple devices
for (int i = 0; i < MAX_DEVICES; i++) {
Set<Pair> tags = new HashSet<>();
tags.add(new Pair(TAG_KEY + i, TAG_VALUE + i));
devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
Set<Pair> desiredProperties = new HashSet<>();
desiredProperties.add(new Pair(PROPERTY_KEY + i, PROPERTY_VALUE + i));
devicesUnderTest[i].sCDeviceForTwin.setDesiredProperties(desiredProperties);
sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
devicesUnderTest[i].sCDeviceForTwin.clearTwin();
}
// Update Tags and desired properties on multiple devices
for (int i = 0; i < MAX_DEVICES; i++) {
sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
Set<Pair> tags = devicesUnderTest[i].sCDeviceForTwin.getTags();
for (Pair tag : tags) {
tag.setValue(TAG_VALUE_UPDATE + i);
}
devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
Set<Pair> desiredProperties = devicesUnderTest[i].sCDeviceForTwin.getDesiredProperties();
for (Pair dp : desiredProperties) {
dp.setValue(PROPERTY_VALUE_UPDATE + i);
}
devicesUnderTest[i].sCDeviceForTwin.setDesiredProperties(desiredProperties);
sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
devicesUnderTest[i].sCDeviceForTwin.clearTwin();
}
// Read updates on multiple devices
for (int i = 0; i < MAX_DEVICES; i++) {
sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
for (Pair t : devicesUnderTest[i].sCDeviceForTwin.getTags()) {
assertEquals(t.getKey(), TAG_KEY + i);
assertEquals(t.getValue(), TAG_VALUE_UPDATE + i);
}
for (Pair dp : devicesUnderTest[i].sCDeviceForTwin.getDesiredProperties()) {
assertEquals(dp.getKey(), PROPERTY_KEY + i);
assertEquals(dp.getValue(), PROPERTY_VALUE_UPDATE + i);
}
}
removeMultipleDevices();
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinDeviceTest method getTagsGets.
/*
**Tests_SRS_DEVICETWINDEVICE_25_009: [** This method shall convert the tags map to a set of pairs and return with it. **]**
*/
@Test
public void getTagsGets() {
//arrange
DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
Set<Pair> testTags = new HashSet<>();
testTags.add(new Pair("testTag", "tagObject"));
testDevice.setTags(testTags);
//act
Set<Pair> actualTags = testDevice.getTags();
//assert
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 getReportedPropGetsEmptyIfNotPresent.
/*
**Tests_SRS_DEVICETWINDEVICE_25_006: [** If the reported properties map is null then this method shall return empty set of pairs.**]**
*/
@Test
public void getReportedPropGetsEmptyIfNotPresent() {
//arrange
DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
//act
Set<Pair> actualRepProp = testDevice.getReportedProperties();
//assert
assertNotNull(actualRepProp);
assertTrue(actualRepProp.size() == 0);
}
Aggregations