Search in sources :

Example 16 with Expectations

use of mockit.Expectations in project java-chassis by ServiceComb.

the class TestHttpsClient method testInitKeyStore.

@Test
public void testInitKeyStore(@Mocked final HttpsConfigInfoBean configInfoBean, @Mocked final KeyManagerFactory factory) {
    HttpsConfigInfoBean oBean = new HttpsConfigInfoBean();
    new Expectations() {

        {
            configInfoBean.getKeyStorePath();
            result = "/foundation-common/src/test/resources/config/test.1.properties";
            configInfoBean.getKeyStorePasswd();
            result = "1769";
            configInfoBean.getTrustStorePath();
            result = "/foundation-common/src/test/resources/config/test.1.properties";
            configInfoBean.getTrustStorePasswd();
            result = "1769";
        }
    };
    new MockUp<KeyManagerFactory>() {

        @Mock
        public final void init(KeyStore ks, char[] password) {
        }

        @Mock
        public final KeyManager[] getKeyManagers() {
            return null;
        }
    };
    String keyStoreType = KeyStore.getDefaultType();
    try {
        final KeyStore keyStore = KeyStore.getInstance(keyStoreType);
        new MockUp<HttpsClient>() {

            @Mock
            private KeyStore initKeyStore(String storePath, String storePasswd, String storeType) throws IOException {
                return keyStore;
            }
        };
    } catch (KeyStoreException e) {
        Assert.assertTrue(false);
    }
    HttpsClient.getHttpsClient(oBean);
    Assert.assertNotEquals(null, HttpsClient.getHttpsClient(Mockito.mock(HttpsConfigInfoBean.class)));
}
Also used : Expectations(mockit.Expectations) MockUp(mockit.MockUp) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) HttpsConfigInfoBean(io.servicecomb.foundation.common.entities.HttpsConfigInfoBean) Test(org.junit.Test)

Example 17 with Expectations

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

the class FeedbackReceiverTest method receive_async_without_deviceId.

// 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_without_deviceId() throws Exception {
    // Arrange
    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(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 18 with Expectations

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

the class FeedbackReceiverTest method receive_with_timout_call_receive_timeout_without_deviceId.

// 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_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);
        }
    };
    // 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)

Example 19 with Expectations

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

the class FeedbackReceiverTest method open_call_receiver_open_without_deviceId.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_005: [The function shall call open() on the member AMQPReceive object]
@Test
public void open_call_receiver_open_without_deviceId() throws Exception {
    // Arrange
    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.open();
        }
    };
    // Act
    feedbackReceiver.open();
}
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)

Example 20 with Expectations

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

the class FeedbackReceiverTest method close_call_receiver_close.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_007: [The function shall call close() on the member AMQPReceive object]
@Test
public void close_call_receiver_close() 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.close();
        }
    };
    // Act
    feedbackReceiver.close();
}
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)113 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