use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method isEmptyReturnsFalseIfWaitingListIsNotEmpty.
// Tests_SRS_AMQPSTRANSPORT_15_035: [The function shall return true if the waiting list,
// in progress list and callback list are all empty, and false otherwise.]
@Test
public void isEmptyReturnsFalseIfWaitingListIsNotEmpty() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
Queue<IotHubOutboundPacket> waitingMessages = new LinkedBlockingDeque<>();
waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
Deencapsulation.setField(transport, "waitingMessages", waitingMessages);
Boolean isEmpty = transport.isEmpty();
Assert.assertFalse(isEmpty);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method openOpensAmqpsConnection.
// Tests_SRS_AMQPSTRANSPORT_15_004: [The function shall open an AMQPS connection with the IoT Hub given in the configuration.]
@Test
public void openOpensAmqpsConnection() throws IOException, InterruptedException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
final AmqpsIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.open();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessageConsumesAMessage.
// Tests_SRS_AMQPSTRANSPORT_15_023: [The function shall attempt to consume a message from the IoT Hub.]
// Tests_SRS_AMQPSTRANSPORT_15_026: [The function shall invoke the callback on the message.]
// Tests_SRS_AMQPSTRANSPORT_15_027: [The function shall return the message result (one of COMPLETE, ABANDON, or REJECT) to the IoT Hub.]
@Test
public void handleMessageConsumesAMessage() 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 = true;
}
};
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");
new Verifications() {
{
mockMessageCallback.execute((Message) any, any);
times = 1;
mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
times = 1;
}
};
Assert.assertTrue(receivedTransportMessages.size() == 1);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method closeClosesAmqpsConnectionAndRemovePendingMessages.
// Tests_SRS_AMQPSTRANSPORT_15_008: [The function shall close an AMQPS connection with the IoT Hub given in the configuration.]
// Tests_SRS_AMQPSTRANSPORT_99_036: [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_AMQPSTRANSPORT_99_037: [The method shall invoke all the callbacks.]
@Test
public void closeClosesAmqpsConnectionAndRemovePendingMessages(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockedPacket) throws IOException, InterruptedException {
final AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
final AmqpsIotHubConnection 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, "waitingMessages");
Map<Integer, IotHubOutboundPacket> actualInProgressMessages = Deencapsulation.getField(transport, "inProgressMessages");
assertEquals(actualWaitingMessages.size(), 0);
assertEquals(actualInProgressMessages.size(), 0);
new Verifications() {
{
mockCallback.execute((IotHubStatusCode) any, any);
times = 1;
expectedConnection.close();
minTimes = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesFailsIfTransportAlreadyClosed.
// Tests_SRS_AMQPSTRANSPORT_15_012: [If the AMQPS session is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void sendMessagesFailsIfTransportAlreadyClosed() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.close();
transport.sendMessages();
}
Aggregations