use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method openSetsStateToOpenIfSuccessful.
// Tests_SRS_AMQPSTRANSPORT_15_006: [If the connection was opened successfully, the transport state shall be set to OPEN.]
@Test
public void openSetsStateToOpenIfSuccessful() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
final AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
State state = Deencapsulation.getField(transport, "state");
assertEquals(State.OPEN, state);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method constructorSavesInputParameters.
// Tests_SRS_AMQPSTRANSPORT_15_001: [The constructor shall save the input parameters into instance variables.]
@Test
public void constructorSavesInputParameters() {
DeviceClientConfig expectedClientConfig = mockConfig;
Boolean expectedUseWebSockets = false;
AmqpsTransport transport = new AmqpsTransport(expectedClientConfig, expectedUseWebSockets);
DeviceClientConfig actualClientConfig = Deencapsulation.getField(transport, "config");
Boolean actualUseWebSockets = Deencapsulation.getField(transport, "useWebSockets");
assertEquals(expectedClientConfig, actualClientConfig);
assertEquals(expectedUseWebSockets, actualUseWebSockets);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method closeDoesNothingIfConnectionAlreadyClosed.
// Tests_SRS_AMQPSTRANSPORT_15_007: [If the AMQPS connection is closed, the function shall do nothing.]
@Test
public void closeDoesNothingIfConnectionAlreadyClosed() throws IOException, InterruptedException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.close();
transport.close();
final AmqpsIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.close();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method connectionLostClearsAllInProgressMessagesAndAddsThemToTheWaitingList.
// Tests_SRS_AMQPSTRANSPORT_15_032: [The messages in progress are buffered to be sent again.]
// Tests_SRS_AMQPSTRANSPORT_15_033: [The map of messages in progress is cleared.]
@Test
public void connectionLostClearsAllInProgressMessagesAndAddsThemToTheWaitingList() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
inProgressMessages.put(1, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
inProgressMessages.put(2, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
Queue<IotHubOutboundPacket> waitingMessages = new LinkedBlockingDeque<>();
waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
Deencapsulation.setField(transport, "waitingMessages", waitingMessages);
transport.connectionLost();
Assert.assertTrue(inProgressMessages.size() == 0);
Assert.assertTrue(waitingMessages.size() == 4);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method addMessageFailsIfTransportAlreadyClosed.
// Tests_SRS_AMQPSTRANSPORT_15_010: [If the AMQPS session is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void addMessageFailsIfTransportAlreadyClosed(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback) throws IOException {
final Map<String, Object> context = new HashMap<>();
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.close();
transport.addMessage(mockMsg, mockCallback, context);
}
Aggregations