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());
}
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;
}
}
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));
}
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));
}
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));
}
Aggregations