Search in sources :

Example 61 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class RegistryManagerTests method crud_device_e2e_X509_self_signed.

@Test
public void crud_device_e2e_X509_self_signed() throws Exception {
    // -Create-//
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    Device deviceAdded = Device.createDevice(testInstance.deviceId, AuthenticationType.SELF_SIGNED);
    deviceAdded.setThumbprintFinal(primaryThumbprint, secondaryThumbprint);
    Tools.addDeviceWithRetry(testInstance.registryManager, deviceAdded);
    // -Read-//
    Device deviceRetrieved = testInstance.registryManager.getDevice(testInstance.deviceId);
    // -Update-//
    Device deviceUpdated = testInstance.registryManager.getDevice(testInstance.deviceId);
    deviceUpdated.setThumbprintFinal(primaryThumbprint2, secondaryThumbprint2);
    deviceUpdated = testInstance.registryManager.updateDevice(deviceUpdated);
    // -Delete-//
    testInstance.registryManager.removeDevice(testInstance.deviceId);
    // Assert
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, deviceAdded.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, deviceRetrieved.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), AuthenticationType.SELF_SIGNED, deviceAdded.getAuthenticationType());
    assertEquals(buildExceptionMessage("", hostName), AuthenticationType.SELF_SIGNED, deviceRetrieved.getAuthenticationType());
    assertEquals(buildExceptionMessage("", hostName), primaryThumbprint, deviceAdded.getPrimaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint, deviceAdded.getSecondaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), primaryThumbprint, deviceRetrieved.getPrimaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint, deviceRetrieved.getSecondaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), primaryThumbprint2, deviceUpdated.getPrimaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint2, deviceUpdated.getSecondaryThumbprint());
    assertTrue(buildExceptionMessage("", hostName), deviceWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 62 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class RegistryManagerTests method crud_module_e2e_X509_self_signed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void crud_module_e2e_X509_self_signed() throws Exception {
    // Arrange
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
    Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
    deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
    // -Create-//
    Module moduleAdded = Module.createModule(testInstance.deviceId, testInstance.moduleId, AuthenticationType.SELF_SIGNED);
    moduleAdded.setThumbprintFinal(primaryThumbprint, secondaryThumbprint);
    Tools.addModuleWithRetry(testInstance.registryManager, moduleAdded);
    // -Read-//
    Module moduleRetrieved = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
    // -Update-//
    Module moduleUpdated = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
    moduleUpdated.setThumbprintFinal(primaryThumbprint2, secondaryThumbprint2);
    moduleUpdated = testInstance.registryManager.updateModule(moduleUpdated);
    // -Delete-//
    testInstance.registryManager.removeModule(testInstance.deviceId, testInstance.moduleId);
    // Assert
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleAdded.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleAdded.getId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleRetrieved.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleRetrieved.getId());
    assertEquals(buildExceptionMessage("", hostName), AuthenticationType.SELF_SIGNED, moduleAdded.getAuthenticationType());
    assertEquals(buildExceptionMessage("", hostName), AuthenticationType.SELF_SIGNED, moduleRetrieved.getAuthenticationType());
    assertEquals(buildExceptionMessage("", hostName), primaryThumbprint, moduleAdded.getPrimaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint, moduleAdded.getSecondaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), primaryThumbprint, moduleRetrieved.getPrimaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint, moduleRetrieved.getSecondaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), primaryThumbprint2, moduleUpdated.getPrimaryThumbprint());
    assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint2, moduleUpdated.getSecondaryThumbprint());
    assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Module(com.microsoft.azure.sdk.iot.service.Module) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 63 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class RegistryManagerTests method crud_module_e2e_X509_CA_signed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void crud_module_e2e_X509_CA_signed() throws Exception {
    // Arrange
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
    Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
    Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
    deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
    // -Create-//
    Module moduleAdded = Module.createModule(testInstance.deviceId, testInstance.moduleId, AuthenticationType.CERTIFICATE_AUTHORITY);
    Tools.addModuleWithRetry(testInstance.registryManager, moduleAdded);
    // -Read-//
    Module moduleRetrieved = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
    // -Delete-//
    testInstance.registryManager.removeModule(testInstance.deviceId, testInstance.moduleId);
    testInstance.registryManager.removeDevice(testInstance.deviceId);
    // Assert
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleAdded.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleAdded.getId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleRetrieved.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleRetrieved.getId());
    assertNull(buildExceptionMessage("", hostName), moduleAdded.getPrimaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), moduleAdded.getSecondaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), moduleRetrieved.getPrimaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), moduleRetrieved.getSecondaryThumbprint());
    assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Module(com.microsoft.azure.sdk.iot.service.Module) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 64 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class RegistryManagerTests method registryManagerTokenRenewalWithAzureSasCredential.

