use of com.microsoft.azure.sdk.iot.service.Module in project azure-iot-sdk-java by Azure.
the class ModuleTest method constructorInitializePropertiesToDefault.
// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_007: [The constructor shall initialize all properties to default values]
@Test
public void constructorInitializePropertiesToDefault() {
// Arrange
String deviceId = "device-xxx";
String moduleId = "module-xxx";
String utcTimeDefault = "0001-01-01T00:00:00";
String offsetTimeDefault = "0001-01-01T00:00:00-00:00";
// Act
Module module = Deencapsulation.newInstance(Module.class, new Class[] { String.class, String.class, SymmetricKey.class }, deviceId, moduleId, null);
// Assert
assertEquals(deviceId, module.getDeviceId());
assertEquals(moduleId, module.getId());
assertNotNull(module.getSymmetricKey());
assertEquals("", module.getGenerationId());
assertEquals("", module.geteTag());
assertEquals(DeviceConnectionState.Disconnected, module.getConnectionState());
assertEquals(utcTimeDefault, module.getConnectionStateUpdatedTime());
assertEquals(offsetTimeDefault, module.getLastActivityTime());
assertEquals("", module.getManagedBy());
}
use of com.microsoft.azure.sdk.iot.service.Module in project azure-iot-sdk-java by Azure.
the class ModuleTest method conversionFromDeviceParserWithSASAuthentication.
// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_011: [This constructor shall create a new Module object using the values within the provided parser.]
@Test
public void conversionFromDeviceParserWithSASAuthentication() {
// arrange
DeviceParser parserSAS = new DeviceParser();
parserSAS.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
parserSAS.getAuthenticationParser().setType(AuthenticationTypeParser.SAS);
parserSAS.getAuthenticationParser().setSymmetricKey(new SymmetricKeyParser(SAMPLE_KEY, SAMPLE_KEY));
parserSAS.setDeviceId("deviceSAS");
parserSAS.setModuleId("moduleSelf");
parserSAS.setManagedBy("xyz");
// act
Module moduleSAS = reflectivelyInvokeDeviceParserConstructor(parserSAS);
// assert
assertNull(moduleSAS.getPrimaryThumbprint());
assertNull(moduleSAS.getSecondaryThumbprint());
assertNotNull(moduleSAS.getSymmetricKey());
assertEquals(AuthenticationType.SAS, moduleSAS.getAuthenticationType());
assertEquals("xyz", moduleSAS.getManagedBy());
}
use of com.microsoft.azure.sdk.iot.service.Module in project azure-iot-sdk-java by Azure.
the class ModuleTest method conversionToDeviceParserWithSelfSignedAuthentication.
// 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 conversionToDeviceParserWithSelfSignedAuthentication() {
// arrange
Module moduleSelf = Module.createModule("deviceSelf", "moduleSelf", AuthenticationType.SELF_SIGNED);
// act
DeviceParser parserSelf = reflectivelyInvokeToDeviceParser(moduleSelf);
// assert
assertEquals(AuthenticationTypeParser.SELF_SIGNED, parserSelf.getAuthenticationParser().getType());
}
use of com.microsoft.azure.sdk.iot.service.Module in project azure-iot-sdk-java by Azure.
the class Tools method getModuleWithRetry.
public static Module getModuleWithRetry(RegistryManager registryManager, String deviceid, String moduleid) throws IotHubException, IOException, InterruptedException {
long startTime = System.currentTimeMillis();
Module ret = null;
while (System.currentTimeMillis() - startTime < RETRY_TIMEOUT_ON_NETWORK_FAILURE_MILLISECONDS) {
try {
ret = registryManager.getModule(deviceid, moduleid);
break;
} catch (UnknownHostException | SocketException e) {
System.out.println("Failed to get module ");
e.printStackTrace();
Thread.sleep(WAIT_FOR_RETRY);
if (System.currentTimeMillis() - startTime >= RETRY_TIMEOUT_ON_NETWORK_FAILURE_MILLISECONDS) {
throw e;
}
}
}
return ret;
}
use of com.microsoft.azure.sdk.iot.service.Module in project azure-iot-sdk-java by Azure.
the class Tools method addModules.
private static void addModules(Iterable<Module> modules, String connectionString) throws IOException, IotHubException {
if (modules == null) {
throw new IllegalArgumentException("modules cannot be null");
}
IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
URL url = getBulkDeviceAddUrl(iotHubConnectionString);
List<ExportImportDeviceParser> parsers = new ArrayList<>();
for (Module module : modules) {
ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
exportImportDevice.setId(module.getDeviceId());
exportImportDevice.setModuleId(module.getId());
AuthenticationParser authenticationParser = new AuthenticationParser();
if (module.getAuthenticationType() == AuthenticationType.SAS) {
authenticationParser.setType(AuthenticationTypeParser.SAS);
authenticationParser.setSymmetricKey(new SymmetricKeyParser(module.getSymmetricKey().getPrimaryKey(), module.getSymmetricKey().getSecondaryKey()));
} else {
authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
authenticationParser.setThumbprint(new X509ThumbprintParser(module.getPrimaryThumbprint(), module.getSecondaryThumbprint()));
}
exportImportDevice.setAuthentication(authenticationParser);
exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
parsers.add(exportImportDevice);
}
ExportImportDevicesParser body = new ExportImportDevicesParser();
body.setExportImportDevices(parsers);
bulkRegistryOperation(body.toJson(), url, connectionString);
}
Aggregations