Search in sources :

Example 1 with Module

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

the class ModuleManagerSample method GetModule.

private static void GetModule() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Module returnModule;
    try {
        returnModule = registryManager.getModule(SampleUtils.deviceId, SampleUtils.moduleId0);
        System.out.println("Module: " + returnModule.getId());
        System.out.println("Module primary key: " + returnModule.getPrimaryKey());
        System.out.println("Module secondary key: " + returnModule.getSecondaryKey());
        System.out.println("Module eTag: " + returnModule.geteTag());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    List<Module> list = registryManager.getModulesOnDevice(SampleUtils.deviceId);
    for (Module module : list) {
        System.out.println("Module: " + module.getId());
        System.out.println("Module primary key: " + module.getPrimaryKey());
        System.out.println("Module secondary key: " + module.getSecondaryKey());
        System.out.println("Module eTag: " + module.geteTag());
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) Module(com.microsoft.azure.sdk.iot.service.Module) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 2 with Module

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

the class ModuleTest method conversionFromDeviceParserWithCertificateAuthorityAuthentication.

// 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 conversionFromDeviceParserWithCertificateAuthorityAuthentication() {
    // arrange
    DeviceParser parserCA = new DeviceParser();
    parserCA.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
    parserCA.getAuthenticationParser().setType(AuthenticationTypeParser.CERTIFICATE_AUTHORITY);
    parserCA.setDeviceId("deviceCA");
    parserCA.setModuleId("moduleCA");
    parserCA.setManagedBy("xyz");
    // act
    Module moduleCA = reflectivelyInvokeDeviceParserConstructor(parserCA);
    // assert
    assertNull(moduleCA.getPrimaryThumbprint());
    assertNull(moduleCA.getSecondaryThumbprint());
    assertNull(moduleCA.getSymmetricKey());
    assertEquals(AuthenticationType.CERTIFICATE_AUTHORITY, moduleCA.getAuthenticationType());
    assertEquals("xyz", moduleCA.getManagedBy());
}
Also used : Module(com.microsoft.azure.sdk.iot.service.Module) Test(org.junit.Test)

Example 3 with Module

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

the class ModuleTest method conversionFromDeviceParserWithSelfSignedAuthentication.

// 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 conversionFromDeviceParserWithSelfSignedAuthentication() {
    // arrange
    DeviceParser parserSelf = new DeviceParser();
    parserSelf.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
    parserSelf.getAuthenticationParser().setType(AuthenticationTypeParser.SELF_SIGNED);
    parserSelf.getAuthenticationParser().setThumbprint(new X509ThumbprintParser(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT));
    parserSelf.setDeviceId("deviceSelf");
    parserSelf.setModuleId("moduleSelf");
    parserSelf.setManagedBy("xyz");
    // act
    Module moduleSelf = reflectivelyInvokeDeviceParserConstructor(parserSelf);
    // assert
    assertNull(moduleSelf.getSymmetricKey());
    assertNotNull(moduleSelf.getPrimaryThumbprint());
    assertNotNull(moduleSelf.getSecondaryThumbprint());
    assertEquals(AuthenticationType.SELF_SIGNED, moduleSelf.getAuthenticationType());
    assertEquals("xyz", moduleSelf.getManagedBy());
}
Also used : Module(com.microsoft.azure.sdk.iot.service.Module) Test(org.junit.Test)

Example 4 with Module

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

the class ModuleTest method constructor2InitializePropertiesToDefault.

// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_009: [The constructor shall initialize all properties to default values]
@Test
public void constructor2InitializePropertiesToDefault() {
    // 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, AuthenticationType.class }, deviceId, moduleId, AuthenticationType.SAS);
    // 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(0, module.getCloudToDeviceMessageCount());
    assertEquals("", module.getManagedBy());
}
Also used : Module(com.microsoft.azure.sdk.iot.service.Module) Test(org.junit.Test)

Example 5 with Module

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

the class ModuleTest method conversionToDeviceParser.

// 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 conversionToDeviceParser() {
    // arrange
    String expectedDeviceId = "deviceCA";
    String expectedModuleId = "moduleCA";
    int expectedCloudToDeviceMessageCount = 23;
    DeviceConnectionState expectedConnectionState = DeviceConnectionState.Connected;
    String expectedConnectionStateUpdatedTime = "2001-09-09T09:09:09";
    String expectedETag = "1234";
    String expectedGenerationId = "5678";
    String expectedLastActivityTime = "2001-09-09T09:09:09";
    String expectedManagedBy = "jkik";
    Module module = Module.createModule(expectedDeviceId, expectedModuleId, AuthenticationType.SAS);
    Deencapsulation.setField(module, "cloudToDeviceMessageCount", expectedCloudToDeviceMessageCount);
    Deencapsulation.setField(module, "connectionState", expectedConnectionState);
    Deencapsulation.setField(module, "connectionStateUpdatedTime", expectedConnectionStateUpdatedTime);
    Deencapsulation.setField(module, "eTag", expectedETag);
    Deencapsulation.setField(module, "generationId", expectedGenerationId);
    Deencapsulation.setField(module, "lastActivityTime", expectedLastActivityTime);
    Deencapsulation.setField(module, "managedBy", expectedManagedBy);
    // act
    DeviceParser parser = reflectivelyInvokeToDeviceParser(module);
    // assert
    assertEquals(AuthenticationTypeParser.SAS, parser.getAuthenticationParser().getType());
    assertEquals(expectedCloudToDeviceMessageCount, parser.getCloudToDeviceMessageCount());
    assertEquals(expectedConnectionState.toString(), parser.getConnectionState());
    assertEquals(ParserUtility.getDateTimeUtc(expectedConnectionStateUpdatedTime), parser.getConnectionStateUpdatedTime());
    assertEquals(expectedDeviceId, parser.getDeviceId());
    assertEquals(expectedModuleId, parser.getModuleId());
    assertEquals("\"" + expectedETag + "\"", parser.geteTag());
    assertEquals(expectedGenerationId, parser.getGenerationId());
    assertEquals(ParserUtility.getDateTimeUtc(expectedLastActivityTime), parser.getLastActivityTime());
    assertEquals(expectedManagedBy, parser.getManagedBy());
}
Also used : DeviceConnectionState(com.microsoft.azure.sdk.iot.service.DeviceConnectionState) Module(com.microsoft.azure.sdk.iot.service.Module) 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