Search in sources :

Example 31 with Message

use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.

the class MqttTest method receiveReturnsNullMessageWhenParseTopicReturnsNull.

/*
    **Tests_SRS_Mqtt_25_022: [**If the call parseTopic returns null or empty string then this method shall do nothing and return null**]**
     */
@Test
public void receiveReturnsNullMessageWhenParseTopicReturnsNull() throws IOException, MqttException {
    //arrange
    final byte[] payload = { 0x61, 0x62, 0x63 };
    baseConstructorExpectations(true);
    baseConnectExpectation();
    new MockUp<MqttMessaging>() {

        @Mock
        String parseTopic() throws IOException {
            return null;
        }

        @Mock
        byte[] parsePayload(String topic) throws IOException {
            return payload;
        }
    };
    final Mqtt mockMqtt = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
    try {
        new NonStrictExpectations() {

            {
                mockMqttAsyncClient.isConnected();
                result = true;
            }
        };
        Deencapsulation.invoke(mockMqtt, "connect");
        //act
        Message receivedMessage = mockMqtt.receive();
        //assert
        assertNull(receivedMessage);
    } finally {
        testCleanUp(mockMqtt);
    }
}
Also used : Mqtt(com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt) Message(com.microsoft.azure.sdk.iot.device.Message) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Test(org.junit.Test)

Aggregations

Message (com.microsoft.azure.sdk.iot.device.Message)31 Test (org.junit.Test)29 DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)7 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)7 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)6 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)6 NonStrictExpectations (mockit.NonStrictExpectations)6 Mqtt (com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt)4 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)4 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)3 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 DeviceConnectionString (tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString)3 EventCallback (tests.integration.com.microsoft.azure.sdk.iot.device.EventCallback)3 Success (tests.integration.com.microsoft.azure.sdk.iot.device.Success)3 Verifications (mockit.Verifications)2 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)1