Search in sources :

Example 6 with Pair

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

the class DeviceTwinIT method testUpdateTagUpdates.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testUpdateTagUpdates() throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException {
    addMultipleDevices();
    // Add 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);
        devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Update Tags on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
        Set<Pair> tags = devicesUnderTest[i].sCDeviceForTwin.getTags();
        for (Pair tag : tags) {
            tag.setValue(TAG_VALUE_UPDATE + i);
        }
        devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
        sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
        devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Read updates on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
        for (Pair t : devicesUnderTest[i].sCDeviceForTwin.getTags()) {
            assertEquals(t.getKey(), TAG_KEY + i);
            assertEquals(t.getValue(), TAG_VALUE_UPDATE + i);
        }
    }
    removeMultipleDevices();
}
Also used : Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair)

Example 7 with Pair

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

the class DeviceTwinIT method testSubscribeToDesiredPropertiesSequentially.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testSubscribeToDesiredPropertiesSequentially() throws IOException, InterruptedException, IotHubException {
    // arrange
    for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) {
        PropertyState propertyState = new PropertyState();
        propertyState.callBackTriggered = false;
        propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE);
        deviceUnderTest.dCDeviceForTwin.propertyStateList.add(propertyState);
        deviceUnderTest.dCDeviceForTwin.setDesiredPropertyCallback(propertyState.property, deviceUnderTest.dCDeviceForTwin, propertyState);
    }
    // act
    deviceClient.subscribeToDesiredProperties(deviceUnderTest.dCDeviceForTwin.getDesiredProp());
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) {
        Set<Pair> desiredProperties = new HashSet<>();
        desiredProperties.add(new Pair(PROPERTY_KEY + i, PROPERTY_VALUE_UPDATE + UUID.randomUUID()));
        deviceUnderTest.sCDeviceForTwin.setDesiredProperties(desiredProperties);
        sCDeviceTwin.updateTwin(deviceUnderTest.sCDeviceForTwin);
        Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    }
    // assert
    for (PropertyState propertyState : deviceUnderTest.dCDeviceForTwin.propertyStateList) {
        assertTrue(propertyState.property.toString(), propertyState.callBackTriggered);
        assertTrue(((String) propertyState.propertyNewValue).startsWith(PROPERTY_VALUE_UPDATE));
        assertEquals(deviceUnderTest.deviceTwinStatus, STATUS.SUCCESS);
    }
}
Also used : Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair)

Example 8 with Pair

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

the class DeviceTwinIT method testUpdateDesiredUpdates.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testUpdateDesiredUpdates() throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException {
    addMultipleDevices();
    // Add desired properties for multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        Set<Pair> desiredProperties = new HashSet<>();
        desiredProperties.add(new Pair(PROPERTY_KEY + i, PROPERTY_VALUE + i));
        devicesUnderTest[i].sCDeviceForTwin.setDesiredProperties(desiredProperties);
        sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
        devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Update desired properties on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
        Set<Pair> desiredProperties = devicesUnderTest[i].sCDeviceForTwin.getDesiredProperties();
        for (Pair dp : desiredProperties) {
            dp.setValue(PROPERTY_VALUE_UPDATE + i);
        }
        devicesUnderTest[i].sCDeviceForTwin.setDesiredProperties(desiredProperties);
        sCDeviceTwin.updateTwin(devicesUnderTest[i].sCDeviceForTwin);
        devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Read updates on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        sCDeviceTwin.getTwin(devicesUnderTest[i].sCDeviceForTwin);
        for (Pair dp : devicesUnderTest[i].sCDeviceForTwin.getDesiredProperties()) {
            assertEquals(dp.getKey(), PROPERTY_KEY + i);
            assertEquals(dp.getValue(), PROPERTY_VALUE_UPDATE + i);
        }
    }
    removeMultipleDevices();
}
Also used : Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair)

Example 9 with Pair

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

the class DeviceTwinDeviceTest method setDesiredPropSets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_011: [** This method shall convert the set of pairs of desiredProperties to a map and save it. **]**
     */
@Test
public void setDesiredPropSets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testDesProp = new HashSet<>();
    testDesProp.add(new Pair("testDes", "desObject"));
    //act
    testDevice.setDesiredProperties(testDesProp);
    //assert
    Set<Pair> actualDesProp = testDevice.getDesiredProperties();
    assertEquals(testDesProp.size(), actualDesProp.size());
    for (Pair test : actualDesProp) {
        assertTrue(test.getKey().equals("testDes"));
        assertTrue(test.getValue().equals("desObject"));
    }
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) HashSet(java.util.HashSet) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) Test(org.junit.Test)

Example 10 with Pair

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

the class DeviceTwinDeviceTest method getTagsGetsEmptyIfNotPresent.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_010: [** If the tags map is null then this method shall return empty set of pairs.**]**
     */
@Test
public void getTagsGetsEmptyIfNotPresent() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    //act
    Set<Pair> actualTags = testDevice.getTags();
    //assert
    assertNotNull(actualTags);
    assertTrue(actualTags.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)

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