Search in sources :

Example 26 with MqttMessaging

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);
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Test(org.junit.Test)

Example 27 with MqttMessaging

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]);
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Test(org.junit.Test)

Example 28 with MqttMessaging

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));
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Test(org.junit.Test)

Example 29 with MqttMessaging

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);
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Test(org.junit.Test)

Aggregations

MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)29 Test (org.junit.Test)29 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)8 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)5 Verifications (mockit.Verifications)5 Message (com.microsoft.azure.sdk.iot.device.Message)4 Mqtt (com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt)4 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)3 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)3 IOException (java.io.IOException)3 NonStrictExpectations (mockit.NonStrictExpectations)3 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)2 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)2 State (com.microsoft.azure.sdk.iot.device.transport.State)1