use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parsePayloadShallReturnNullIfTopicIsNull.
/*
**Tests_SRS_MqttMessaging_25_011: [**If the topic is null then parsePayload shall stop parsing for payload and return.**]**
*/
@Test
public void parsePayloadShallReturnNullIfTopicIsNull(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
final String insertTopic_messaging = "devices/" + clientId + "/messages/devicebound/abc";
final byte[] insertMessage = { 0x61, 0x62, 0x63 };
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic_messaging, insertMessage);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", String.class);
assertNull(retrieveMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parsePayloadLooksForValueWithGivenKeyTopic.
/*
**Tests_SRS_MqttMessaging_25_010: [**This parsePayload method look for payload for the corresponding topic from the received messagesqueue.**]**
*/
@Test
public void parsePayloadLooksForValueWithGivenKeyTopic(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
final String insertTopic = "devices/" + clientId + "/messages/devicebound/abc";
final byte[] insertMessage = { 0x61, 0x62, 0x63 };
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, insertMessage);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", insertTopic);
assertEquals(insertMessage.length, retrieveMessage.length);
for (int i = 0; i < retrieveMessage.length; i++) {
assertEquals(retrieveMessage[i], insertMessage[i]);
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parseTopicLooksForNextAvailableMessagesForDeviceMessagingTopic.
/*
**Tests_SRS_MqttMessaging_25_005: [**parseTopic shall look for the subscribe topic prefix from received message queue.**]**
*/
@Test
public void parseTopicLooksForNextAvailableMessagesForDeviceMessagingTopic(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
String insertTopic = "devices/" + clientId + "/messages/devicebound/abc";
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, "DataData".getBytes());
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
String retrieveTopic = Deencapsulation.invoke(testMqttMessaging, "parseTopic");
assertEquals(retrieveTopic.length(), insertTopic.length());
for (int i = 0; i < retrieveTopic.length(); i++) {
assertEquals(retrieveTopic.charAt(i), insertTopic.charAt(i));
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parseTopicReturnsNullIfNoMessageMatchingKeyIsFound.
/*
**Tests_SRS_MqttMessaging_25_006: [**If none of the topics from the received queue match the subscribe topic prefix then this method shall return null string .**]**
*/
@Test
public void parseTopicReturnsNullIfNoMessageMatchingKeyIsFound(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
String insertTopic = "devices/" + clientId + "/fakemessages/devicebound/abc";
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, "DataData".getBytes());
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
String retrieveTopic = Deencapsulation.invoke(testMqttMessaging, "parseTopic");
assertNull(retrieveTopic);
}
Aggregations