use of com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities in project azure-iot-sdk-java by Azure.
the class DeviceManagerSample method UpdateDevice.
private static void UpdateDevice() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
// Create an Edge device, and set leaf-device as a child.
Device edge = Device.createFromId(SampleUtils.edgeId, null, null);
DeviceCapabilities capabilities = new DeviceCapabilities();
capabilities.setIotEdge(true);
edge.setCapabilities(capabilities);
try {
edge = registryManager.addDevice(edge);
// Set Edge device as a parent by getting its scope and adding it to the device's device scope.
Device device = registryManager.getDevice(SampleUtils.deviceId);
device.setScope(edge.getScope());
device = registryManager.updateDevice(device);
System.out.println("Device updated: " + device.getDeviceId());
System.out.println("Device scope: " + device.getScope());
System.out.println("Device parent: " + device.getParentScopes().get(0));
} catch (IotHubException | IOException iote) {
iote.printStackTrace();
}
registryManager.close();
}
use of com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities in project azure-iot-sdk-java by Azure.
the class DeviceTest method device_get_all_properties.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_001: [The Device class shall have the following properties:
// deviceId, Etag, Status, StatusReason, StatusUpdatedTime, ConnectionState, CloudToDeviceMessageCount
// ConnectionStateUpdatedTime, LastActivityTime, symmetricKey, thumbprint, authentication]
// Assert
@Test
public void device_get_all_properties() {
// Arrange
String deviceId = "xxx-device";
SymmetricKey expectedSymmetricKey = new SymmetricKey();
String expectedPrimaryThumbprint = "0000000000000000000000000000000000000000";
String expectedSecondaryThumbprint = "1111111111111111111111111111111111111111";
// Act
Device device = Device.createFromId(deviceId, null, null);
device.setSymmetricKey(expectedSymmetricKey);
assertEquals(expectedSymmetricKey, device.getSymmetricKey());
device.setThumbprintFinal(expectedPrimaryThumbprint, expectedSecondaryThumbprint);
assertEquals(expectedPrimaryThumbprint, device.getPrimaryThumbprint());
assertEquals(expectedSecondaryThumbprint, device.getSecondaryThumbprint());
device.setStatus(DeviceStatus.Enabled);
assertEquals(DeviceStatus.Enabled, device.getStatus());
device.getPrimaryThumbprint();
device.getSecondaryThumbprint();
device.getDeviceId();
device.getGenerationId();
device.getPrimaryKey();
device.getSecondaryKey();
device.geteTag();
device.getStatus();
device.getStatusReason();
device.getStatusUpdatedTime();
device.getConnectionState();
device.getConnectionStateUpdatedTime();
device.getLastActivityTime();
device.getCloudToDeviceMessageCount();
DeviceCapabilities cap = new DeviceCapabilities();
cap.setIotEdge(true);
device.setCapabilities(cap);
assertEquals((Boolean) true, device.getCapabilities().isIotEdge());
}
use of com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities in project azure-iot-sdk-java by Azure.
the class DeviceTest method conversionToDeviceParser.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_34_018: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParser() {
// arrange
String expectedDeviceId = "deviceCA";
DeviceStatus expectedDeviceStatus = DeviceStatus.Disabled;
String expectedStatusReason = "no reason";
String expectedStatusUpdatedTime = "2001-09-09T09:09:09";
int expectedCloudToDeviceMessageCount = 23;
DeviceConnectionState expectedConnectionState = DeviceConnectionState.Connected;
String expectedConnectionStateUpdatedTime = "2001-09-09T09:09:09";
String expectedETag = "1234";
String expectedGenerationId = "5678";
String expectedLastActivityTime = "2001-09-09T09:09:09";
Boolean expectedCapabilities = false;
String scope = "scope";
Device device = Device.createDevice(expectedDeviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
device.setStatus(expectedDeviceStatus);
Deencapsulation.setField(device, "statusReason", expectedStatusReason);
Deencapsulation.setField(device, "statusUpdatedTime", expectedStatusUpdatedTime);
Deencapsulation.setField(device, "cloudToDeviceMessageCount", expectedCloudToDeviceMessageCount);
Deencapsulation.setField(device, "connectionState", expectedConnectionState);
Deencapsulation.setField(device, "connectionStateUpdatedTime", expectedConnectionStateUpdatedTime);
Deencapsulation.setField(device, "eTag", expectedETag);
Deencapsulation.setField(device, "generationId", expectedGenerationId);
Deencapsulation.setField(device, "lastActivityTime", expectedLastActivityTime);
Deencapsulation.setField(device, "capabilities", new DeviceCapabilities());
Deencapsulation.setField(device, "scope", scope);
device.getCapabilities().setIotEdge(expectedCapabilities);
// act
DeviceParser parser = reflectivelyInvokeToDeviceParser(device);
// assert
assertEquals(AuthenticationTypeParser.CERTIFICATE_AUTHORITY, parser.getAuthenticationParser().getType());
assertEquals(expectedDeviceStatus.toString(), parser.getStatus());
assertEquals(expectedDeviceStatus.toString(), parser.getStatus());
assertEquals(expectedStatusReason, parser.getStatusReason());
assertEquals(ParserUtility.getDateTimeUtc(expectedStatusUpdatedTime), parser.getStatusUpdatedTime());
assertEquals(expectedCloudToDeviceMessageCount, parser.getCloudToDeviceMessageCount());
assertEquals(expectedConnectionState.toString(), parser.getConnectionState());
assertEquals(ParserUtility.getDateTimeUtc(expectedConnectionStateUpdatedTime), parser.getConnectionStateUpdatedTime());
assertEquals(expectedDeviceId, parser.getDeviceId());
assertEquals("\"" + expectedETag + "\"", parser.geteTag());
assertEquals(expectedGenerationId, parser.getGenerationId());
assertEquals(ParserUtility.getDateTimeUtc(expectedLastActivityTime), parser.getLastActivityTime());
assertEquals(expectedCapabilities, parser.getCapabilities().getIotEdge());
assertEquals(parser.getScope(), scope);
}
use of com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities in project azure-iot-sdk-java by Azure.
the class EnrollmentGroupTest method getDeviceCapabilitiesSucceed.
/* Tests_SRS_ENROLLMENT_GROUP_34_074: [This function shall return the saved capabilities.] */
@Test
public void getDeviceCapabilitiesSucceed() {
EnrollmentGroup enrollmentGroup = makeMockedSymmetricKeyEnrollmentGroup();
final DeviceCapabilities capabilities = new DeviceCapabilities();
Deencapsulation.setField(enrollmentGroup, "capabilities", capabilities);
// act
DeviceCapabilities actualDeviceCapabilities = enrollmentGroup.getCapabilities();
// assert
assertEquals(capabilities, actualDeviceCapabilities);
}
use of com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities in project azure-iot-sdk-java by Azure.
the class EnrollmentGroupTest method setDeviceCapabilitiesSucceed.
/* Tests_SRS_ENROLLMENT_GROUP_34_073: [This function shall save the provided capabilities.] */
@Test
public void setDeviceCapabilitiesSucceed() {
// arrange
EnrollmentGroup enrollmentGroup = makeMockedSymmetricKeyEnrollmentGroup();
final DeviceCapabilities capabilities = new DeviceCapabilities();
assertNotEquals(capabilities, Deencapsulation.getField(enrollmentGroup, "capabilities"));
// act
enrollmentGroup.setCapabilities(capabilities);
// assert
assertEquals(capabilities, Deencapsulation.getField(enrollmentGroup, "capabilities"));
}
Aggregations