Search in sources :

Example 76 with Expectations

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

the class ServiceClientTest method send_call_sender_close.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_013: [The function shall call send() on the member AMQP sender object with the given parameters]
@Test
public void send_call_sender_close() throws Exception {
    // Arrange
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    String deviceId = "XXX";
    String content = "HELLO";
    Message iotMessage = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            amqpSend.send(deviceId, iotMessage);
        }
    };
    // Act
    serviceClient.send(deviceId, iotMessage);
}
Also used : Expectations(mockit.Expectations) Message(com.microsoft.azure.sdk.iot.service.Message) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 77 with Expectations

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

the class ServiceClientTest method open_async_future_return_ok.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_014: [The function shall create an async wrapper around the open() function call, handle the return value or delegate exception]
@Test
public void open_async_future_return_ok() throws Exception {
    // Arrange
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            amqpSend.open();
            serviceClient.open();
        }
    };
    // Act
    CompletableFuture<Void> completableFuture = serviceClient.openAsync();
    completableFuture.get();
}
Also used : Expectations(mockit.Expectations) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 78 with Expectations

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

the class ServiceClientTest method getFeedbackReceiver_good_case_without_deviceid.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_017: [The function shall create a FeedbackReceiver object and returns with it]
@Test
public void getFeedbackReceiver_good_case_without_deviceid() throws Exception {
    // Arrange
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            feedbackReceiver = new FeedbackReceiver(anyString, anyString, anyString, iotHubServiceClientProtocol);
        }
    };
    // Act
    FeedbackReceiver feedbackReceiver = serviceClient.getFeedbackReceiver();
    // Assert
    assertNotEquals(null, feedbackReceiver);
}
Also used : Expectations(mockit.Expectations) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 79 with Expectations

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

the class ToolsTest method isNullOrWhiteSpace_not_empty.

// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_005: [The function shall call the isNullOrEmpty function and return with it’s return value]
@Test
public void isNullOrWhiteSpace_not_empty() {
    // Arrange
    String value = "XXX";
    Boolean expResult = false;
    new Expectations() {

        Tools tools;

        {
            tools.isNullOrEmpty(anyString);
        }
    };
    // Act
    Boolean result = Tools.isNullOrWhiteSpace(value);
    // Assert
    assertEquals(expResult, result);
}
Also used : Expectations(mockit.Expectations) Tools(com.microsoft.azure.sdk.iot.service.Tools) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 80 with Expectations

use of mockit.Expectations in project pulsar by yahoo.

the class AbstractStatelessLongHashTest method testCalculateByteBuffer.

@Test
public void testCalculateByteBuffer() {
    final ByteBuffer input = ByteBuffer.allocate(20);
    input.position(5);
    input.limit(15);
    new Expectations(hash) {

        {
            hash.calculateUnchecked(input.array(), input.arrayOffset() + 5, 10);
        }
    };
    hash.calculate(input);
    assertEquals(input.limit(), input.position());
}
Also used : Expectations(mockit.Expectations) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.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