use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method receiveParsesResponseTopicMandatoryStatusNotFoundException.
/*
**SRS_MQTTDEVICETWIN_25_039: [**If the topic is of type response topic and if status is either a non 3 digit number or not found then receive shall throw IOException **]**
*/
@Test(expected = IOException.class)
public void receiveParsesResponseTopicMandatoryStatusNotFoundException(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] actualPayload = "GetTwinResponseDataContainingDesiredAndReportedPropertiesDocument".getBytes();
final String expectedTopic = "$iothub/twin/res/" + "?$rid=" + mockReqId;
DeviceTwinMessage receivedMessage = null;
try {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
String insertTopic = expectedTopic;
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, actualPayload);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
//act
receivedMessage = (DeviceTwinMessage) testTwin.receive();
} finally {
//assert
assertNull(receivedMessage);
}
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method receiveParsesResponseTopicInvalidStatusThrowsException.
/*
**Tests_SRS_MQTTDEVICETWIN_25_039: [**If the topic is of type response topic and if status is either a non 3 digit number or not found then receive shall throw IOException **]**
*/
@Test(expected = IOException.class)
public void receiveParsesResponseTopicInvalidStatusThrowsException(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] actualPayload = "GetTwinResponseDataContainingDesiredAndReportedPropertiesDocument".getBytes();
final String expectedTopic = "$iothub/twin/res/" + "abc/" + "?$rid=" + mockReqId;
DeviceTwinMessage receivedMessage = null;
try {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
String insertTopic = expectedTopic;
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, actualPayload);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
//act
receivedMessage = (DeviceTwinMessage) testTwin.receive();
} finally {
//assert
assertNull(receivedMessage);
}
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinMessageTest method setTwinOpSets.
/*
**Tests_SRS_DEVICETWINMESSAGE_25_009: [**The function shall save the device twin operation type.**]**
*/
@Test
public void setTwinOpSets() {
//arrange
final byte[] actualData = {};
DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
//act
msg.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
//assert
assertEquals(msg.getDeviceOperationType(), DeviceOperations.DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinMessageTest method constructorSetsRequiredPrivateMembers.
/*
**Tests_SRS_DEVICETWINMESSAGE_25_001: [**The constructor shall save the message body by calling super with the body as parameter.**]**
*/
@Test
public void constructorSetsRequiredPrivateMembers() {
//arrange
final byte[] actualData = {};
//act
DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
//assert
String actualVersion = Deencapsulation.getField(msg, "version");
String actualRequestId = Deencapsulation.getField(msg, "requestId");
String actualStatus = Deencapsulation.getField(msg, "status");
DeviceOperations operationType = Deencapsulation.getField(msg, "operationType");
assertNull(actualVersion);
assertNull(actualRequestId);
assertNull(actualStatus);
assertEquals(operationType, DeviceOperations.DEVICE_OPERATION_UNKNOWN);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage in project azure-iot-sdk-java by Azure.
the class DeviceTwinMessageTest method getTwinOpGets.
/*
**Tests_SRS_DEVICETWINMESSAGE_25_010: [**The function shall return the operation type either set by the setter or the default (DEVICE_OPERATION_UNKNOWN) if unset so far.**]**
*/
@Test
public void getTwinOpGets() {
//arrange
final byte[] actualData = {};
DeviceTwinMessage msg = new DeviceTwinMessage(actualData);
msg.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
//act
DeviceOperations op = msg.getDeviceOperationType();
//assert
assertEquals(op, DeviceOperations.DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
}
Aggregations