use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.
the class DeviceTwinDeviceTest method getTwinObjectGets.
/*
Tests_SRS_DEVICETWINDEVICE_25_028: [ This method shall return the twinObject for this device]
*/
@Test
public void getTwinObjectGets() {
//arrange
DeviceTwinDevice testDevice = new DeviceTwinDevice("testDevice");
//act
TwinParser testDeviceTwinParserObject = Deencapsulation.invoke(testDevice, "getTwinParser");
//assert
assertNotNull(testDeviceTwinParserObject);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.
the class DeviceTwinDeviceTest method getTwinObjectUniquePerDevice.
@Test
public void getTwinObjectUniquePerDevice() {
//arrange
DeviceTwinDevice testDevice1 = new DeviceTwinDevice("testDevice1");
DeviceTwinDevice testDevice2 = new DeviceTwinDevice("testDevice2");
//act
TwinParser testDeviceTwinParserObject1 = Deencapsulation.invoke(testDevice1, "getTwinParser");
TwinParser testDeviceTwinParserObject2 = Deencapsulation.invoke(testDevice2, "getTwinParser");
//assert
assertNotEquals(testDeviceTwinParserObject1, testDeviceTwinParserObject2);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method contructorSetAllPrivateMembersCorrectly.
/*
**Tests_SRS_DEVICETWIN_25_003: [**The constructor shall save all the parameters specified i.e client, config, deviceTwinCallback, genericPropertyCallback.**]**
*/
@Test
public void contructorSetAllPrivateMembersCorrectly() throws IOException {
//Arrange
//Act
DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
//Assert
TwinParser actualTwinParserObj = Deencapsulation.getField(testTwin, "twinParser");
DeviceIO actualClient = Deencapsulation.getField(testTwin, "deviceIO");
DeviceClientConfig actualConfig = Deencapsulation.getField(testTwin, "config");
IotHubEventCallback actualStatucCB = Deencapsulation.getField(testTwin, "deviceTwinStatusCallback");
PropertyCallBack actualPropCB = Deencapsulation.getField(testTwin, "deviceTwinGenericPropertyChangeCallback");
assertEquals(actualPropCB, mockedGenericPropertyCB);
assertEquals(actualStatucCB, mockedStatusCB);
assertEquals(actualClient, mockedDeviceIO);
assertEquals(actualConfig, mockedConfig);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method updateReportedPropSetsCorrectTwinOperation.
/*
**Tests_SRS_DEVICETWIN_25_012: [**The method shall create a device twin message with the serialized payload if not null to be sent IotHub.**]**
**Tests_SRS_DEVICETWIN_25_013: [**This method shall set the message type as DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST by calling setDeviceOperationType.**]**
**Tests_SRS_DEVICETWIN_25_014: [**This method shall set the request id for the message by calling setRequestId .**]**
**Tests_SRS_DEVICETWIN_25_015: [**This method shall send the message to the lower transport layers by calling sendEventAsync.**]**
*/
@Test
public void updateReportedPropSetsCorrectTwinOperation(@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 getDeviceTwinResponseCallStusCBWithERRORIfStatusNull.
/*
**Tests_SRS_DEVICETWIN_25_031: [**If the message is of type DeviceTwin and DEVICE_OPERATION_TWIN_GET_RESPONSE and if the status is null then the user is notified on the status callback registered by the user as ERROR.**]**
*/
@Test
public void getDeviceTwinResponseCallStusCBWithERRORIfStatusNull(@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(null);
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.ERROR, withAny(new Object()));
times = 1;
actualTwinParserObj.updateTwin(anyString);
times = 0;
}
};
}
Aggregations