Search in sources :

Example 61 with Expectations

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

the class AmqpFileUploadNotificationReceivedHandlerTest method onConnectionBoundCallFlowAndInitOkAmqps.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_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_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBoundCallFlowAndInitOkAmqps() {
    // Arrange
    final String hostName = "aaa";
    final String userName = "bbb";
    final String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
    // 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
    Deencapsulation.invoke(amqpReceiveHandler, "onConnectionBound", event);
}
Also used : Expectations(mockit.Expectations) WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 62 with Expectations

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

the class DeviceTest method createFromId_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_003: [The constructor shall create a new instance of Device using the given deviceId and return with it]
@Test
public void createFromId_good_case() throws NoSuchAlgorithmException {
    // Arrange
    String deviceId = "xxx-device";
    new Expectations() {

        {
            Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
        }
    };
    // Act
    Device device = Device.createFromId(deviceId, null, null);
    // Assert
    assertNotEquals(device, null);
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) Expectations(mockit.Expectations) Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 63 with Expectations

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

the class FeedbackReceiverTest method receive_async.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_013: [The function shall create an async wrapper around the receive() function call]
@Test
public void receive_async() throws Exception {
    // Arrange
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    String deviceId = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
    // Assert
    new Expectations() {

        {
            amqpReceive.receive(Deencapsulation.getField(feedbackReceiver, "DEFAULT_TIMEOUT_MS"));
            feedbackReceiver.receive();
        }
    };
    // Act
    CompletableFuture<FeedbackBatch> completableFuture = feedbackReceiver.receiveAsync();
    completableFuture.get();
}
Also used : Expectations(mockit.Expectations) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) FeedbackBatch(com.microsoft.azure.sdk.iot.service.FeedbackBatch) Test(org.junit.Test)

Example 64 with Expectations

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

the class FeedbackReceiverTest method receive_with_timout_async_without_deviceId.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_014: [The function shall create an async wrapper around the receive(long timeoutMs) function call]
@Test
public void receive_with_timout_async_without_deviceId() throws Exception {
    // Arrange
    long timeoutMs = 1000;
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            amqpReceive.receive(timeoutMs);
            feedbackReceiver.receive(anyLong);
        }
    };
    // Act
    CompletableFuture<FeedbackBatch> completableFuture = feedbackReceiver.receiveAsync(timeoutMs);
    completableFuture.get();
}
Also used : Expectations(mockit.Expectations) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) FeedbackBatch(com.microsoft.azure.sdk.iot.service.FeedbackBatch) Test(org.junit.Test)

Example 65 with Expectations

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

the class FeedbackReceiverTest method receive_with_timout_call_receive_timeout.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_010: [The function shall call receive() on the member AMQPReceive object and return with the result]
@Test
public void receive_with_timout_call_receive_timeout() throws Exception {
    // Arrange
    long timeoutMs = 1000;
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    String deviceId = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
    // Assert
    new Expectations() {

        {
            amqpReceive.receive(timeoutMs);
        }
    };
    // Act
    feedbackReceiver.receive(timeoutMs);
}
Also used : Expectations(mockit.Expectations) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) 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