Search in sources :

Example 1 with MqttTransport

use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method isEmptyReturnsFalseIfWaitingListIsNotEmpty.

// Tests_SRS_MqttTransport_11_019: [The function shall return true if the waiting list
// and callback list are all empty, and false otherwise.]
@Test
public void isEmptyReturnsFalseIfWaitingListIsNotEmpty(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback) throws IOException {
    final Map<String, Object> context = new HashMap<>();
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    boolean testIsEmpty = transport.isEmpty();
    boolean expectedIsEmpty = false;
    assertThat(testIsEmpty, is(expectedIsEmpty));
}
Also used : HashMap(java.util.HashMap) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Example 2 with MqttTransport

use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method sendMessagesFailsIfTransportClosed.

// Tests_SRS_MQTTTRANSPORT_15_011: [If the MQTT connection is closed,
// the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void sendMessagesFailsIfTransportClosed() throws IOException {
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.close();
    transport.sendMessages();
}
Also used : MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Example 3 with MqttTransport

use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method addMessageWithResponseNotSupportedThrows.

// Tests_SRS_MQTTTRANSPORT_21_022: [The function shall throws `UnsupportedOperationException`.]
@Test(expected = UnsupportedOperationException.class)
public <T extends Queue> void addMessageWithResponseNotSupportedThrows(@Mocked final Message mockMsg, @Mocked final IotHubResponseCallback mockCallback) throws IOException {
    // arrange
    final Queue mockQueue = new MockUp<T>() {
    }.getMockInstance();
    final Map<String, Object> context = new HashMap<>();
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    // act
    transport.addMessage(mockMsg, mockCallback, context);
}
Also used : HashMap(java.util.HashMap) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Queue(java.util.Queue) Test(org.junit.Test)

Example 4 with MqttTransport

use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method sendMessagesAddsToCallbackQueue.

// Tests_SRS_MQTTTRANSPORT_15_010: [For each message being sent, the function shall send the message
// and add the IoT Hub status code along with the callback and context to the callback list.]
@Test
public <T extends Queue> void sendMessagesAddsToCallbackQueue(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket, @Mocked final IotHubCallbackPacket mockCallbackPacket) throws IOException {
    final Queue mockQueue = new MockUp<T>() {
    }.getMockInstance();
    final Map<String, Object> context = new HashMap<>();
    new NonStrictExpectations() {

        {
            new MqttIotHubConnection(mockConfig);
            result = mockConnection;
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            result = mockPacket;
            mockPacket.getCallback();
            result = mockCallback;
            mockPacket.getContext();
            result = context;
            mockConnection.sendEvent((Message) any);
            returns(IotHubStatusCode.OK_EMPTY, IotHubStatusCode.ERROR);
            new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, mockCallback, context);
            result = mockCallbackPacket;
            new IotHubCallbackPacket(IotHubStatusCode.ERROR, mockCallback, context);
            result = mockCallbackPacket;
        }
    };
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    transport.addMessage(mockMsg, mockCallback, context);
    transport.sendMessages();
    new VerificationsInOrder() {

        {
            new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, mockCallback, context);
            mockQueue.add(mockCallbackPacket);
            new IotHubCallbackPacket(IotHubStatusCode.ERROR, mockCallback, context);
            mockQueue.add(mockCallbackPacket);
        }
    };
}
Also used : HashMap(java.util.HashMap) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Queue(java.util.Queue) Test(org.junit.Test)

Example 5 with MqttTransport

use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method handleMessageFailsIfTransportAlreadyClosed.

// Tests_SRS_MQTTTRANSPORT_15_018: [If the MQTT connection is closed,
// the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void handleMessageFailsIfTransportAlreadyClosed() throws IOException {
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.close();
    transport.handleMessage();
}
Also used : MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) Test(org.junit.Test)

Aggregations

MqttTransport (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport)26 Test (org.junit.Test)26 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)12 HashMap (java.util.HashMap)12 IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)4 Queue (java.util.Queue)3 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)1 Field (java.lang.reflect.Field)1 AssertionFailedError (junit.framework.AssertionFailedError)1