Search in sources :

Example 11 with AmqpSendHandler

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();
}
Also used : Expectations(mockit.Expectations) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) AmqpResponseVerification(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification) Test(org.junit.Test)

Example 12 with AmqpSendHandler

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

Example 13 with AmqpSendHandler

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

Example 14 with AmqpSendHandler

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

Example 15 with AmqpSendHandler

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

Aggregations

IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)20 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)20 Test (org.junit.Test)20 Expectations (mockit.Expectations)12 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 Message (org.apache.qpid.proton.message.Message)3 AmqpResponseVerification (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification)2 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)1 Message (com.microsoft.azure.sdk.iot.service.Message)1 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)1 Verifications (mockit.Verifications)1 Binary (org.apache.qpid.proton.amqp.Binary)1 Symbol (org.apache.qpid.proton.amqp.Symbol)1 Properties (org.apache.qpid.proton.amqp.messaging.Properties)1 Target (org.apache.qpid.proton.amqp.messaging.Target)1 Handshaker (org.apache.qpid.proton.reactor.Handshaker)1