use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method desiredPropResponseDoesNotCallsUserStatusCBOnNotification.
/*
**Tests_SRS_DEVICETWIN_25_025: [**On receiving a message from IOTHub with desired property changes, the callback deviceTwinResponseMessageCallback is triggered.**]**
**Tests_SRS_DEVICETWIN_25_026: [**If the message is of type DEVICE_TWIN and DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE then the payload is deserialize by calling updateDesiredProperty.**]**
*/
@Test
public void desiredPropResponseDoesNotCallsUserStatusCBOnNotification(@Mocked final TwinState mockedTwinState, @Mocked final TwinCollection mockedTwinCollection) {
// arrange
final byte[] body = {};
DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
MessageCallback deviceTwinResponseMessageCallback = Deencapsulation.newInnerInstance("deviceTwinResponseMessageCallback", testTwin);
final IotHubTransportMessage testMessage = new IotHubTransportMessage(body, MessageType.DEVICE_TWIN);
testMessage.setStatus(String.valueOf(200));
testMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
new NonStrictExpectations() {
{
TwinState.createFromDesiredPropertyJson((String) any);
result = mockedTwinState;
times = 1;
mockedTwinState.getDesiredProperty();
result = mockedTwinCollection;
times = 2;
}
};
// act
deviceTwinResponseMessageCallback.execute(testMessage, null);
// assert
final IotHubEventCallback actualStatusCB = Deencapsulation.getField(testTwin, "deviceTwinStatusCallback");
new Verifications() {
{
actualStatusCB.execute(IotHubStatusCode.OK, withAny(new Object()));
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method deviceMethodResponseCallbackSendsResponseOnlyIfNonNull.
/*
**Tests_SRS_DEVICEMETHOD_25_014: [**If the user invoked callback failed for any reason then the user shall be notified on the status callback registered by the user as ERROR before marking the status of the sent message as Rejected.**]**
*/
@Test
public void deviceMethodResponseCallbackSendsResponseOnlyIfNonNull() throws IllegalArgumentException {
// arrange
DeviceMethod testMethod = new DeviceMethod(mockedDeviceIO, mockedConfig, mockedStatusCB, null);
testMethod.subscribeToDeviceMethod(mockedDeviceMethodCB, null);
byte[] testPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
IotHubTransportMessage testMessage = new IotHubTransportMessage(testPayload, DEVICE_METHODS);
testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
final DeviceMethodData testUserData = null;
MessageCallback testDeviceMethodResponseMessageCallback = Deencapsulation.newInnerInstance("deviceMethodResponseCallback", testMethod);
new NonStrictExpectations() {
{
mockedDeviceMethodCB.call(anyString, any, any);
result = testUserData;
}
};
// act
IotHubMessageResult result = testDeviceMethodResponseMessageCallback.execute(testMessage, null);
// assert
assertNotSame(result, IotHubMessageResult.COMPLETE);
new Verifications() {
{
mockedStatusCB.execute(IotHubStatusCode.ERROR, any);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method deviceMethodResponseCallbackDoesNotHangOnUserCallBackHang.
@Test
public void deviceMethodResponseCallbackDoesNotHangOnUserCallBackHang() throws IllegalArgumentException {
// arrange
DeviceMethod testMethod = new DeviceMethod(mockedDeviceIO, mockedConfig, mockedStatusCB, null);
testMethod.subscribeToDeviceMethod(mockedDeviceMethodCB, null);
byte[] testPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
IotHubTransportMessage testMessage = new IotHubTransportMessage(testPayload, DEVICE_METHODS);
testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
MessageCallback testDeviceMethodResponseMessageCallback = Deencapsulation.newInnerInstance("deviceMethodResponseCallback", testMethod);
new NonStrictExpectations() {
{
mockedDeviceMethodCB.call(anyString, any, any);
result = new Exception("Test Exception");
}
};
// act
IotHubMessageResult result = testDeviceMethodResponseMessageCallback.execute(testMessage, null);
// assert
assertNotSame(result, IotHubMessageResult.COMPLETE);
new Verifications() {
{
mockedStatusCB.execute(IotHubStatusCode.ERROR, any);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method deviceMethodResponseCallbackAbandonsOnIncorrectMessage.
/*
**Tests_SRS_DEVICEMETHOD_25_009: [**If the received message is not of type DeviceMethod and DEVICE_OPERATION_METHOD_RECEIVE_REQUEST then user shall be notified on the status callback registered by the user as ERROR before marking the status of the sent message as Abandon **]**
*/
@Test
public void deviceMethodResponseCallbackAbandonsOnIncorrectMessage() throws IllegalArgumentException {
// arrange
DeviceMethod testMethod = new DeviceMethod(mockedDeviceIO, mockedConfig, mockedStatusCB, null);
testMethod.subscribeToDeviceMethod(mockedDeviceMethodCB, null);
byte[] testPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
IotHubTransportMessage testMessage = new IotHubTransportMessage(testPayload, MessageType.DEVICE_TWIN);
testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
final DeviceMethodData testUserData = new DeviceMethodData(100, "Some test message");
MessageCallback testDeviceMethodResponseMessageCallback = Deencapsulation.newInnerInstance("deviceMethodResponseCallback", testMethod);
new NonStrictExpectations() {
{
mockedDeviceMethodCB.call(anyString, any, any);
result = testUserData;
}
};
// act
IotHubMessageResult result = testDeviceMethodResponseMessageCallback.execute(testMessage, null);
// assert
assertNotSame(result, IotHubMessageResult.COMPLETE);
new Verifications() {
{
mockedStatusCB.execute(IotHubStatusCode.ERROR, any);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinMessageTest method getStatusGets.
/*
**Tests_SRS_DEVICETWINMESSAGE_25_008: [**The function shall return the value of the status either set by the setter or the default (null) if unset so far.**]**
*/
@Test
public void getStatusGets() {
// arrange
final byte[] actualData = {};
IotHubTransportMessage msg = new IotHubTransportMessage(actualData, MessageType.DEVICE_TWIN);
msg.setStatus("12");
// act
String status = msg.getStatus();
// assert
assertEquals(status, "12");
}
Aggregations