Search in sources :

Example 6 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 onLinkFlow_call_flow_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_017: [The event handler shall get the Sender (Proton) object from the link]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_018: [The event handler shall encode the message and copy to the byte buffer]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_019: [The event handler shall set the delivery tag on the Sender (Proton) object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_020: [The event handler shall send the encoded bytes]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_021: [The event handler shall close the Sender, Session and Connection]
@Test
public void onLinkFlow_call_flow_ok() throws UnsupportedEncodingException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String hostAddr = hostName + ":5671";
    String deviceId = "deviceId";
    String content = "abcdefghijklmnopqrst";
    com.microsoft.azure.sdk.iot.service.Message iotMessage = new com.microsoft.azure.sdk.iot.service.Message(content);
    String endpoint = "/messages/devicebound";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    createProtonObjects();
    AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpSendHandler.createProtonMessage(deviceId, iotMessage);
    // Assert
    new Expectations() {

        {
            link = event.getLink();
            link.getCredit();
            byte[] buffer = new byte[1024];
            message.encode(buffer, 0, 1024);
        }
    };
    // Act
    amqpSendHandler.onLinkFlow(event);
}
Also used : Expectations(mockit.Expectations) Message(org.apache.qpid.proton.message.Message) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 7 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_protocol_null.

// 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_protocol_null() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = null;
    // 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 8 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 onConnectionBound_call_flow_and_init_ok_amqp.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_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_AMQPSENDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_023: [The event handler shall not initialize WebSocket if the protocol is AMQP]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqp() {
    // 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();
            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
    amqpSendHandler.onConnectionBound(event);
}
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 9 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_userName_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_userName_empty() {
    // Arrange
    String hostName = "aaa";
    String userName = "";
    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 10 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_userName_null.

// 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_userName_null() {
    // Arrange
    String hostName = "aaa";
    String userName = null;
    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)

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