use of com.microsoft.azure.sdk.iot.service.Device 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;
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class Tools method getSasTestDevice.
private static TestDeviceIdentity getSasTestDevice(String iotHubConnectionString, IotHubClientProtocol protocol, boolean needCleanTwin) throws URISyntaxException, IOException, IotHubException, GeneralSecurityException {
// and the subsequent callers just used one of those devices
synchronized (testSasDeviceQueueLock) {
TestDeviceIdentity testDeviceIdentity;
if (!needCleanTwin && testSasDeviceWithTwinQueue.size() > 0) {
log.debug("Acquiring test device from testSasDeviceWithTwinQueue");
testDeviceIdentity = testSasDeviceWithTwinQueue.remove();
} else {
if (testSasDeviceQueue.size() < 1) {
// No cached devices to return, so create a new set of devices to cache, and return one of the newly created devices
log.debug("Proactively adding another {} devices to the SAS test device queue", PROACTIVE_TEST_DEVICE_REGISRATION_COUNT);
List<Device> devicesToAdd = new ArrayList<>();
for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
Device deviceToAdd = Device.createDevice("test-device-" + UUID.randomUUID().toString(), AuthenticationType.SAS);
deviceToAdd.setSymmetricKey(new SymmetricKey());
devicesToAdd.add(deviceToAdd);
}
addDevices(devicesToAdd, iotHubConnectionString);
for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
testSasDeviceQueue.add(new TestDeviceIdentity(null, devicesToAdd.get(i)));
}
}
log.debug("Acquiring test device from testSasDeviceQueue");
testDeviceIdentity = testSasDeviceQueue.remove();
}
testDeviceIdentity.setDeviceClient(new DeviceClient(getRegistyManager(iotHubConnectionString).getDeviceConnectionString(testDeviceIdentity.getDevice()), protocol));
return testDeviceIdentity;
}
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class Tools method getX509TestModule.
private static TestModuleIdentity getX509TestModule(String iotHubConnectionString, IotHubClientProtocol protocol, boolean needCleanTwin) throws URISyntaxException, IOException, IotHubException, InterruptedException, ModuleClientException, GeneralSecurityException {
// remove an identity from the queue.
synchronized (testX509ModuleQueueLock) {
TestModuleIdentity testModuleIdentity;
if (!needCleanTwin && testX509ModuleWithTwinQueue.size() > 0) {
log.debug("Acquiring test module from testX509ModuleWithTwinQueue");
testModuleIdentity = testX509ModuleWithTwinQueue.remove();
} else {
if (testX509ModuleQueue.size() < 1) {
// No cached modules to return, so create a new set of modules to cache, and return one of the newly created modules
log.debug("Proactively adding another {} modules to the SAS test module queue", PROACTIVE_TEST_DEVICE_REGISRATION_COUNT);
List<Device> devices = new ArrayList<>();
List<Module> modulesToAdd = new ArrayList<>();
for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
TestDeviceIdentity testDeviceIdentity = getTestDevice(iotHubConnectionString, protocol, AuthenticationType.SELF_SIGNED, needCleanTwin);
devices.add(testDeviceIdentity.device);
Module module = Module.createModule(testDeviceIdentity.device.getDeviceId(), "test-module-" + UUID.randomUUID(), AuthenticationType.SELF_SIGNED);
String x509Thumbprint = IntegrationTest.x509CertificateGenerator.getX509Thumbprint();
module.setThumbprintFinal(x509Thumbprint, x509Thumbprint);
modulesToAdd.add(module);
}
addModules(modulesToAdd, iotHubConnectionString);
for (int i = 0; i < PROACTIVE_TEST_DEVICE_REGISRATION_COUNT; i++) {
testX509ModuleQueue.add(new TestModuleIdentity(null, devices.get(i), modulesToAdd.get(i)));
}
}
log.debug("Acquiring test module from testX509ModuleQueue");
testModuleIdentity = testX509ModuleQueue.remove();
}
SSLContext sslContext = SSLContextBuilder.buildSSLContext(IntegrationTest.x509CertificateGenerator.getPublicCertificate(), IntegrationTest.x509CertificateGenerator.getPrivateKey());
ModuleClient moduleClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, testModuleIdentity.device, testModuleIdentity.module), protocol, sslContext);
testModuleIdentity.setModuleClient(moduleClient);
return testModuleIdentity;
}
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method createFromId_good_case.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_003: [The constructor shall create a new instance of Device using the given deviceId and return with it]
@Test
public void createFromId_good_case() throws NoSuchAlgorithmException {
// Arrange
String deviceId = "xxx-device";
new Expectations() {
{
Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
}
};
// Act
Device device = Device.createFromId(deviceId, null, null);
// Assert
assertNotEquals(device, null);
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method constructor_initialize_properties.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_006: [The constructor shall initialize all properties to default value]
@Test
public void constructor_initialize_properties() throws NoSuchAlgorithmException {
// Arrange
String utcTimeDefault = "0001-01-01T00:00:00";
String deviceId = "xxx-device";
// Act
Device device = Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
// Assert
assertNotEquals(null, device);
assertNotEquals(device.getSymmetricKey(), null);
assertEquals("xxx-device", device.getDeviceId());
assertEquals("", device.getGenerationId());
assertEquals("", device.geteTag());
assertEquals(DeviceStatus.Enabled, device.getStatus());
assertEquals("", device.getStatusReason());
assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
assertEquals(utcTimeDefault, device.getLastActivityTime());
assertEquals(0, device.getCloudToDeviceMessageCount());
}
Aggregations