Search in sources :

Example 16 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 onLinkInit_call_flow_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_015: [The event handler shall create a new Target (Proton) object using the given endpoint address]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_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_ok() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String hostAddr = hostName + ":5671";
    String endpoint = "/messages/devicebound";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            link = event.getLink();
            target = new Target();
            target.setAddress(endpoint);
        }
    };
    // Act
    amqpSendHandler.onLinkInit(event);
}
Also used : Expectations(mockit.Expectations) Target(org.apache.qpid.proton.amqp.messaging.Target) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 17 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_sasToken_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_sasToken_empty() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "";
    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 18 with AmqpSendHandler

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

the class AmqpSendTest method send_creates_ProtonMessage.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_006: [The event handler shall create a Proton message with the given content]
@Test
public void send_creates_ProtonMessage() throws Exception {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String deviceId = "deviceId";
    String content = "abcdefghijklmnopqrst";
    Message message = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpSend.open();
    AmqpSendHandler handler = Deencapsulation.getField(amqpSend, "amqpSendHandler");
    // Assert
    new Expectations() {

        {
            Deencapsulation.invoke(handler, "createProtonMessage", deviceId, message);
        }
    };
    // Act
    amqpSend.send(deviceId, message);
}
Also used : Expectations(mockit.Expectations) Message(com.microsoft.azure.sdk.iot.service.Message) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 19 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_sasToken_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_sasToken_null() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = null;
    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 20 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_Connection_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 = IOException.class)
public void sendComplete_throws_Connection_exception_if_found(@Mocked final AmqpResponseVerification mockedVerification, @Mocked final IotHubException mockedIotHubException, @Mocked final Event mockedEvent) 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);
    amqpSendHandler.onTransportError(mockedEvent);
    // Act
    amqpSendHandler.sendComplete();
}
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