Search in sources :

Example 16 with Pair

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

the class DeviceTwinDeviceTest method getDesiredReturnsEmptyIfNullMap.

/*
    Tests_SRS_DEVICETWINDEVICE_25_014: [ If the desiredProperties map is null then this method shall return empty set of pairs.]
     */
@Test
public void getDesiredReturnsEmptyIfNullMap() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    //act
    Set<Pair> actualDesProp = testDevice.getDesiredProperties();
    //assert
    assertNotNull(actualDesProp);
    assertTrue(actualDesProp.size() == 0);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 17 with Pair

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

the class DeviceTwinDeviceTest method setDesiredThrowsIfNullInput.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_012: [** If the desiredProperties Set is null then this method shall throw IllegalArgumentException.**]**
     */
@Test(expected = IllegalArgumentException.class)
public void setDesiredThrowsIfNullInput() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testDesProp = null;
    //act
    testDevice.setDesiredProperties(testDesProp);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 18 with Pair

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

the class PairTest method getKeyGets.

/*
    **Tests_SRS_Pair_25_004: [**The function shall return the value of the key corresponding to this Pair.**]**
     */
@Test
public void getKeyGets() {
    //arrange
    Pair testPair = new Pair("TestKey", "TestObject");
    //act
    String key = testPair.getKey();
    //assert
    assertNotNull(testPair);
    assertTrue(key.equals("TestKey"));
}
Also used : Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 19 with Pair

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

the class DeviceTwinSample method main.

/**
     * @param args
     * @throws IOException
     * @throws URISyntaxException
     */
public static void main(String[] args) throws Exception {
    System.out.println("Starting sample...");
    DeviceTwin twinClient = DeviceTwin.createFromConnectionString(iotHubConnectionString);
    DeviceTwinDevice device = new DeviceTwinDevice(deviceId);
    try {
        // Manage complete twin
        System.out.println("Getting device twin");
        twinClient.getTwin(device);
        System.out.println(device);
        //Update Twin Tags and Desired Properties
        Set<Pair> tags = new HashSet<Pair>();
        tags.add(new Pair("HomeID", UUID.randomUUID()));
        device.setTags(tags);
        Set<Pair> desProp = new HashSet<Pair>();
        int temp = new Random().nextInt(100);
        desProp.add(new Pair("temp", temp));
        device.setDesiredProperties(desProp);
        System.out.println("Updating device twin");
        twinClient.updateTwin(device);
        System.out.println("Getting device twin");
        twinClient.getTwin(device);
        System.out.println(device);
    } catch (IotHubException e) {
        System.out.println(e.getMessage());
    }
    System.out.println("Shutting down sample...");
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Random(java.util.Random) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) HashSet(java.util.HashSet) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair)

Example 20 with Pair

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

the class DeviceTwinIT method testAddTagUpdates.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testAddTagUpdates() throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException {
    addMultipleDevices();
    // Update tag for multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        Set<Pair> tags = new HashSet<>();
        tags.add(new Pair(TAG_KEY + i, TAG_VALUE + i));
        devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
        sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
        Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
        devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Read updates on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
        Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
        for (Pair t : devicesUnderTest[i].sCDeviceForTwin.getTags()) {
            assertEquals(t.getKey(), TAG_KEY + i);
            assertEquals(t.getValue(), TAG_VALUE + i);
        }
    }
    removeMultipleDevices();
}
Also used : Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair)

Aggregations

Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)32 Test (org.junit.Test)23 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)20 HashSet (java.util.HashSet)10 HashMap (java.util.HashMap)5 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)3 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)1 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)1 Random (java.util.Random)1 ExecutorService (java.util.concurrent.ExecutorService)1 DeviceConnectionString (tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString)1