Search in sources :

Example 1 with DeviceCapabilities

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();
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 2 with DeviceCapabilities

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());
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) Test(org.junit.Test)

Example 3 with DeviceCapabilities

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);
}
Also used : DeviceConnectionState(com.microsoft.azure.sdk.iot.service.DeviceConnectionState) Device(com.microsoft.azure.sdk.iot.service.Device) DeviceStatus(com.microsoft.azure.sdk.iot.service.DeviceStatus) DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) Test(org.junit.Test)

Example 4 with DeviceCapabilities

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);
}
Also used : DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) Test(org.junit.Test)

Example 5 with DeviceCapabilities

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"));
}
Also used : DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) Test(org.junit.Test)

Aggregations

DeviceCapabilities (com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities)14 Test (org.junit.Test)12 Device (com.microsoft.azure.sdk.iot.service.Device)4 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)2 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)2 RegisterManager (com.microsoft.azure.sdk.iot.deps.twin.RegisterManager)1 DeviceConnectionState (com.microsoft.azure.sdk.iot.service.DeviceConnectionState)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)1 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)1 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)1 IOException (java.io.IOException)1 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)1 DeviceProvisioningServiceTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DeviceProvisioningServiceTest)1 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)1