use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method isEmptyReturnsFalseIfCallbackListIsNotEmpty.
// 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 isEmptyReturnsFalseIfCallbackListIsNotEmpty(@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);
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
boolean testIsEmpty = transport.isEmpty();
final boolean expectedIsEmpty = false;
assertThat(testIsEmpty, is(expectedIsEmpty));
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method addMessageAddsToTransportQueue.
// Tests_SRS_MQTTTRANSPORT_15_001: [The constructor shall initialize an empty transport queue
// for adding messages to be sent as a batch.]
// Tests_SRS_MQTTTRANSPORT_15_007: [The function shall add a packet containing the message,
// callback, and callback context to the transport queue.]
@Test
public <T extends Queue> void addMessageAddsToTransportQueue(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
final Queue mockQueue = new MockUp<T>() {
}.getMockInstance();
final Map<String, Object> context = new HashMap<>();
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
new VerificationsInOrder() {
{
new IotHubOutboundPacket(mockMsg, mockCallback, context);
mockQueue.add(mockPacket);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method handleMessageInvokesCallbackIfMessageReceived.
// Tests_SRS_MQTTTRANSPORT_15_017: [If a message is found and a message callback is registered,
// the function shall invoke the callback on the message.]
@Test
public void handleMessageInvokesCallbackIfMessageReceived(@Mocked final MessageCallback mockCallback, @Mocked final Message mockMsg) throws IOException {
final Object context = new Object();
new NonStrictExpectations() {
{
mockConfig.getMessageCallback();
result = mockCallback;
mockConfig.getMessageContext();
result = context;
mockConnection.receiveMessage();
result = mockMsg;
}
};
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.handleMessage();
final MessageCallback expectedCallback = mockCallback;
final Message expectedMsg = mockMsg;
final Object expectedContext = context;
new Verifications() {
{
expectedCallback.execute(expectedMsg, expectedContext);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method isEmptyReturnsTrueIfEmpty.
// 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 isEmptyReturnsTrueIfEmpty(@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);
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
transport.invokeCallbacks();
boolean testIsEmpty = transport.isEmpty();
final boolean expectedIsEmpty = true;
assertThat(testIsEmpty, is(expectedIsEmpty));
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport 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;
}
};
}
Aggregations