use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method sendMessageAcknowledgesProperlyBasedOnMessageResult.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_023: [If the message result is COMPLETE, ABANDON, or REJECT,
// the function shall acknowledge the last message with acknowledgement type COMPLETE, ABANDON, or REJECT respectively.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_024: [The function shall return true after the message was acknowledged.]
@Test
public void sendMessageAcknowledgesProperlyBasedOnMessageResult() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
mockAmqpsMessage.acknowledge(AmqpsMessage.ACK_TYPE.COMPLETE);
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
Deencapsulation.setField(connection, "state", State.OPEN);
for (final AmqpsMessage.ACK_TYPE ackType : AmqpsMessage.ACK_TYPE.values()) {
Boolean expectedResult = true;
Boolean actualResult = connection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.valueOf(ackType.toString()));
assertEquals(expectedResult, actualResult);
new Verifications() {
{
mockAmqpsMessage.acknowledge(ackType);
times = 1;
}
};
}
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method onReactorInit.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_033: [The event handler shall set the current handler to handle the connection events.]
@Test
public void onReactorInit() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
mockEvent.getReactor();
result = mockReactor;
mockReactor.connectionToHost(anyString, anyInt, (Handler) any);
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
connection.onReactorInit(mockEvent);
new Verifications() {
{
mockEvent.getReactor();
times = 1;
mockReactor.connectionToHost(anyString, anyInt, (Handler) connection);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method sendMessageDoesNothingIfNotEnoughLinkCredit.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_015: [If the state of the connection is CLOSED or there is not enough
// credit, the function shall return -1.]
@Test
public void sendMessageDoesNothingIfNotEnoughLinkCredit() throws IOException {
baseExpectations();
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
Deencapsulation.setField(connection, "state", State.OPEN);
Deencapsulation.setField(connection, "linkCredit", -1);
Integer expectedDeliveryHash = -1;
Integer actualDeliveryHash = connection.sendMessage(Message.Factory.create());
assertEquals(expectedDeliveryHash, actualDeliveryHash);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method closeClosesAllProtonVariablesAndStopsProtonReactor.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_012: [The function shall set the status of the AMQPS connection to CLOSED.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_013: [The function shall close the AMQPS sender and receiver links,
// the AMQPS session and the AMQPS connection.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_014: [The function shall stop the Proton reactor.]
@Test
public void closeClosesAllProtonVariablesAndStopsProtonReactor() throws IOException, InterruptedException {
baseExpectations();
new NonStrictExpectations() {
{
mockReactorFuture.cancel(true);
mockExecutorService.shutdown();
}
};
new MockUp<AmqpsIotHubConnection>() {
@Mock
void open() {
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
Deencapsulation.setField(connection, "state", State.OPEN);
Deencapsulation.setField(connection, "sender", mockSender);
Deencapsulation.setField(connection, "receiver", mockReceiver);
Deencapsulation.setField(connection, "session", mockSession);
Deencapsulation.setField(connection, "connection", mockConnection);
Deencapsulation.setField(connection, "executorService", mockExecutorService);
connection.close();
State actualState = Deencapsulation.getField(connection, "state");
assertEquals(State.CLOSED, actualState);
new Verifications() {
{
mockSender.close();
times = 1;
mockReceiver.close();
times = 1;
mockSession.close();
times = 1;
mockConnection.close();
times = 1;
mockExecutorService.shutdown();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection 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);
}
Aggregations