use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method sendComplete_throws_exception_if_found.
//Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_031: [** The event handler shall get the exception from the response and throw is it is not null **]**
@Test(expected = IotHubException.class)
public void sendComplete_throws_exception_if_found(@Mocked final AmqpResponseVerification mockedVerification, @Mocked final IotHubException mockedIotHubException) throws IotHubException, IOException {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
Queue<AmqpResponseVerification> testsendStatusQueue = new LinkedBlockingQueue<>();
testsendStatusQueue.add(mockedVerification);
Deencapsulation.setField(amqpSendHandler, "sendStatusQueue", testsendStatusQueue);
// Assert
new Expectations() {
{
mockedVerification.getException();
result = mockedIotHubException;
}
};
// Act
amqpSendHandler.sendComplete();
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method constructor_checks_if_hostName_empty.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_001: [The constructor shall throw IllegalArgumentException if any of the input parameter is null or empty]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_checks_if_hostName_empty() {
// Arrange
String hostName = "";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Act
AmqpSendHandler amqpSend = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onDelivery_flow_ok.
/*
Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_023: [** The event handler shall get the Delivery from the event only if the event type is DELIVERY **]**
Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_024: [** The event handler shall get the Delivery remote state from the delivery **]**
Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_025: [** The event handler shall verify the Amqp response and add the response to a queue. **]**
Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_026: [** The event handler shall settle the delivery. **]**
Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_027: [** The event handler shall get the Sender (Proton) object from the event **]**
Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_028: [** The event handler shall close the Sender, Session and Connection **]**
*/
@Test
public void onDelivery_flow_ok(@Mocked final Event mockedEvent, @Mocked final DeliveryState mockedDeliveryState, @Mocked final Delivery mockedDelivery) throws UnsupportedEncodingException {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
mockedEvent.getType();
result = Event.Type.DELIVERY;
mockedEvent.getDelivery();
result = mockedDelivery;
mockedDelivery.getRemoteState();
result = mockedDeliveryState;
sender.close();
session = sender.getSession();
connection = session.getConnection();
connection.close();
}
};
// Act
amqpSendHandler.onDelivery(mockedEvent);
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method constructor_copies_params_to_members.
// Test_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_001: [The constructor shall copy all input parameters to private member variables for event processing]
// Test_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_002: [The constructor shall concatenate the host name with the port]
// Test_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_003: [The constructor shall initialize a new Handshaker (Proton) object to handle communication handshake]
@Test
public void constructor_copies_params_to_members() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
new Expectations() {
{
handshaker = new Handshaker();
}
};
// Act
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
String _hostName = Deencapsulation.getField(amqpSendHandler, "hostName");
String _userName = Deencapsulation.getField(amqpSendHandler, "userName");
String _sasToken = Deencapsulation.getField(amqpSendHandler, "sasToken");
IotHubServiceClientProtocol _ioIotHubServiceClientProtocol = Deencapsulation.getField(amqpSendHandler, "iotHubServiceClientProtocol");
// Assert
assertEquals(hostName + ":5671", _hostName);
assertEquals(userName, _userName);
assertEquals(sasToken, _sasToken);
assertEquals(iotHubServiceClientProtocol, _ioIotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onConnectionInit_creates_Session_and_open_Connection.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_011: [The event handler shall set the host name on the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_012: [The event handler shall create a Session (Proton) object from the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_013: [The event handler shall create a Sender (Proton) object and set the protocol tag on it to a predefined constant]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_014: [The event handler shall open the Connection, the Session and the Sender object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_15_023: [The Sender object shall have the properties set to service client version identifier.]
@Test
public void onConnectionInit_creates_Session_and_open_Connection() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String hostAddr = hostName + ":5671";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
connection = event.getConnection();
connection.setHostname(hostAddr);
session = connection.session();
sender = session.sender(anyString);
connection.open();
session.open();
sender.open();
sender.setProperties((Map<Symbol, Object>) any);
}
};
// Act
amqpSendHandler.onConnectionInit(event);
}
Aggregations