use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice 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.DeviceTwinDevice 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.DeviceTwinDevice in project azure-iot-sdk-java by Azure.
the class DeviceTwinDeviceTest method constructorCreatesNewDevice.
/*
**Tests_SRS_DEVICETWINDEVICE_25_003: [** The constructor shall create a new instance of twin object for this device and store the device id.**]**
*/
@Test
public void constructorCreatesNewDevice() {
//act
DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
//assert
assertNotNull(testDevice);
Map<String, Object> tagsMap = Deencapsulation.getField(testDevice, "tag");
assertNull(tagsMap);
Map<String, Object> repPropMap = Deencapsulation.getField(testDevice, "reportedProperties");
assertNull(repPropMap);
Map<String, Object> desPropMap = Deencapsulation.getField(testDevice, "reportedProperties");
assertNull(desPropMap);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice 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.DeviceTwinDevice in project azure-iot-sdk-java by Azure.
the class DeviceTwinIT method setUpTwin.
private void setUpTwin(DeviceState deviceState) throws IOException, URISyntaxException, IotHubException, InterruptedException {
/*
Because of the bug in device client on MQTT, we cannot have multiple device client open
in the main thread at the same time. Hence restricting to use single device client.
*/
if (deviceClient == null) {
deviceState.dCDeviceForTwin = new DeviceExtension();
deviceClient = new DeviceClient(DeviceConnectionString.get(iotHubConnectionString, deviceState.sCDeviceForRegistryManager), IotHubClientProtocol.MQTT);
deviceClient.open();
deviceClient.startDeviceTwin(new DeviceTwinStatusCallBack(), deviceState, deviceState.dCDeviceForTwin, deviceState);
deviceState.deviceTwinStatus = STATUS.SUCCESS;
}
// set up twin on ServiceClient
if (sCDeviceTwin != null) {
deviceState.sCDeviceForTwin = new DeviceTwinDevice(deviceState.sCDeviceForRegistryManager.getDeviceId());
sCDeviceTwin.getTwin(deviceState.sCDeviceForTwin);
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
}
}
Aggregations