use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessagePutsMessageBackIntoQueueIfCannotSendResultBackToServer.
// Tests_SRS_AMQPSTRANSPORT_15_028: [If the result could not be sent to IoTHub, the message shall be put back in the received messages queue to be processed again.]
// Tests_SRS_AMQPSTRANSPORT_15_028: [If the result could not be sent to IoTHub, the message shall be put back in the received messages queue to be processed again.]
@Test
public void handleMessagePutsMessageBackIntoQueueIfCannotSendResultBackToServer() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
mockConfig.getMessageCallback();
result = mockMessageCallback;
mockMessageCallback.execute((Message) any, any);
result = IotHubMessageResult.COMPLETE;
mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
result = false;
}
};
new MockUp<AmqpsTransport>() {
@Mock
Message protonMessageToIoTHubMessage(MessageImpl protonMessage) {
return new Message();
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Queue<AmqpsMessage> receivedMessages = new LinkedBlockingQueue<>();
receivedMessages.add(mockAmqpsMessage);
receivedMessages.add(mockAmqpsMessage);
Deencapsulation.setField(transport, "receivedMessages", receivedMessages);
transport.handleMessage();
Queue<AmqpsMessage> receivedTransportMessages = Deencapsulation.getField(transport, "receivedMessages");
Assert.assertTrue(receivedTransportMessages.size() == 2);
new Verifications() {
{
mockMessageCallback.execute((Message) any, any);
times = 1;
mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
times = 1;
}
};
Assert.assertTrue(receivedTransportMessages.size() == 2);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessageFailsIfTransportNeverOpened.
// Tests_SRS_AMQPSTRANSPORT_15_021: [If the transport is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void handleMessageFailsIfTransportNeverOpened() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.handleMessage();
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessageClearsReceivedMessagesListIfNoCallbackIsDefined.
// Tests_SRS_AMQPSTRANSPORT_15_025: [If no callback is defined, the list of received messages is cleared.]
@Test
public void handleMessageClearsReceivedMessagesListIfNoCallbackIsDefined() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
mockConfig.getMessageCallback();
result = null;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Queue<AmqpsMessage> receivedMessages = new LinkedBlockingQueue<>();
receivedMessages.add(mockAmqpsMessage);
receivedMessages.add(mockAmqpsMessage);
Deencapsulation.setField(transport, "receivedMessages", receivedMessages);
transport.handleMessage();
Queue<AmqpsMessage> receivedTransportMessages = Deencapsulation.getField(transport, "receivedMessages");
Assert.assertTrue(receivedTransportMessages.size() == 0);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageSentReturnsIfThereAreNoMessagesInProgress.
// Tests_SRS_AMQPSTRANSPORT_15_029: [If the hash cannot be found in the list of keys for the messages in progress, the method returns.]
@Test
public void messageSentReturnsIfThereAreNoMessagesInProgress() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
transport.messageSent(1, true);
new Verifications() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method addMessageWithResponseNotSupportedThrows.
// Tests_SRS_AMQPSTRANSPORT_21_040: [The function shall throws `UnsupportedOperationException`.]
@Test(expected = UnsupportedOperationException.class)
public void addMessageWithResponseNotSupportedThrows(@Mocked final Message mockMsg, @Mocked final IotHubResponseCallback mockCallback) throws IOException {
// arrange
final Map<String, Object> context = new HashMap<>();
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
// act
transport.addMessage(mockMsg, mockCallback, context);
}
Aggregations