Search in sources :

Example 11 with TwinParser

use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method getDeviceTwinResponseTriggersStatusCB.

@Test
public void getDeviceTwinResponseTriggersStatusCB(@Mocked final TwinParser mockedTwinParserObj) throws IOException {
    //arrange
    final byte[] body = {};
    DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
    MessageCallback deviceTwinResponseMessageCallback = Deencapsulation.newInnerInstance("deviceTwinResponseMessageCallback", testTwin);
    final DeviceTwinMessage testMessage = new DeviceTwinMessage(body);
    testMessage.setStatus(String.valueOf(200));
    testMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_GET_RESPONSE);
    //act
    deviceTwinResponseMessageCallback.execute(testMessage, null);
    //assert
    final TwinParser actualTwinParserObj = Deencapsulation.getField(testTwin, "twinParser");
    final IotHubEventCallback actualStatusCB = Deencapsulation.getField(testTwin, "deviceTwinStatusCallback");
    new Verifications() {

        {
            actualStatusCB.execute(IotHubStatusCode.OK, withAny(new Object()));
            times = 1;
            actualTwinParserObj.updateTwin(anyString);
            times = 1;
        }
    };
}
Also used : TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) DeviceTwin(com.microsoft.azure.sdk.iot.device.DeviceTwin) Test(org.junit.Test)

Example 12 with TwinParser

use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method getDeviceTwinResponseCallsUpdateTwinIfStatusOk.

/*
    **Tests_SRS_DEVICETWIN_25_030: [**If the message is of type DeviceTwin and DEVICE_OPERATION_TWIN_GET_RESPONSE then the payload is deserialized by calling updateTwin only if the status is ok.**]**
     */
@Test
public void getDeviceTwinResponseCallsUpdateTwinIfStatusOk(@Mocked TwinParser mockedTwinParserObject) throws IOException {
    //arrange
    final byte[] body = {};
    DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
    MessageCallback deviceTwinResponseMessageCallback = Deencapsulation.newInnerInstance("deviceTwinResponseMessageCallback", testTwin);
    final DeviceTwinMessage testMessage = new DeviceTwinMessage(body);
    testMessage.setStatus(String.valueOf(200));
    testMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_GET_RESPONSE);
    //act
    deviceTwinResponseMessageCallback.execute(testMessage, null);
    //assert
    final TwinParser actualTwinParserObj = Deencapsulation.getField(testTwin, "twinParser");
    final IotHubEventCallback actualStatusCB = Deencapsulation.getField(testTwin, "deviceTwinStatusCallback");
    new Verifications() {

        {
            actualStatusCB.execute(IotHubStatusCode.OK, withAny(new Object()));
            times = 1;
            actualTwinParserObj.updateTwin(anyString);
            times = 1;
        }
    };
}
Also used : TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) DeviceTwin(com.microsoft.azure.sdk.iot.device.DeviceTwin) Test(org.junit.Test)

Example 13 with TwinParser

use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method desiredPropResponseDoesNotCallsUserStatusCBOnNotification.

@Test
public void desiredPropResponseDoesNotCallsUserStatusCBOnNotification(@Mocked TwinParser mockedTwinParserObject) throws IOException {
    //arrange
    final byte[] body = {};
    DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
    MessageCallback deviceTwinResponseMessageCallback = Deencapsulation.newInnerInstance("deviceTwinResponseMessageCallback", testTwin);
    final DeviceTwinMessage testMessage = new DeviceTwinMessage(body);
    testMessage.setStatus(String.valueOf(200));
    testMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
    //act
    deviceTwinResponseMessageCallback.execute(testMessage, null);
    //assert
    final TwinParser actualTwinParserObj = Deencapsulation.getField(testTwin, "twinParser");
    final IotHubEventCallback actualStatusCB = Deencapsulation.getField(testTwin, "deviceTwinStatusCallback");
    new Verifications() {

        {
            actualStatusCB.execute(IotHubStatusCode.OK, withAny(new Object()));
            times = 0;
            actualTwinParserObj.updateTwin(anyString);
            times = 0;
            actualTwinParserObj.updateDesiredProperty(anyString);
            times = 1;
        }
    };
}
Also used : TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) DeviceTwin(com.microsoft.azure.sdk.iot.device.DeviceTwin) Test(org.junit.Test)

