Search in sources :

Example 16 with Module

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

the class ModuleTest method conversionToDeviceParserWithSASAuthentication.

// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_010: [This method shall return a new instance of a DeviceParser object that is populated using the properties of this.]
@Test
public void conversionToDeviceParserWithSASAuthentication() {
    // arrange
    Module moduleSAS = Module.createModule("deviceSAS", "moduleSelf", AuthenticationType.SAS);
    // act
    DeviceParser parserSAS = reflectivelyInvokeToDeviceParser(moduleSAS);
    // assert
    assertEquals(AuthenticationTypeParser.SAS, parserSAS.getAuthenticationParser().getType());
}
Also used : Module(com.microsoft.azure.sdk.iot.service.Module) Test(org.junit.Test)

Example 17 with Module

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

the class Tools method getSasTestModule.

private static TestModuleIdentity getSasTestModule(String iotHubConnectionString, IotHubClientProtocol protocol, boolean needCleanTwin) throws URISyntaxException, IOException, IotHubException, InterruptedException, ModuleClientException, GeneralSecurityException {
    // remove an identity from the queue.
    synchronized (testSasModuleQueueLock) {
        TestModuleIdentity testModuleIdentity;
        if (!needCleanTwin && testSasModuleWithTwinQueue.size() > 0) {
            log.debug("Acquiring test module from testSasModuleWithTwinQueue");
            testModuleIdentity = testSasModuleWithTwinQueue.remove();
        } else {
            if (testSasModuleQueue.size() < 1) {
                // No cached modules to return, so create a new set of modules to cache, and return one of the newly created modules
                log.debug("Proactively adding another {} modules to the SAS test module queue", PROACTIVE_TEST_DEVICE_REGISRATION_COUNT);
                List<Device> devices = new ArrayList<>();
                List<Module> modulesToAdd = new ArrayList<>();
                for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
                    TestDeviceIdentity testDeviceIdentity = getTestDevice(iotHubConnectionString, protocol, AuthenticationType.SAS, needCleanTwin);
                    devices.add(testDeviceIdentity.device);
                    modulesToAdd.add(Module.createModule(testDeviceIdentity.device.getDeviceId(), "test-module-" + UUID.randomUUID(), AuthenticationType.SAS));
                }
                addModules(modulesToAdd, iotHubConnectionString);
                for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
                    testSasModuleQueue.add(new TestModuleIdentity(null, devices.get(i), modulesToAdd.get(i)));
                }
            }
            log.debug("Acquiring test module from testSasModuleQueue");
            testModuleIdentity = testSasModuleQueue.remove();
        }
        ModuleClient moduleClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, testModuleIdentity.device, testModuleIdentity.module), protocol);
        testModuleIdentity.setModuleClient(moduleClient);
        return testModuleIdentity;
    }
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) ArrayList(java.util.ArrayList) Module(com.microsoft.azure.sdk.iot.service.Module) ModuleClient(com.microsoft.azure.sdk.iot.device.ModuleClient)

Example 18 with Module

use of com.microsoft.azure.sdk.iot.service.Module 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 19 with Module

use of com.microsoft.azure.sdk.iot.service.Module 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 20 with Module

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

the class RegistryManagerTests method crud_module_e2e.

@Test
@StandardTierHubOnlyTest
public void crud_module_e2e() throws Exception {
    // Arrange
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    SymmetricKey expectedSymmetricKey = new SymmetricKey();
    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.createFromId(testInstance.deviceId, testInstance.moduleId, null);
    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.getSymmetricKey().setPrimaryKeyFinal(expectedSymmetricKey.getPrimaryKey());
    moduleUpdated = testInstance.registryManager.updateModule(moduleUpdated);
    // -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());
    assertEquals(buildExceptionMessage("", hostName), expectedSymmetricKey.getPrimaryKey(), moduleUpdated.getPrimaryKey());
    assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) 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)

Aggregations

Module (com.microsoft.azure.sdk.iot.service.Module)23 Test (org.junit.Test)14 Device (com.microsoft.azure.sdk.iot.service.Device)5 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)3 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)3 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)3 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)3 ModuleClient (com.microsoft.azure.sdk.iot.device.ModuleClient)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)2 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 AuthenticationParser (com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser)1 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)1 SymmetricKeyParser (com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser)1 X509ThumbprintParser (com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser)1