use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method closeDoesNothingIfConnectionAlreadyClosed.
// Tests_SRS_MQTTTRANSPORT_15_006: [If the MQTT connection is closed, the function shall do nothing.]
@Test
public void closeDoesNothingIfConnectionAlreadyClosed() throws IOException {
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.close();
transport.close();
final MqttIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.close();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection 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.MqttIotHubConnection 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.MqttIotHubConnection 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();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method openDoesNothingIfAlreadyOpened.
// SRS_MQTTTRANSPORT_15_004: [If the MQTT connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfAlreadyOpened() throws IOException {
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.open();
final MqttIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.open();
times = 1;
}
};
}
Aggregations