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;
}
};
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
Aggregations