Search in sources :

Example 66 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NotificationBoltTest method testFail.

@Test
public void testFail() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("foobar", "100");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
    final Notification notification = new StreamlineEventAdapter(event);
    new MockUp<NotificationQueueHandler>() {

        @Mock
        public void enqueue(Notifier notifier, Notification notification1) {
            notifier.notify(notification);
        }

        @Mock
        public void resubmit(String notificationId) {
            notifier.notify(notification);
        }
    };
    new Expectations() {

        {
            mockProxyUtil.loadClassFromJar(anyString, "TestClass");
            result = notifier;
            tuple.getValueByField(anyString);
            result = event;
        }
    };
    Map<String, String> stormConf = new HashMap<>();
    stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
    stormConf.put("local.notifier.jar.path", "/tmp");
    bolt.prepare(stormConf, null, collector);
    bolt.execute(tuple);
    new Verifications() {

        {
            hBaseNotificationStore.store(notification);
            times = 1;
            hBaseNotificationStore.updateNotificationStatus(notification.getId(), Notification.Status.FAILED);
            times = 1;
            collector.ack(tuple);
            times = 0;
            collector.fail(tuple);
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) MockUp(mockit.MockUp) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 67 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class FunctionsTest method testStringFunctions1.

@Test
public void testStringFunctions1() throws Exception {
    doTest(readFile("/streamline-udf.json"), getTuple());
    new Verifications() {

        {
            String streamId;
            Tuple anchor;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
            Assert.assertEquals(1, tuples.size());
            Assert.assertEquals("CONCAT helloworld IDENTITY hello UPPER HELLO LOWER hello INITCAP Hello CHAR_LENGTH 5", ((StreamlineEvent) (tuples.get(0).get(0))).get("body"));
        }
    };
}
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 68 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class FunctionsTest method testStringFunctions3.

@Test
public void testStringFunctions3() throws Exception {
    doTest(readFile("/streamline-udf3.json"), getTuple());
    new Verifications() {

        {
            String streamId;
            Tuple anchor;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
            Assert.assertEquals(1, tuples.size());
            Assert.assertEquals("TRIM2 space LTRIM2 space  RTRIM2  space", ((StreamlineEvent) (tuples.get(0).get(0))).get("body"));
        }
    };
}
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 69 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventCorrelatingOutputCollectorTest method testAck.

@Test
public void testAck() throws Exception {
    setupExpectationsForTuple();
    setupExpectationsForTopologyContextNoEmit();
    EventCorrelatingOutputCollector sut = getSystemUnderTest();
    Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(PARENT_STREAMLINE_EVENT), TASK_0, Utils.DEFAULT_STREAM_ID);
    sut.ack(anchor);
    new Verifications() {

        {
            mockedOutputCollector.ack(anchor);
            times = 1;
        }
    };
}
Also used : Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 70 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventCorrelatingOutputCollectorTest method emitWithoutAnchor.

@Test
public void emitWithoutAnchor() throws Exception {
    setupExpectationsForTopologyContextEmit();
    setupExpectationsForEventCorrelationInjector();
    EventCorrelatingOutputCollector sut = getSystemUnderTest();
    String testStreamId = "testStreamId";
    List<Integer> expectedTasks = Lists.newArrayList(TASK_1, TASK_2);
    final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
    // String streamId, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emit(testStreamId, withAny(tuple));
            result = expectedTasks;
        }
    };
    List<Integer> tasks = sut.emit(testStreamId, tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

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

        {
            mockedOutputCollector.emit(withAny(tuple));
            result = expectedTasks;
        }
    };
    tasks = sut.emit(tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emit(capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.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)

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