Search in sources :

Example 6 with Device

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

the class DeviceTest method setReportedPropertyAddsToReportedProperty.

/*
    **Tests_SRS_DEVICE_25_002: [**The function shall add the new property to the map.**]**
     */
@Test
public void setReportedPropertyAddsToReportedProperty() {
    //arrange
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    Property test = new Property("RepProp1", "RepValue1");
    //act
    testDev.setReportedProp(test);
    //assert
    HashSet<Property> testRepProp = testDev.getReportedProp();
    assertTrue(testRepProp.contains(test));
}
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 7 with Device

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

the class DeviceTest method setDesiredPropertyCallbackAddsToDesiredProperty.

/*
    **Tests_SRS_DEVICE_25_006: [**The function shall add the property and its callback and context pair to the user map of desired properties.**]**
     */
@Test
public void setDesiredPropertyCallbackAddsToDesiredProperty() {
    //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, testDev, null);
    //assert
    HashMap<Property, Pair<PropertyCallBack<String, Object>, Object>> testDesiredMap = testDev.getDesiredProp();
    assertNotNull(testDesiredMap);
    assertEquals(testDesiredMap.get(test).getKey(), testDev);
}
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 8 with Device

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

the class DeviceTest method setReportedPropertyCannotAddNullProperty.

/*
    **Tests_SRS_DEVICE_25_004: [**If the parameter reportedProp is null then this method shall throw IllegalArgumentException**]**
     */
@Test(expected = IllegalArgumentException.class)
public void setReportedPropertyCannotAddNullProperty() {
    //arrange
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    //act
    testDev.setReportedProp(null);
}
Also used : Device(com.microsoft.azure.sdk.iot.device.DeviceTwin.Device) Test(org.junit.Test)

Example 9 with Device

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

the class DeviceTest method setDesiredPropertyCallbackCannotAddNullProperty.

/*
    **Tests_SRS_DEVICE_25_007: [**If the parameter desiredProp is null then this method shall throw IllegalArgumentException**]**
     */
@Test(expected = IllegalArgumentException.class)
public void setDesiredPropertyCallbackCannotAddNullProperty() {
    //arrange
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    Property test = new Property("DesiredProp1", null);
    //act
    testDev.setDesiredPropertyCallback(null, testDev, null);
}
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 10 with Device

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.Device 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)

Aggregations

Device (com.microsoft.azure.sdk.iot.device.DeviceTwin.Device)11 Test (org.junit.Test)11 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)9 Pair (com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair)5 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1