use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method amqpReceiveHandlerCallFlowAndInitOk.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_001: [The constructor shall copy all input parameters to private member variables for event processing]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_002: [The constructor shall initialize a new Handshaker (Proton) object to handle communication handshake]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_003: [The constructor shall initialize a new FlowController (Proton) object to handle communication handshake]
@Test
public void amqpReceiveHandlerCallFlowAndInitOk() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Assert
new Expectations() {
{
handshaker = new Handshaker();
flowcontroller = new FlowController();
}
};
// Act
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
final String _hostName = Deencapsulation.getField(amqpReceiveHandler, "hostName");
final String _userName = Deencapsulation.getField(amqpReceiveHandler, "userName");
final String _sasToken = Deencapsulation.getField(amqpReceiveHandler, "sasToken");
AmqpFeedbackReceivedEvent _amqpFeedbackReceivedEvent = Deencapsulation.getField(amqpReceiveHandler, "amqpFeedbackReceivedEvent");
// Assert
assertEquals(hostName + ":5671", _hostName);
assertEquals(userName, _userName);
assertEquals(sasToken, _sasToken);
assertEquals(amqpFeedbackReceivedEvent, _amqpFeedbackReceivedEvent);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method onConnectionBoundCallFlowAndInitOkAmqp.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_017: [The event handler shall not initialize WebSocket if the protocol is AMQP]
@Test
public void onConnectionBoundCallFlowAndInitOkAmqp() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
// Assert
new Expectations() {
{
connection = event.getConnection();
transport = connection.getTransport();
sasl.plain(anyString, anyString);
sslDomain = Proton.sslDomain();
sslDomain.init(SslDomain.Mode.CLIENT);
sslDomain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
transport.ssl(sslDomain);
}
};
// Act
Deencapsulation.invoke(amqpReceiveHandler, "onConnectionBound", event);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpReceiveHandlerTest method onConnectionInit_call_flow_and_init_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_011: [The event handler shall set the host name on the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_012: [The event handler shall create a Session (Proton) object from the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_013: [The event handler shall create a Receiver (Proton) object and set the protocol tag on it to a predefined constant]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_014: [The event handler shall open the Connection, the Session and the Receiver object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_15_017: [The Receiver object shall have the properties set to service client version identifier.]
@Test
public void onConnectionInit_call_flow_and_init_ok() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
final String hostAddr = hostName + ":5671";
final String receiver_tag = "receiver";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
// Assert
new Expectations() {
{
connection = event.getConnection();
connection.setHostname(hostAddr);
session = connection.session();
receiver = session.receiver(receiver_tag);
connection.open();
session.open();
receiver.open();
receiver.setProperties((Map<Symbol, Object>) any);
}
};
// Act
amqpReceiveHandler.onConnectionInit(event);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpReceiveHandlerTest method amqpReceiveHandler_call_flow_and_init_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_001: [The constructor shall copy all input parameters to private member variables for event processing]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_002: [The constructor shall initialize a new Handshaker (Proton) object to handle communication handshake]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_003: [The constructor shall initialize a new FlowController (Proton) object to handle communication handshake]
@Test
public void amqpReceiveHandler_call_flow_and_init_ok() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Assert
new Expectations() {
{
handshaker = new Handshaker();
flowcontroller = new FlowController();
}
};
// Act
AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
final String _hostName = Deencapsulation.getField(amqpReceiveHandler, "hostName");
final String _userName = Deencapsulation.getField(amqpReceiveHandler, "userName");
final String _sasToken = Deencapsulation.getField(amqpReceiveHandler, "sasToken");
AmqpFeedbackReceivedEvent _amqpFeedbackReceivedEvent = Deencapsulation.getField(amqpReceiveHandler, "amqpFeedbackReceivedEvent");
// Assert
assertEquals(hostName + ":5671", _hostName);
assertEquals(userName, _userName);
assertEquals(sasToken, _sasToken);
assertEquals(amqpFeedbackReceivedEvent, _amqpFeedbackReceivedEvent);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpReceiveHandlerTest method onDelivery_call_flow_and_init_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_004: [The event handler shall get the Link, Receiver and Delivery (Proton) objects from the event]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_005: [The event handler shall read the received buffer] int size = delivery.pending();
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_006: [The event handler shall create a Message (Proton) object from the decoded buffer]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_007: [** The event handler shall settle the Delivery with the Accepted outcome **]**
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_008: [The event handler shall close the Session and Connection (Proton)]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_009: [The event handler shall call the FeedbackReceived callback if it has been initialized]
@Test
public void onDelivery_call_flow_and_init_ok() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
final String hostAddr = hostName + ":5671";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
createProtonObjects();
AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
// Assert
new Expectations() {
{
event.getLink();
receiver.current();
delivery.isReadable();
delivery.isPartial();
delivery.getLink();
delivery.pending();
byte[] buffer = new byte[1024];
receiver.recv(buffer, 0, buffer.length);
message.decode(withAny(buffer), 0, anyInt);
// send disposition frame and settle the outcome
delivery.disposition(Accepted.getInstance());
delivery.settle();
session = receiver.getSession();
session.close();
connection = session.getConnection();
connection.close();
}
};
// Act
amqpReceiveHandler.onDelivery(event);
}
Aggregations