Search in sources :

Example 16 with ExportImportDevice

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

the class ExportImportDeviceTest method constructorSavesDeviceIdAndAuthType.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_34_051: [This constructor shall save the provided deviceId and authenticationType to itself.]
@Test
public void constructorSavesDeviceIdAndAuthType() {
    // arrange
    String deviceId = "someDevice";
    // act
    ExportImportDevice device = new ExportImportDevice(deviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
    // assert
    assertEquals(AuthenticationType.CERTIFICATE_AUTHORITY, device.getAuthenticationFinal().getAuthenticationType());
    assertEquals(deviceId, device.getId());
}
Also used : ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Example 17 with ExportImportDevice

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

the class ExportImportDeviceTest method conversionFromDeviceParser.

// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_052: [This constructor shall use the properties of the provided parser object to set the new ExportImportDevice's properties.]
@Test
public void conversionFromDeviceParser() {
    // arrange
    ExportImportDeviceParser parserCA = new ExportImportDeviceParser();
    parserCA.setAuthentication(Deencapsulation.newInstance(AuthenticationParser.class));
    parserCA.getAuthenticationFinal().setType(AuthenticationTypeParser.CERTIFICATE_AUTHORITY);
    parserCA.setStatus("Enabled");
    parserCA.setImportMode("Create");
    parserCA.setId("deviceCA");
    ExportImportDeviceParser parserSelf = new ExportImportDeviceParser();
    parserSelf.setAuthentication(Deencapsulation.newInstance(AuthenticationParser.class));
    parserSelf.getAuthenticationFinal().setType(AuthenticationTypeParser.SELF_SIGNED);
    parserSelf.getAuthenticationFinal().setThumbprint(new X509ThumbprintParser(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT));
    parserSelf.setId("deviceSelf");
    ExportImportDeviceParser parserSAS = new ExportImportDeviceParser();
    parserSAS.setAuthentication(Deencapsulation.newInstance(AuthenticationParser.class));
    parserSAS.getAuthenticationFinal().setType(AuthenticationTypeParser.SAS);
    parserSAS.getAuthenticationFinal().setSymmetricKey(new SymmetricKeyParser(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT));
    parserSAS.setId("deviceSAS");
    // act
    ExportImportDevice deviceCA = reflectivelyInvokeExportImportDeviceParserConstructor(parserCA);
    ExportImportDevice deviceSelf = reflectivelyInvokeExportImportDeviceParserConstructor(parserSelf);
    ExportImportDevice deviceSAS = reflectivelyInvokeExportImportDeviceParserConstructor(parserSAS);
    // assert
    assertEquals(AuthenticationType.CERTIFICATE_AUTHORITY, deviceCA.getAuthenticationFinal().getAuthenticationType());
    assertEquals(AuthenticationType.SELF_SIGNED, deviceSelf.getAuthenticationFinal().getAuthenticationType());
    assertEquals(AuthenticationType.SAS, deviceSAS.getAuthenticationFinal().getAuthenticationType());
    assertEquals(ImportMode.Create, deviceCA.getImportMode());
    assertEquals(DeviceStatus.Enabled, deviceCA.getStatus());
}
Also used : ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Example 18 with ExportImportDevice

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

the class ExportImportTests method export_import_storage_auth_e2e.

private static void export_import_storage_auth_e2e(StorageAuthenticationType storageAuthenticationType) throws Exception {
    List<ExportImportDevice> devicesForImport = createListofDevices();
    // importing devices - create mode
    runImportJob(devicesForImport, ImportMode.CreateOrUpdate, Optional.of(storageAuthenticationType));
    List<ExportImportDevice> exportedDevices = runExportJob(Optional.of(storageAuthenticationType));
    for (ExportImportDevice importedDevice : devicesForImport) {
        if (!exportedDevices.contains(importedDevice)) {
            Assert.fail("Exported devices list does not contain device with id: " + importedDevice.getId());
        }
    }
    // importing devices - delete mode
    runImportJob(devicesForImport, ImportMode.Delete, Optional.of(storageAuthenticationType));
    exportedDevices = runExportJob(Optional.of(storageAuthenticationType));
    for (ExportImportDevice importedDevice : devicesForImport) {
        if (exportedDevices.contains(importedDevice)) {
            Assert.fail("Device with id: " + importedDevice.getId() + " was not deleted by the import job");
        }
    }
}
Also used : ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice)

Aggregations

ExportImportDevice (com.microsoft.azure.sdk.iot.service.ExportImportDevice)18 Test (org.junit.Test)13 AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)8 ArrayList (java.util.ArrayList)3 BlobItem (com.azure.storage.blob.models.BlobItem)1 BlobInputStream (com.azure.storage.blob.specialized.BlobInputStream)1 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)1 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)1 Device (com.microsoft.azure.sdk.iot.service.Device)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 ImportMode (com.microsoft.azure.sdk.iot.service.ImportMode)1 JobProperties (com.microsoft.azure.sdk.iot.service.JobProperties)1 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)1 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)1 IotHubTooManyDevicesException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubTooManyDevicesException)1 Scanner (java.util.Scanner)1 AfterClass (org.junit.AfterClass)1 Ignore (org.junit.Ignore)1 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1