use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodMessageTest method setMethodNameThrowsOnNull.
/*
**Tests_SRS_DEVICEMETHODMESSAGE_25_004: [**This method shall throw IllegalArgumentException if the methodName is null.**]**
*/
@Test(expected = IllegalArgumentException.class)
public void setMethodNameThrowsOnNull() {
// arrange
IotHubTransportMessage testDMMessage = new IotHubTransportMessage(new byte[0], MessageType.DEVICE_METHODS);
// act
testDMMessage.setMethodName(null);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodMessageTest method constructorSucceeds.
/*
**Tests_SRS_DEVICEMETHODMESSAGE_25_001: [**The constructor shall save the message body by calling super with the body as parameter.**]**
**Tests_SRS_DEVICEMETHODMESSAGE_25_002: [**If the message body is null, the constructor shall throw an IllegalArgumentException thrown by base constructor.**]**
*/
@Test
public void constructorSucceeds() {
// act
IotHubTransportMessage testDMMessage = new IotHubTransportMessage(new byte[0], MessageType.DEVICE_METHODS);
// assert
assertSame(testDMMessage.getMessageType(), MessageType.DEVICE_METHODS);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method subscribeToDesiredTwinPropertySetsCorrectOperation.
@Test
public void subscribeToDesiredTwinPropertySetsCorrectOperation(@Mocked final IotHubTransportMessage mockedDeviceTwinMessage, @Mocked final TwinPropertyCallBack mockedDesiredCB) {
// arrange
new NonStrictExpectations() {
{
new IotHubTransportMessage(withAny(new byte[0]), MessageType.DEVICE_TWIN);
result = mockedDeviceTwinMessage;
}
};
DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericTwinPropertyCB, null);
Map<Property, Pair<TwinPropertyCallBack, Object>> desiredMap = new HashMap<>();
desiredMap.put(new Property("DesiredProp", "DesiredValue"), new Pair<>(mockedDesiredCB, null));
// act
testTwin.subscribeDesiredPropertiesTwinPropertyNotification(desiredMap);
// assert
final ConcurrentSkipListMap<String, Pair<TwinPropertyCallBack, Object>> actualMap = Deencapsulation.getField(testTwin, "onDesiredTwinPropertyChangeMap");
assertNotNull(actualMap);
assertFalse(actualMap.isEmpty());
assertTrue(actualMap.containsKey("DesiredProp"));
assertEquals(actualMap.get("DesiredProp").getKey(), mockedDesiredCB);
new Verifications() {
{
mockedDeviceTwinMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST);
times = 1;
mockedDeviceIO.sendEventAsync(mockedDeviceTwinMessage, (IotHubEventCallback) any, null, null);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method desiredChangeResponseCallsUserGenericCBWithDesiredChangeIfUnsubscribedYet.
@Test
public void desiredChangeResponseCallsUserGenericCBWithDesiredChangeIfUnsubscribedYet() {
// arrange
final String prop1 = "DesiredProp1";
final String val2 = "DesiredValue2";
final String json = "{\"" + prop1 + "\":\"" + val2 + "\"}";
DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
MessageCallback deviceTwinResponseMessageCallback = Deencapsulation.newInnerInstance("deviceTwinResponseMessageCallback", testTwin);
final IotHubTransportMessage testMessage = new IotHubTransportMessage(json.getBytes(StandardCharsets.UTF_8), MessageType.DEVICE_TWIN);
testMessage.setStatus(String.valueOf(200));
testMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
// act
deviceTwinResponseMessageCallback.execute(testMessage, null);
// assert
new Verifications() {
{
mockedGenericPropertyCB.PropertyCall(prop1, val2, null);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method receiveDoesNotSetVersionOnResTopicIfNotFound.
/*
**Tests_SRS_MQTTDEVICETWIN_25_041: [If the topic is of type response topic then this method shall parse further to look for version which if found is set by calling setVersion]
*/
@Test
public void receiveDoesNotSetVersionOnResTopicIfNotFound() throws TransportException {
final byte[] actualPayload = "GetTwinResponseDataContainingDesiredAndReportedPropertiesDocument".getBytes(StandardCharsets.UTF_8);
final String expectedTopic = "$iothub/twin/res/" + "201" + "/?$rid=" + mockReqId;
IotHubTransportMessage receivedMessage = null;
try {
// arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin("", mockedConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
Queue<Pair<String, byte[]>> testreceivedMessages = new ConcurrentLinkedQueue<>();
testreceivedMessages.add(new MutablePair<>(expectedTopic, actualPayload));
Deencapsulation.setField(testTwin, "receivedMessages", testreceivedMessages);
Map<String, DeviceOperations> requestMap = new HashMap<>();
requestMap.put(mockReqId, DEVICE_OPERATION_TWIN_GET_REQUEST);
Deencapsulation.setField(testTwin, "requestMap", requestMap);
// act
receivedMessage = testTwin.receive();
} finally {
// assert
assertNotNull(receivedMessage);
assertSame(receivedMessage.getMessageType(), MessageType.DEVICE_TWIN);
assertSame(receivedMessage.getDeviceOperationType(), DEVICE_OPERATION_TWIN_GET_RESPONSE);
assertEquals(receivedMessage.getRequestId(), mockReqId);
assertEquals("201", receivedMessage.getStatus());
assertNull(receivedMessage.getVersion());
}
}
Aggregations