Search in sources :

Example 1 with Device

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

the class DeviceTest method getReportedPropertiesReturnsMapsOfProperties.

/*
    **Tests_SRS_DEVICE_25_001: [**This method shall return a HashSet of properties that user has set by calling setReportedProp.**]**
     */
@Test
public void getReportedPropertiesReturnsMapsOfProperties() {
    //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);
    HashSet<Property> testRepProp = testDev.getReportedProp();
    //assert
    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 2 with Device

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

the class DeviceTest method freeEmptiesAllProperties.

/*
    **Tests_SRS_DEVICE_25_009: [**The method shall remove all the reported and desired properties set by the user so far and mark existing collections as null to be garbage collected.**]**
     */
@Test
public void freeEmptiesAllProperties() {
    //arrange
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    Property testDes = new Property("DesiredProp1", null);
    Property testRep = new Property("DesiredProp1", null);
    testDev.setDesiredPropertyCallback(testDes, testDev, null);
    testDev.setReportedProp(testRep);
    //act
    testDev.clean();
    //assert
    HashMap<Property, Pair<PropertyCallBack<String, Object>, Object>> testDesiredMap = testDev.getDesiredProp();
    HashSet<Property> testRepMap = testDev.getReportedProp();
    assertNull(testDesiredMap);
    assertNull(testRepMap);
}
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 3 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 4 with Device

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

the class DeviceTest method getDesiredPropertiesReturnsMapsOfProperties.

/*
    **Tests_SRS_DEVICE_25_005: [**The function shall return the HashMap containing the property and its callback and context pair set by the user so far.**]**
     */
@Test
public void getDesiredPropertiesReturnsMapsOfProperties() {
    //arrange
    Device testDev = new Device() {

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

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

the class DeviceTest method constructorCreatesNewMapsForProperties.

@Test
public void constructorCreatesNewMapsForProperties() {
    //act
    Device testDev = new Device() {

        @Override
        public void PropertyCall(String propertyKey, Object propertyValue, Object context) {
        }
    };
    //assert
    HashSet reported = Deencapsulation.getField(testDev, "reportedProp");
    HashMap desired = Deencapsulation.getField(testDev, "desiredProp");
    assertNotNull(reported);
    assertNotNull(desired);
}
Also used : HashMap(java.util.HashMap) Device(com.microsoft.azure.sdk.iot.device.DeviceTwin.Device) HashSet(java.util.HashSet) 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