use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method receiveThrowsUnsupportedExceptionOnAnythingOtherThenPatchOrResTopic.
/*
**Tests_SRS_MQTTDEVICETWIN_25_037: [**This method shall parse topic to look for only either twin response topic or twin patch topic and thorw unsupportedoperation exception other wise.**]**
*/
@Test(expected = UnsupportedOperationException.class)
public void receiveThrowsUnsupportedExceptionOnAnythingOtherThenPatchOrResTopic(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] actualPayload = "NotificationResponseDataContainingDesiredPropertiesDocument".getBytes();
final String expectedTopic = "$iothub/twin/NOTPATCH_NOTRES/properties/" + "?$version=" + mockVersion;
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.transport.mqtt.MqttDeviceTwin in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method parseTopicThrowsExceptionIfQueueIsNull.
/*
**Tests_SRS_MQTTDEVICETWIN_25_007: [**If receiveMessage queue is null then parseTopic shall throw IOException.**]**
*/
@Test(expected = IOException.class)
public void parseTopicThrowsExceptionIfQueueIsNull(@Mocked final Mqtt mockMqtt) throws IOException {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
ConcurrentSkipListMap<String, byte[]> testMap = null;
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
//act
String parsedTopic = Deencapsulation.invoke(testTwin, "parseTopic");
//assert
assertNull(parsedTopic);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method sendThrowsExceptionForUpdateReportedPropertiesOnCorrectTopicIfReqIdIsNullOrEmpty.
/*
**Tests_SRS_MQTTDEVICETWIN_25_027: [**send method shall throw an exception if message contains a null or empty request id if the operation is of type DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST.**]**
*/
@Test(expected = IOException.class)
public void sendThrowsExceptionForUpdateReportedPropertiesOnCorrectTopicIfReqIdIsNullOrEmpty(@Mocked final Mqtt mockMqtt, @Mocked final DeviceTwinMessage mockMessage) throws IOException {
final byte[] actualPayload = { 0x61, 0x62, 0x63 };
final String expectedTopic = "$iothub/twin/PATCH/properties/reported/?$rid=" + mockReqId + "&$version=" + mockVersion;
try {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
new NonStrictExpectations() {
{
mockMessage.getBytes();
result = actualPayload;
mockMessage.getMessageType();
result = MessageType.DeviceTwin;
mockMessage.getDeviceOperationType();
result = DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST;
mockMessage.getRequestId();
result = null;
}
};
//act
testTwin.send(mockMessage);
} finally {
//assert
new Verifications() {
{
mockMessage.getBytes();
times = 1;
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 0;
}
};
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method stopUnsubscribesFromDeviceTwinResponse.
/*
**Tests_SRS_MQTTDEVICETWIN_25_020: [**stop method shall unsubscribe from twin response topic ($iothub/twin/res/#).**]**
*/
@Test
public void stopUnsubscribesFromDeviceTwinResponse(@Mocked final Mqtt mockMqtt) throws IOException {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
Deencapsulation.setField(testTwin, "isStarted", true);
//act
testTwin.stop();
//assert
new Verifications() {
{
Deencapsulation.invoke(mockMqtt, "unsubscribe", resTopic);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method constructorConstructsSubscribeTopicForTwin.
/*
**Tests_SRS_MQTTDEVICETWIN_25_001: [**The constructor shall instantiate super class without any parameters.**]**
**Tests_SRS_MQTTDEVICETWIN_25_002: [**The constructor shall construct device twin response subscribeTopic.**]**
*/
@Test
public void constructorConstructsSubscribeTopicForTwin(@Mocked final Mqtt mockMqtt) throws IOException {
//arrange
//act
MqttDeviceTwin testTwin = new MqttDeviceTwin();
//assert
String actualSubscribeTopic = Deencapsulation.getField(testTwin, "subscribeTopic");
assertNotNull(actualSubscribeTopic);
assertEquals(actualSubscribeTopic, resTopic);
}
Aggregations