@Test
public void registryManagerTokenRenewalWithAzureSasCredential() throws Exception {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
    RegistryManager registryManager = new RegistryManager(iotHubConnectionStringObj.getHostName(), azureSasCredential);
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance(registryManager);
    Device device1 = Device.createDevice(testInstance.deviceId + "-1", AuthenticationType.SAS);
    Device device2 = Device.createDevice(testInstance.deviceId + "-2", AuthenticationType.SAS);
    Device device3 = Device.createDevice(testInstance.deviceId + "-3", AuthenticationType.SAS);
    azureSasCredential.update(serviceSasToken.toString());
    // add first device just to make sure that the first credential update worked
    testInstance.registryManager.addDevice(device1);
    // deliberately expire the SAS token to provoke a 401 to ensure that the registry manager is using the shared
    // access signature that is set here.
    azureSasCredential.update(SasTokenTools.makeSasTokenExpired(serviceSasToken.toString()));
    try {
        testInstance.registryManager.addDevice(device2);
        fail("Expected adding a device to throw unauthorized exception since an expired SAS token was used, but no exception was thrown");
    } catch (IotHubUnathorizedException e) {
        log.debug("IotHubUnauthorizedException was thrown as expected, continuing test");
    }
    // Renew the expired shared access signature
    serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    azureSasCredential.update(serviceSasToken.toString());
    // adding the final device should succeed since the shared access signature has been renewed
    testInstance.registryManager.addDevice(device3);
}
Also used : IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) Device(com.microsoft.azure.sdk.iot.service.Device) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubUnathorizedException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnathorizedException) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 65 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class RegistryManagerTests method crud_device_e2e_X509_CA_signed.

@Test
public void crud_device_e2e_X509_CA_signed() throws Exception {
    // -Create-//
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    Device deviceAdded = Device.createDevice(testInstance.deviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
    Tools.addDeviceWithRetry(testInstance.registryManager, deviceAdded);
    // -Read-//
    Device deviceRetrieved = testInstance.registryManager.getDevice(testInstance.deviceId);
    // -Update-//
    Device deviceUpdated = testInstance.registryManager.getDevice(testInstance.deviceId);
    deviceUpdated.setStatus(DeviceStatus.Disabled);
    deviceUpdated = testInstance.registryManager.updateDevice(deviceUpdated);
    // -Delete-//
    testInstance.registryManager.removeDevice(testInstance.deviceId);
    // Assert
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, deviceAdded.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, deviceRetrieved.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), AuthenticationType.CERTIFICATE_AUTHORITY, deviceRetrieved.getAuthenticationType());
    assertEquals(buildExceptionMessage("", hostName), DeviceStatus.Disabled, deviceUpdated.getStatus());
    assertNull(buildExceptionMessage("", hostName), deviceAdded.getPrimaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), deviceAdded.getSecondaryKey());
    assertNull(buildExceptionMessage("", hostName), deviceRetrieved.getPrimaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), deviceRetrieved.getSecondaryThumbprint());
    assertTrue(buildExceptionMessage("", hostName), deviceWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Aggregations

Device (com.microsoft.azure.sdk.iot.service.Device)68 Test (org.junit.Test)46 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)21 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)17 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)15 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)13 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)12 IOException (java.io.IOException)11 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)11 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)11 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)10 ArrayList (java.util.ArrayList)10 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)7 RegistryManagerOptions (com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)5 AzureSasCredential (com.azure.core.credential.AzureSasCredential)4 DeviceCapabilities (com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities)4 ClientOptions (com.microsoft.azure.sdk.iot.device.ClientOptions)4 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)4 Module (com.microsoft.azure.sdk.iot.service.Module)4