Search in sources :

Example 6 with Module

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

Example 7 with Module

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

Example 8 with Module

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

Example 9 with Module

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;
}
Also used : SocketException(java.net.SocketException) UnknownHostException(java.net.UnknownHostException) Module(com.microsoft.azure.sdk.iot.service.Module)

Example 10 with Module

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);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Module(com.microsoft.azure.sdk.iot.service.Module) URL(java.net.URL)

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