use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinDeviceTest method getDesiredReturnsEmptyIfNullMap.
/*
Tests_SRS_DEVICETWINDEVICE_25_014: [ If the desiredProperties map is null then this method shall return empty set of pairs.]
*/
@Test
public void getDesiredReturnsEmptyIfNullMap() {
//arrange
DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
//act
Set<Pair> actualDesProp = testDevice.getDesiredProperties();
//assert
assertNotNull(actualDesProp);
assertTrue(actualDesProp.size() == 0);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinDeviceTest method setDesiredThrowsIfNullInput.
/*
**Tests_SRS_DEVICETWINDEVICE_25_012: [** If the desiredProperties Set is null then this method shall throw IllegalArgumentException.**]**
*/
@Test(expected = IllegalArgumentException.class)
public void setDesiredThrowsIfNullInput() {
//arrange
DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
Set<Pair> testDesProp = null;
//act
testDevice.setDesiredProperties(testDesProp);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class PairTest method getKeyGets.
/*
**Tests_SRS_Pair_25_004: [**The function shall return the value of the key corresponding to this Pair.**]**
*/
@Test
public void getKeyGets() {
//arrange
Pair testPair = new Pair("TestKey", "TestObject");
//act
String key = testPair.getKey();
//assert
assertNotNull(testPair);
assertTrue(key.equals("TestKey"));
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinSample method main.
/**
* @param args
* @throws IOException
* @throws URISyntaxException
*/
public static void main(String[] args) throws Exception {
System.out.println("Starting sample...");
DeviceTwin twinClient = DeviceTwin.createFromConnectionString(iotHubConnectionString);
DeviceTwinDevice device = new DeviceTwinDevice(deviceId);
try {
// Manage complete twin
System.out.println("Getting device twin");
twinClient.getTwin(device);
System.out.println(device);
//Update Twin Tags and Desired Properties
Set<Pair> tags = new HashSet<Pair>();
tags.add(new Pair("HomeID", UUID.randomUUID()));
device.setTags(tags);
Set<Pair> desProp = new HashSet<Pair>();
int temp = new Random().nextInt(100);
desProp.add(new Pair("temp", temp));
device.setDesiredProperties(desProp);
System.out.println("Updating device twin");
twinClient.updateTwin(device);
System.out.println("Getting device twin");
twinClient.getTwin(device);
System.out.println(device);
} catch (IotHubException e) {
System.out.println(e.getMessage());
}
System.out.println("Shutting down sample...");
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Pair in project azure-iot-sdk-java by Azure.
the class DeviceTwinIT method testAddTagUpdates.
@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testAddTagUpdates() throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException {
addMultipleDevices();
// Update tag 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);
sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
devicesUnderTest[i].sCDeviceForTwin.clearTwin();
}
// Read updates on multiple devices
for (int i = 0; i < MAX_DEVICES; i++) {
sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
for (Pair t : devicesUnderTest[i].sCDeviceForTwin.getTags()) {
assertEquals(t.getKey(), TAG_KEY + i);
assertEquals(t.getValue(), TAG_VALUE + i);
}
}
removeMultipleDevices();
}
Aggregations