Search in sources :

Example 21 with Pair

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

the class DeviceTwinIT method testSubscribeToDesiredProperties.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testSubscribeToDesiredProperties() 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);
    Set<Pair> desiredProperties = new HashSet<>();
    for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) {
        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
    assertEquals(deviceUnderTest.deviceTwinStatus, STATUS.SUCCESS);
    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 22 with Pair

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

the class DeviceTwinIT method readReportedProperties.

private int readReportedProperties(DeviceState deviceState, String startsWithKey, String startsWithValue) throws IOException, IotHubException, InterruptedException {
    int totalCount = 0;
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    sCDeviceTwin.getTwin(deviceState.sCDeviceForTwin);
    Set<Pair> repProperties = deviceState.sCDeviceForTwin.getReportedProperties();
    for (Pair p : repProperties) {
        String val = (String) p.getValue();
        if (p.getKey().startsWith(startsWithKey) && val.startsWith(startsWithValue)) {
            totalCount++;
        }
    }
    return totalCount;
}
Also used : DeviceConnectionString(tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair)

Example 23 with Pair

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

the class DeviceTwinIT method testGetTwinUpdates.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
public void testGetTwinUpdates() throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException {
    addMultipleDevices();
    // Add tag and desired 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);
        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 Tags and desired properties 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);
        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 t : devicesUnderTest[i].sCDeviceForTwin.getTags()) {
            assertEquals(t.getKey(), TAG_KEY + i);
            assertEquals(t.getValue(), TAG_VALUE_UPDATE + i);
        }
        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 24 with Pair

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

the class DeviceTwinDeviceTest method getTagsGets.

/*
    **Tests_SRS_DEVICETWINDEVICE_25_009: [** This method shall convert the tags map to a set of pairs and return with it. **]**
     */
@Test
public void getTagsGets() {
    //arrange
    DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
    Set<Pair> testTags = new HashSet<>();
    testTags.add(new Pair("testTag", "tagObject"));
    testDevice.setTags(testTags);
    //act
    Set<Pair> actualTags = testDevice.getTags();
    //assert
    assertEquals(testTags.size(), actualTags.size());
    for (Pair test : actualTags) {
        assertTrue(test.getKey().equals("testTag"));
        assertTrue(test.getValue().equals("tagObject"));
    }
}
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 25 with Pair

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

the class DeviceTwinDeviceTest method getReportedPropGetsEmptyIfNotPresent.

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