Example 14 with TwinParser

use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method updateReportedPropCallsTwinAPIForSerialization.

/*
    **Tests_SRS_DEVICETWIN_25_011: [**The method shall send the property set to Twin Serializer for serilization by calling updateReportedProperty.**]**
     */
@Test
public void updateReportedPropCallsTwinAPIForSerialization(@Mocked final TwinParser mockedTwinParserObject, @Mocked final DeviceTwinMessage mockedDeviceTwinMessage) throws IOException {
    final String mockedSerilizedProp = "SerializedReportedProperties";
    new NonStrictExpectations() {

        {
            new TwinParser(withAny(new TwinChangedCallback() {

                @Override
                public void execute(Map<String, Object> map) {
                }
            }), withAny(new TwinChangedCallback() {

                @Override
                public void execute(Map<String, Object> map) {
                }
            }));
            result = mockedTwinParserObject;
            mockedTwinParserObject.updateReportedProperty(withAny(new HashMap<String, Object>()));
            result = mockedSerilizedProp;
            new DeviceTwinMessage(withAny(new byte[0]));
            result = mockedDeviceTwinMessage;
        }
    };
    DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
    HashSet<Property> reportedProp = new HashSet<>();
    testTwin.updateReportedProperties(reportedProp);
    new Verifications() {

        {
            mockedTwinParserObject.updateReportedProperty(withAny(new HashMap<String, Object>()));
            times = 1;
            mockedDeviceTwinMessage.setRequestId(anyString);
            times = 1;
            mockedDeviceTwinMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST);
            times = 1;
            mockedDeviceIO.sendEventAsync(mockedDeviceTwinMessage, (IotHubEventCallback) any, null);
            times = 1;
        }
    };
}
Also used : TwinChangedCallback(com.microsoft.azure.sdk.iot.deps.serializer.TwinChangedCallback) HashMap(java.util.HashMap) TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map) HashMap(java.util.HashMap) DeviceTwin(com.microsoft.azure.sdk.iot.device.DeviceTwin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with TwinParser

use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method desiredPropResponseCallsTwinApiToDeserialize.

/*
    **Tests_SRS_DEVICETWIN_25_026: [**If the message is of type DeviceTwin and DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE then the payload is deserialize by calling updateDesiredProperty.**]**
     */
@Test
public void desiredPropResponseCallsTwinApiToDeserialize(@Mocked TwinParser mockedTwinParserObject) throws IOException {
    //arrange
    final byte[] body = {};
    DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
    MessageCallback deviceTwinResponseMessageCallback = Deencapsulation.newInnerInstance("deviceTwinResponseMessageCallback", testTwin);
    final DeviceTwinMessage testMessage = new DeviceTwinMessage(body);
    testMessage.setStatus(String.valueOf(200));
    testMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
    //act
    deviceTwinResponseMessageCallback.execute(testMessage, null);
    //assert
    final TwinParser actualTwinParserObj = Deencapsulation.getField(testTwin, "twinParser");
    final IotHubEventCallback actualStatusCB = Deencapsulation.getField(testTwin, "deviceTwinStatusCallback");
    new Verifications() {

        {
            actualTwinParserObj.updateTwin(anyString);
            times = 0;
            actualTwinParserObj.updateDesiredProperty(anyString);
            times = 1;
        }
    };
}
Also used : TwinParser(com.microsoft.azure.sdk.iot.deps.serializer.TwinParser) DeviceTwin(com.microsoft.azure.sdk.iot.device.DeviceTwin) Test(org.junit.Test)

Aggregations

TwinParser (com.microsoft.azure.sdk.iot.deps.serializer.TwinParser)16 Test (org.junit.Test)16 DeviceTwin (com.microsoft.azure.sdk.iot.device.DeviceTwin)14 TwinChangedCallback (com.microsoft.azure.sdk.iot.deps.serializer.TwinChangedCallback)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)5 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)2 HashSet (java.util.HashSet)2