use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method invokeCallbacksInvokesAllCallbacks.
// Tests_SRS_MQTTTRANSPORT_15_013: [The function shall invoke all callbacks on the callback queue.]
@Test
public void invokeCallbacksInvokesAllCallbacks(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubCallbackPacket mockCallbackPacket) throws IOException {
final Map<String, Object> context = new HashMap<>();
new NonStrictExpectations() {
{
new MqttIotHubConnection(mockConfig);
result = mockConnection;
mockCallbackPacket.getStatus();
returns(IotHubStatusCode.OK_EMPTY, IotHubStatusCode.ERROR);
mockCallbackPacket.getCallback();
result = mockCallback;
mockCallbackPacket.getContext();
result = context;
}
};
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
transport.invokeCallbacks();
final IotHubEventCallback expectedCallback = mockCallback;
final Map<String, Object> expectedContext = context;
new VerificationsInOrder() {
{
expectedCallback.execute(IotHubStatusCode.OK_EMPTY, expectedContext);
expectedCallback.execute(IotHubStatusCode.ERROR, expectedContext);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method closeClosesMqttsConnectionAndRemovePendingMessages.
// Tests_SRS_MQTTTRANSPORT_15_005: [The function shall close the MQTT connection with the IoT Hub given in the configuration.]
// Tests_SRS_MQTTTRANSPORT_99_020: [The method shall remove all the messages which are in progress or waiting to be sent and add them to the callback list.]
// Tests_SRS_MQTTTRANSPORT_99_021: [The method shall invoke the callback list]
@Test
public void closeClosesMqttsConnectionAndRemovePendingMessages(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockedPacket) throws IOException, InterruptedException {
final MqttTransport transport = new MqttTransport(mockConfig);
final MqttIotHubConnection expectedConnection = mockConnection;
new NonStrictExpectations() {
{
mockedPacket.getMessage();
result = mockMsg;
mockMsg.getBytes();
result = "AnyData".getBytes();
}
};
transport.open();
transport.addMessage(mockMsg, mockCallback, null);
transport.close();
Queue<IotHubOutboundPacket> actualWaitingMessages = Deencapsulation.getField(transport, "waitingList");
assertEquals(actualWaitingMessages.size(), 0);
new Verifications() {
{
mockCallback.execute((IotHubStatusCode) any, any);
times = 1;
expectedConnection.close();
minTimes = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method addMessageFailsIfTransportAlreadyClosed.
// Tests_SRS_MQTTTRANSPORT_15_008: [If the transport is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void addMessageFailsIfTransportAlreadyClosed(@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.close();
transport.addMessage(mockMsg, mockCallback, context);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method invokeCallbacksFailsIfTransportAlreadyClosed.
// Tests_SRS_MQTTTRANSPORT_15_014: [If the transport is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void invokeCallbacksFailsIfTransportAlreadyClosed() throws IOException {
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.close();
transport.invokeCallbacks();
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method handleMessageAttemptsToReceiveMessage.
// Tests_SRS_MQTTTRANSPORT_15_016: [The function shall attempt to consume a message from the IoT Hub.]
@Test
public void handleMessageAttemptsToReceiveMessage(@Mocked final MessageCallback mockCallback) throws IOException {
final Object context = new Object();
new NonStrictExpectations() {
{
mockConfig.getMessageCallback();
result = mockCallback;
mockConfig.getMessageContext();
result = context;
}
};
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.handleMessage();
final MqttIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.receiveMessage();
}
};
}
Aggregations