Search in sources :

Example 1 with Device

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

the class SendMessagesIT method SendMessagesOverAmqps_multithreaded.

@Test
public void SendMessagesOverAmqps_multithreaded() throws URISyntaxException, IOException, InterruptedException {
    List<Thread> threads = new ArrayList<>(deviceListAmqps.length);
    CountDownLatch cdl = new CountDownLatch(deviceListAmqps.length);
    Integer count = 0;
    for (Device deviceAmqps : deviceListAmqps) {
        Thread thread = new Thread(new TestDevice(deviceAmqps, IotHubClientProtocol.AMQPS, NUM_CONNECTIONS_PER_DEVICE, NUM_MESSAGES_PER_CONNECTION, NUM_KEYS_PER_MESSAGE, SEND_TIMEOUT_MILLISECONDS, cdl));
        thread.start();
        threads.add(thread);
        count++;
    }
    cdl.await();
    if (!succeed.get()) {
        Assert.fail("Sending message over AMQP protocol in parallel failed");
    }
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with Device

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

the class DeviceTest method device_get_all_properties.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_001: [The Device class has the following properties: Id, Etag, Authentication.SymmetricKey, State, StateReason, StateUpdatedTime, ConnectionState, ConnectionStateUpdatedTime, LastActivityTime]
// Assert
@Test(expected = IllegalArgumentException.class)
public void device_get_all_properties() throws NoSuchAlgorithmException {
    // Arrange
    String deviceId = "xxx-device";
    // Act
    Device device = Device.createFromId(deviceId, null, null);
    device.getDeviceId();
    device.getGenerationId();
    device.getSymmetricKey();
    device.getPrimaryKey();
    device.getSecondaryKey();
    device.geteTag();
    device.getStatus();
    device.getStatusReason();
    device.getStatusUpdatedTime();
    device.getConnectionState();
    device.getConnectionStateUpdatedTime();
    device.getLastActivityTime();
    device.getCloudToDeviceMessageCount();
    device.setForceUpdate(true);
    device.setForceUpdate(null);
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 3 with Device

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

the class DeviceTest method constructor_string_empty.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_004: [The constructor shall throw IllegalArgumentException if the input string is empty or null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_string_empty() throws NoSuchAlgorithmException {
    // Arrange
    String deviceId = "";
    // Act
    Device device = Deencapsulation.newInstance(Device.class, deviceId, null, null);
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 4 with Device

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

the class DeviceTest method constructor_create_symmetrickey.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_005: [If the input symmetric key is empty, the constructor shall create
// a new SymmetricKey instance using AES encryption and store it into a member variable]
@Test
public void constructor_create_symmetrickey() throws NoSuchAlgorithmException {
    // Arrange
    String encryptionMethod = "AES";
    String deviceId = "xxx-device";
    new NonStrictExpectations() {

        {
            SymmetricKey symmetricKey = new SymmetricKey();
            KeyGenerator.getInstance(encryptionMethod);
        }
    };
    // Act
    Device device = Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
    // Assert
    assertNotEquals(device.getSymmetricKey(), null);
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 5 with Device

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

the class DeviceTest method constructor_string_null.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_004: [The constructor shall throw IllegalArgumentException if the input string is empty or null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_string_null() throws NoSuchAlgorithmException {
    // Arrange
    String deviceId = null;
    // Act
    Device device = Deencapsulation.newInstance(Device.class, deviceId, null, null);
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Aggregations

Device (com.microsoft.azure.sdk.iot.service.Device)68 Test (org.junit.Test)46 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)21 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)17 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)15 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)13 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)12 IOException (java.io.IOException)11 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)11 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)11 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)10 ArrayList (java.util.ArrayList)10 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)7 RegistryManagerOptions (com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)5 AzureSasCredential (com.azure.core.credential.AzureSasCredential)4 DeviceCapabilities (com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities)4 ClientOptions (com.microsoft.azure.sdk.iot.device.ClientOptions)4 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)4 Module (com.microsoft.azure.sdk.iot.service.Module)4