use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved.
// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_061: [If this device uses self signed authentication, but does not have a primary and secondary thumbprint saved, an IllegalStateException shall be thrown.]
@Test(expected = IllegalStateException.class)
public void toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved() {
// arrange
ExportImportDevice device = new ExportImportDevice();
device.setId("someDevice");
AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SELF_SIGNED);
X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class);
Deencapsulation.setField(thumbprint, "primaryThumbprint", null);
Deencapsulation.setField(authentication, "thumbprint", thumbprint);
device.setAuthentication(authentication);
// act
reflectivelyInvokeToExportImportDeviceParser(device);
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportTests method runExportJob.
private static List<ExportImportDevice> runExportJob(Optional<StorageAuthenticationType> storageAuthenticationType) throws Exception {
Boolean excludeKeys = false;
String containerSasUri = getContainerSasUri(exportContainer);
boolean exportJobScheduled = false;
JobProperties exportJob = null;
while (!exportJobScheduled) {
try {
if (storageAuthenticationType.isPresent()) {
JobProperties exportJobProperties = JobProperties.createForExportJob(containerSasUri, excludeKeys, storageAuthenticationType.get());
exportJob = registryManager.exportDevices(exportJobProperties);
} else {
exportJob = registryManager.exportDevices(containerSasUri, excludeKeys);
}
exportJobScheduled = true;
} catch (IotHubTooManyDevicesException e) {
// test is being throttled, wait a while and try again
Thread.sleep(10 * 1000);
}
}
JobProperties.JobStatus jobStatus;
long startTime = System.currentTimeMillis();
while (true) {
exportJob = registryManager.getJob(exportJob.getJobId());
jobStatus = exportJob.getStatus();
if (jobStatus == JobProperties.JobStatus.COMPLETED || jobStatus == JobProperties.JobStatus.FAILED) {
break;
}
if (System.currentTimeMillis() - startTime > EXPORT_JOB_TIMEOUT_MILLISECONDS) {
fail("Timed out waiting for the export job to complete");
}
Thread.sleep(100);
}
String exportedDevicesJson = "";
for (BlobItem blobItem : exportContainer.listBlobs()) {
BlobInputStream stream = exportContainer.getBlobClient(blobItem.getName()).openInputStream();
try (Scanner scanner = new Scanner(stream, StandardCharsets.UTF_8.name())) {
exportedDevicesJson = scanner.next();
}
}
List<ExportImportDevice> result = new ArrayList<>();
Scanner scanner = new Scanner(exportedDevicesJson);
while (scanner.hasNextLine()) {
String exportImportDeviceJson = scanner.nextLine();
ExportImportDeviceParser parser = new ExportImportDeviceParser(exportImportDeviceJson);
ExportImportDevice device = Deencapsulation.newInstance(ExportImportDevice.class, new Class[] { ExportImportDeviceParser.class }, parser);
device.setImportMode(ImportMode.CreateOrUpdate);
result.add(device);
}
scanner.close();
if (jobStatus != JobProperties.JobStatus.COMPLETED) {
Assert.fail("The export job was not completed successfully");
}
return result;
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportTests method tearDown.
@AfterClass
public static void tearDown() throws Exception {
// Deleting all devices created as a part of the bulk import-export test
List<ExportImportDevice> exportedDevices = runExportJob(Optional.empty());
List<ExportImportDevice> devicesToBeDeleted = new ArrayList<>();
for (ExportImportDevice device : exportedDevices) {
if (device.getId().startsWith("java-bulk-test-")) {
devicesToBeDeleted.add(device);
}
}
runImportJob(devicesToBeDeleted, ImportMode.Delete, Optional.empty());
// Cleaning up the containers
importContainer.delete();
exportContainer.delete();
if (registryManager != null) {
registryManager.close();
registryManager = null;
}
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportTests method export_import_e2e.
@Test(timeout = IMPORT_EXPORT_TEST_TIMEOUT_MILLISECONDS)
@ContinuousIntegrationTest
@Ignore
public void export_import_e2e() throws Exception {
List<ExportImportDevice> devicesForImport = createListofDevices();
// importing devices - create mode
runImportJob(devicesForImport, ImportMode.CreateOrUpdate, Optional.empty());
List<ExportImportDevice> exportedDevices = runExportJob(Optional.empty());
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.empty());
exportedDevices = runExportJob(Optional.empty());
for (ExportImportDevice importedDevice : devicesForImport) {
if (exportedDevices.contains(importedDevice)) {
Assert.fail("Device with id: " + importedDevice.getId() + " was not deleted by the import job");
}
}
}
use of com.microsoft.azure.sdk.iot.service.ExportImportDevice in project azure-iot-sdk-java by Azure.
the class ExportImportTests method createListofDevices.
private static List<ExportImportDevice> createListofDevices() {
// Creating the list of devices to be created, then deleted
Integer numberOfDevices = 10;
List<ExportImportDevice> devicesForImport = new ArrayList<>(numberOfDevices);
for (int i = 0; i < numberOfDevices; i++) {
String deviceId = "java-bulk-test-" + UUID.randomUUID().toString();
Device device = Device.createFromId(deviceId, null, null);
AuthenticationMechanism authentication = new AuthenticationMechanism(device.getSymmetricKey());
ExportImportDevice deviceToAdd = new ExportImportDevice();
deviceToAdd.setId(deviceId);
deviceToAdd.setAuthentication(authentication);
deviceToAdd.setStatus(DeviceStatus.Enabled);
TwinCollection tags = new TwinCollection();
tags.putFinal("test01", "firstvalue");
deviceToAdd.setTags(tags);
devicesForImport.add(deviceToAdd);
}
return devicesForImport;
}
Aggregations