Search in sources :

Example 86 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class RulesBoltConditionTest method testPassThrough.

@Test
public void testPassThrough() throws Exception {
    doTest(readFile("/passthrough-rule.json"), getTuple(20));
    new Verifications() {

        {
            String streamId;
            Tuple anchor;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
            System.out.println(streamId);
            System.out.println(anchor);
            System.out.println(tuples);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Verifications(mockit.Verifications) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 87 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventCorrelatingSpoutOutputCollectorTest method emitDirect.

@Test
public void emitDirect() throws Exception {
    setupExpectationsForTopologyContextEmit();
    setupExpectationsForEventCorrelationInjector();
    sut = new EventCorrelatingSpoutOutputCollector(mockedTopologyContext, mockedOutputCollector);
    Deencapsulation.setField(sut, "eventCorrelationInjector", mockEventCorrelationInjector);
    String testStreamId = "testStreamId";
    final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
    String messageId = "testMessageId";
    // int taskId, String streamId, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(TASK_1, testStreamId, withAny(tuple));
        }
    };
    sut.emitDirect(TASK_1, testStreamId, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(TASK_1, testStreamId, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(0, capturedParents.size());
        }
    };
    // int taskId, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(TASK_1, withAny(tuple));
        }
    };
    sut.emitDirect(TASK_1, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(TASK_1, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(0, capturedParents.size());
        }
    };
    // int taskId, String streamId, List<Object> tuple, Object messageId
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(TASK_1, testStreamId, withAny(tuple), messageId);
        }
    };
    sut.emitDirect(TASK_1, testStreamId, tuple, messageId);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(TASK_1, testStreamId, capturedValues = withCapture(), messageId);
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(0, capturedParents.size());
        }
    };
    // int taskId, List<Object> tuple, Object messageId
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(TASK_1, withAny(tuple), messageId);
        }
    };
    sut.emitDirect(TASK_1, tuple, messageId);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(TASK_1, capturedValues = withCapture(), messageId);
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(0, capturedParents.size());
        }
    };
}
Also used : Expectations(mockit.Expectations) Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 88 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class HBaseBundleHintProviderTest method testGetHintsOnCluster.

// FIXME: below hint needs to access HBase and currently it doesn't work with secure cluster
// FIXME: hence can't add HBase sink to the topology
// FIXME: so we should mark this test to ignore until it is fixed
@Ignore
@Test
public void testGetHintsOnCluster() throws Exception {
    List<String> tables = Lists.newArrayList("test1", "test2", "test3");
    new Expectations() {

        {
            hbaseMetadataService.getHBaseTables();
            result = new Tables(tables);
        }
    };
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cluster1");
    Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null);
    Assert.assertNotNull(hints);
    Assert.assertEquals(1, hints.size());
    Assert.assertEquals(tables, hints.get(HBaseBundleHintProvider.FIELD_NAME_TABLE));
    new Verifications() {

        {
            hbaseMetadataService.getHBaseTables();
        }
    };
}
Also used : Expectations(mockit.Expectations) Tables(com.hortonworks.streamline.streams.cluster.service.metadata.json.Tables) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Verifications(mockit.Verifications) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 89 with Verifications

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

the class FileUploadNotificationReceiverTest method receiveAsync.

// Tests_SRS_SERVICE_SDK_JAVA_FILEUPLOADNOTIFICATIONRECEIVER_25_012: [ The function shall create an async wrapper around the receive() function call using the default timeout ]
@Test
public void receiveAsync() throws Exception {
    // Arrange
    final String hostName = "xxx";
    final String userName = "xxx";
    final String sasToken = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FileUploadNotificationReceiver fileUploadNotificationReceiver = Deencapsulation.newInstance(FileUploadNotificationReceiver.class, hostName, userName, sasToken, iotHubServiceClientProtocol, mockedProxyOptions, mockedSslContext);
    // Act
    CompletableFuture<FileUploadNotification> completableFuture = fileUploadNotificationReceiver.receiveAsync();
    completableFuture.get();
    // Assert
    new Verifications() {

        {
            amqpFileUploadNotificationReceive.receive(Deencapsulation.getField(fileUploadNotificationReceiver, "DEFAULT_TIMEOUT_MS"));
            times = 1;
            fileUploadNotificationReceiver.receive();
            times = 1;
        }
    };
}
Also used : FileUploadNotification(com.microsoft.azure.sdk.iot.service.FileUploadNotification) FileUploadNotificationReceiver(com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver) Verifications(mockit.Verifications) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 90 with Verifications

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

the class FileUploadNotificationReceiverTest method receiveWithTimeoutAsync.

// Tests_SRS_SERVICE_SDK_JAVA_FILEUPLOADNOTIFICATIONRECEIVER_25_013: [ The function shall create an async wrapper around the receive(long timeoutMs) function call ]
@Test
public void receiveWithTimeoutAsync() throws Exception {
    // Arrange
    long timeoutMs = 1000;
    final String hostName = "xxx";
    final String userName = "xxx";
    final String sasToken = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FileUploadNotificationReceiver fileUploadNotificationReceiver = Deencapsulation.newInstance(FileUploadNotificationReceiver.class, hostName, userName, sasToken, iotHubServiceClientProtocol, mockedProxyOptions, mockedSslContext);
    // Act
    CompletableFuture<FileUploadNotification> completableFuture = fileUploadNotificationReceiver.receiveAsync(timeoutMs);
    completableFuture.get();
    // Assert
    new Verifications() {

        {
            amqpFileUploadNotificationReceive.receive(timeoutMs);
            times = 1;
            fileUploadNotificationReceiver.receive(anyLong);
            times = 1;
        }
    };
}
Also used : FileUploadNotification(com.microsoft.azure.sdk.iot.service.FileUploadNotification) FileUploadNotificationReceiver(com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver) Verifications(mockit.Verifications) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

Verifications (mockit.Verifications)329 Test (org.junit.Test)326 NonStrictExpectations (mockit.NonStrictExpectations)163 Expectations (mockit.Expectations)52 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)34 Tuple (org.apache.storm.tuple.Tuple)28 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)24 AmqpResponseVerification (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification)22 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)21 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)21 ArrayList (java.util.ArrayList)21 List (java.util.List)21 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)20 FileUploadNotificationReceiver (com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver)18 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)17 HashMap (java.util.HashMap)16 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)14 IOException (java.io.IOException)14 Values (org.apache.storm.tuple.Values)14 SaslListenerImpl (com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl)13