use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket 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.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class HttpsTransportTest method addMessageAddsToTransportQueue.
// Tests_SRS_HTTPSTRANSPORT_11_003: [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<>();
HttpsTransport transport = new HttpsTransport(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.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class HttpsTransportTest method addMessageWithResponseAddsToTransportQueue.
// Tests_SRS_HTTPSTRANSPORT_21_017: [The function shall add a packet containing the message, callback, and callback context to the transport queue.]
@Test
public <T extends Queue> void addMessageWithResponseAddsToTransportQueue(@Mocked final Message mockMsg, @Mocked final IotHubResponseCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
final Queue mockQueue = new MockUp<T>() {
}.getMockInstance();
final Map<String, Object> context = new HashMap<>();
HttpsTransport transport = new HttpsTransport(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.IotHubOutboundPacket 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.IotHubOutboundPacket 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;
}
};
}
Aggregations