Search in sources :

Example 1 with AmqpFeedbackReceivedHandler

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler 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);
}
Also used : Expectations(mockit.Expectations) Symbol(org.apache.qpid.proton.amqp.Symbol) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 2 with AmqpFeedbackReceivedHandler

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler 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);
}
Also used : Expectations(mockit.Expectations) AmqpFeedbackReceivedEvent(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedEvent) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 3 with AmqpFeedbackReceivedHandler

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler 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);
}
Also used : Expectations(mockit.Expectations) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 4 with AmqpFeedbackReceivedHandler

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler in project azure-iot-sdk-java by Azure.

the class AmqpReceiveHandlerTest method onLinkInit_call_flow_and_init_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_015: [The event handler shall create a new Target (Proton) object using the given endpoint address]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_016: [The event handler shall get the Link (Proton) object and set its target to the created Target (Proton) object]
@Test
public void onLinkInit_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 endpoint = "/messages/servicebound/feedback";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
    // Assert
    new Expectations() {

        {
            link = event.getLink();
            link.getName();
            result = RECEIVE_TAG;
            target = new Target();
            target.setAddress(endpoint);
            source = new Source();
            source.setAddress(endpoint);
            link.setTarget(target);
            link.setSource(source);
        }
    };
    // Act
    amqpReceiveHandler.onLinkInit(event);
}
Also used : Expectations(mockit.Expectations) Target(org.apache.qpid.proton.amqp.messaging.Target) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Source(org.apache.qpid.proton.amqp.messaging.Source) Test(org.junit.Test)

Example 5 with AmqpFeedbackReceivedHandler

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler in project azure-iot-sdk-java by Azure.

the class AmqpReceiveHandlerTest method onConnectionBound_call_flow_and_init_ok_amqps.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_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_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqps() {
    // Arrange
    final String hostName = "aaa";
    final String userName = "bbb";
    final String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
    // Assert
    new Expectations() {

        {
            event.getConnection();
            result = connection;
            connection.getTransport();
            result = transportInternal;
            new WebSocketImpl();
            result = webSocket;
            webSocket.configure(anyString, anyString, 0, anyString, null, null);
            transportInternal.addTransportLayer(webSocket);
            sasl.plain(anyString, anyString);
            Proton.sslDomain();
            result = sslDomain;
            sslDomain.init(SslDomain.Mode.CLIENT);
            sslDomain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
            transportInternal.ssl(sslDomain);
        }
    };
    // Act
    amqpReceiveHandler.onConnectionBound(event);
}
Also used : Expectations(mockit.Expectations) WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)6 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)6 Expectations (mockit.Expectations)6 Test (org.junit.Test)6 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)1 AmqpFeedbackReceivedEvent (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedEvent)1 Symbol (org.apache.qpid.proton.amqp.Symbol)1 Source (org.apache.qpid.proton.amqp.messaging.Source)1 Target (org.apache.qpid.proton.amqp.messaging.Target)1