Search in sources :

Example 91 with Expectations

use of mockit.Expectations in project azure-iot-sdk-java by Azure.

the class AmqpReceiveTest method receive_with_timout_zero_call_flow_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_005: [The function shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_006: [The function shall start the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_008: [The function shall stop and free the Proton reactor object ]
@Test
public void receive_with_timout_zero_call_flow_ok() throws IOException, InterruptedException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    int timeoutMs = 0;
    AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpReceive.open();
    // Assert
    new Expectations() {

        {
            reactor = proton.reactor(amqpReceive);
            reactor.start();
            reactor.stop();
            reactor.process();
            reactor.free();
        }
    };
    // Act
    amqpReceive.receive(timeoutMs);
}
Also used : Expectations(mockit.Expectations) AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 92 with Expectations

use of mockit.Expectations in project azure-iot-sdk-java by Azure.

the class AmqpReceiveTest method receiveWithTimout_non_zero_call_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_005: [The function shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_006: [The function shall start the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_008: [The function shall stop and free the Proton reactor object ]
@Test
public void receiveWithTimout_non_zero_call_ok() throws IOException, InterruptedException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    int timeoutMs = 1;
    AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpReceive.open();
    // Assert
    new Expectations() {

        {
            reactor = proton.reactor(amqpReceive);
            reactor.start();
            reactor.stop();
            reactor.process();
            reactor.free();
        }
    };
    // Act
    amqpReceive.receive(timeoutMs);
}
Also used : Expectations(mockit.Expectations) AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 93 with Expectations

use of mockit.Expectations 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 94 with Expectations

use of mockit.Expectations 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)

Example 95 with Expectations

use of mockit.Expectations 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)

Aggregations

Expectations (mockit.Expectations)114 Test (org.junit.Test)98 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)60 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)19 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 Test (org.testng.annotations.Test)14 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)12 ByteBuffer (java.nio.ByteBuffer)12 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)10 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)6 AmqpReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive)5 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)5 FeedbackBatch (com.microsoft.azure.sdk.iot.service.FeedbackBatch)4 Message (com.microsoft.azure.sdk.iot.service.Message)4 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)4 HeartbeatResponse (io.servicecomb.serviceregistry.api.response.HeartbeatResponse)4 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)3 Tools (com.microsoft.azure.sdk.iot.service.Tools)3 AmqpFileUploadNotificationReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceive)3 Endpoint (io.servicecomb.core.Endpoint)3