use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage 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.AmqpsMessage 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.AmqpsMessage in project azure-iot-sdk-java by Azure.
the class AmqpsMessageTest method acknowledgeSetsReleasedDispositionForAbandon.
// Tests_SRS_AMQPSMESSAGE_14_002: [If the ACK_TYPE is ABANDON, the function shall set a Released disposition on the private Delivery object.]
@Test
public void acknowledgeSetsReleasedDispositionForAbandon() {
AmqpsMessage message = new AmqpsMessage();
message.setDelivery(mockDelivery);
message.acknowledge(AmqpsMessage.ACK_TYPE.ABANDON);
final Delivery expectedDelivery = mockDelivery;
new Verifications() {
{
expectedDelivery.disposition(Released.getInstance());
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage in project azure-iot-sdk-java by Azure.
the class AmqpsMessageTest method acknowledgeSetsAcceptedDispositionForComlete.
// Tests_SRS_AMQPSMESSAGE_14_001: [If the ACK_TYPE is COMPLETE, the function shall set an Accepted disposition on the private Delivery object.]
@Test
public void acknowledgeSetsAcceptedDispositionForComlete() {
AmqpsMessage message = new AmqpsMessage();
message.setDelivery(mockDelivery);
message.acknowledge(AmqpsMessage.ACK_TYPE.COMPLETE);
final Delivery expectedDelivery = mockDelivery;
new Verifications() {
{
expectedDelivery.disposition(Accepted.getInstance());
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageReceivedAddsTheMessageToTheListOfMessagesToBeProcessed.
// Tests_SRS_AMQPSTRANSPORT_15_034: [The message received is added to the list of messages to be processed.]
@Test
public void messageReceivedAddsTheMessageToTheListOfMessagesToBeProcessed() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
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.messageReceived(mockAmqpsMessage);
Assert.assertTrue(receivedMessages.size() == 3);
}
Aggregations