Search in sources :

Example 11 with Property

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.Property in project azure-iot-sdk-java by Azure.

the class DeviceTest method setReportedPropertyAddsToAlteredReportedProperty.

/*
    **Tests_SRS_DEVICE_25_003: [**If the already existing property is altered and added then the this method shall replace the old one.**]**
     */
@Test
public void setReportedPropertyAddsToAlteredReportedProperty() {
    //arrange
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    Property test = new Property("RepProp1", "RepValue1");
    testDev.setReportedProp(test);
    test.setValue("RepValue2");
    //act
    testDev.setReportedProp(test);
    //assert
    HashSet<Property> testRepProp = testDev.getReportedProp();
    assertTrue(testRepProp.contains(test));
    assertTrue(testRepProp.size() == 1);
}
Also used : Device(com.microsoft.azure.sdk.iot.device.DeviceTwin.Device) Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) Test(org.junit.Test)

Example 12 with Property

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.Property in project azure-iot-sdk-java by Azure.

the class DeviceTest method setDesiredPropertyCallbackCanAddNullPair.

/*
    **Tests_SRS_DEVICE_25_008: [**This method shall add the parameters to the map even if callback and object pair are null**]**
     */
@Test
public void setDesiredPropertyCallbackCanAddNullPair() {
    //arrange
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    Property test = new Property("DesiredProp1", null);
    //act
    testDev.setDesiredPropertyCallback(test, null, null);
    //assert
    HashMap<Property, Pair<PropertyCallBack<String, Object>, Object>> testDesiredMap = testDev.getDesiredProp();
    assertNotNull(testDesiredMap);
    assertEquals(testDesiredMap.get(test).getKey(), null);
}
Also used : Device(com.microsoft.azure.sdk.iot.device.DeviceTwin.Device) Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) Pair(com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair) Test(org.junit.Test)

Example 13 with Property

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.Property 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 14 with Property

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.Property in project azure-iot-sdk-java by Azure.

the class PropertyTest method getValueGets.

/*
    **Tests_SRS_Property_25_004: [**The function shall return the value for this property.**]**
    */
@Test
public void getValueGets() {
    //arrange
    Property testProp = new Property("TestProp", 1);
    //assert
    assertNotNull(testProp);
    assertEquals(testProp.getValue(), 1);
}
Also used : Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) Test(org.junit.Test)

Example 15 with Property

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.Property in project azure-iot-sdk-java by Azure.

the class PropertyTest method setValueSets.

/*
    **Tests_SRS_Property_25_005: [**The function shall overwrite the new value for old and return old value.**]**
     */
@Test
public void setValueSets() {
    //arrange
    Property testProp = new Property("TestProp", 1);
    //act
    testProp.setValue(2);
    //assert
    assertNotNull(testProp);
    assertEquals(testProp.getValue(), 2);
}
Also used : Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) Test(org.junit.Test)

Aggregations

Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)16 Test (org.junit.Test)13 Device (com.microsoft.azure.sdk.iot.device.DeviceTwin.Device)9 Pair (com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair)5 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)3 ExecutorService (java.util.concurrent.ExecutorService)1