Search in sources :

Example 61 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NotificationServiceImplTest method testRegister.

@Test
public void testRegister() throws Exception {
    new Expectations() {

        {
            mockCtx.getConfig();
            times = 3;
            result = mockNotifierConfig;
            mockNotifierConfig.getClassName();
            times = 1;
            result = "Test";
            mockNotifierConfig.getJarPath();
            times = 1;
            result = "/tmp/test.jar";
            mockProxyUtil.loadClassFromJar("/tmp/test.jar", "Test");
            result = mockNotifier;
        }
    };
    Notifier result = notificationService.register("test_notifier", mockCtx);
    assertEquals(mockNotifier, result);
    new Verifications() {

        {
            NotificationContext ctx;
            mockNotifier.open(ctx = withCapture());
            times = 1;
            assertEquals(NotificationServiceContext.class, ctx.getClass());
        }
    };
}
Also used : Expectations(mockit.Expectations) NotificationContext(com.hortonworks.streamline.streams.notification.NotificationContext) Verifications(mockit.Verifications) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 62 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class HBaseNotificationStoreTest method testGetNotification.

@Test
public void testGetNotification() throws Exception {
    final Map<byte[], byte[]> tsMap = new TreeMap<>(new Bytes.ByteArrayComparator());
    tsMap.put("1444042473518".getBytes(), "1".getBytes());
    new Expectations() {

        {
            mockResult.getRow();
            times = 1;
            result = "rowid".getBytes(CHARSET);
            mockResult.getValue("s".getBytes(), "qs".getBytes());
            times = 1;
            result = "DELIVERED".getBytes();
            mockResult.getFamilyMap("ts".getBytes());
            times = 1;
            result = tsMap;
        }
    };
    Notification notification = notificationStore.getNotification("n123");
    // System.out.println(notification);
    assertEquals("rowid", notification.getId());
    assertEquals(Notification.Status.DELIVERED, notification.getStatus());
    assertEquals(1444042473518L, notification.getTs());
    new Verifications() {

        {
            Get get;
            mockHTable.get(get = withCapture());
            times = 1;
        // System.out.println("get = " + get);
        }
    };
}
Also used : Expectations(mockit.Expectations) Bytes(org.apache.hadoop.hbase.util.Bytes) Get(org.apache.hadoop.hbase.client.Get) TreeMap(java.util.TreeMap) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test)

Example 63 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EmailNotifierTest method testNotifyOverride.

@Test
public void testNotifyOverride() throws Exception {
    final Map<String, String> defaultFieldValues = new HashMap() {

        {
            put("from", "foo@bar.com");
            put("to", "to@bar.com");
        }
    };
    final Map<String, String> fieldsAndValues = new HashMap() {

        {
            put("from", "bar@baz.com");
        }
    };
    new Expectations() {

        {
            mockNotificationContext.getConfig();
            result = mockNotifierConfig;
            mockNotifierConfig.getDefaultFieldValues();
            times = 1;
            result = defaultFieldValues;
            mockNotifierConfig.getProperties();
            result = new Properties();
            mockNotification.getFieldsAndValues();
            times = 1;
            result = fieldsAndValues;
            mockNotification.getId();
            times = 1;
            result = "ABC";
        }
    };
    emailNotifier.open(mockNotificationContext);
    emailNotifier.notify(mockNotification);
    new Verifications() {

        {
            Message msg = null;
            Address[] addr = null;
            mockTransport.sendMessage(msg = withCapture(), addr = withCapture());
            Assert.assertEquals("bar@baz.com", msg.getFrom()[0].toString());
            Assert.assertEquals("to@bar.com", msg.getAllRecipients()[0].toString());
        // System.out.println(addr);
        }
    };
}
Also used : Expectations(mockit.Expectations) Message(javax.mail.Message) Address(javax.mail.Address) HashMap(java.util.HashMap) Properties(java.util.Properties) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 64 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EmailNotifierTest method testDelivered.

@Test
public void testDelivered() throws Exception {
    setupExpectations();
    emailNotifier.open(mockNotificationContext);
    emailNotifier.notify(mockNotification);
    final AtomicReference<Message> msgWrapper = new AtomicReference<>();
    new Verifications() {

        {
            Address[] addr = null;
            Message msg;
            mockTransport.sendMessage(msg = withCapture(), addr = withCapture());
            Assert.assertEquals("foo@bar.com", msg.getFrom()[0].toString());
            Assert.assertEquals("to@bar.com", msg.getAllRecipients()[0].toString());
            msgWrapper.set(msg);
        // System.out.println(addr);
        }
    };
    new Expectations() {

        {
            mockTransportEvent.getMessage();
            times = 1;
            result = msgWrapper.get();
        }
    };
    emailNotifier.messageDelivered(mockTransportEvent);
    new Verifications() {

        {
            String id;
            mockNotificationContext.ack(id = withCapture());
            assertEquals("ABC", id);
        }
    };
}
Also used : Expectations(mockit.Expectations) Message(javax.mail.Message) Address(javax.mail.Address) AtomicReference(java.util.concurrent.atomic.AtomicReference) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 65 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NotificationBoltTest method testWithConsoleNotifier.

@Test
public void testWithConsoleNotifier() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("foo", "100");
    fieldsAndValues.put("bar", "200");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
    NotificationBolt consoleNotificationBolt = new NotificationBolt(new NotificationSink() {

        @Override
        public String getNotifierName() {
            return "console_notifier";
        }

        @Override
        public String getNotifierJarFileName() {
            return "console_notifier.jar";
        }

        @Override
        public String getNotifierClassName() {
            return "ConsoleNotifier";
        }

        @Override
        public Map<String, Object> getNotifierProperties() {
            return new HashMap<>();
        }

        @Override
        public Map<String, Object> getNotifierFieldValues() {
            return new HashMap<>();
        }
    });
    consoleNotificationBolt.withNotificationStoreClass("com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore");
    final ConsoleNotifier consoleNotifier = new ConsoleNotifier();
    final Notification notification = new StreamlineEventAdapter(event);
    new MockUp<NotificationQueueHandler>() {

        @Mock
        public void enqueue(Notifier notifier, Notification notification1) {
            // System.out.println("Mocked enqueue");
            notifier.notify(notification);
        }
    };
    new Expectations() {

        {
            mockProxyUtil.loadClassFromJar("/tmp/console_notifier.jar", "ConsoleNotifier");
            result = consoleNotifier;
            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");
    consoleNotificationBolt.prepare(stormConf, null, collector);
    consoleNotificationBolt.execute(tuple);
    new Verifications() {

        {
            collector.ack(tuple);
            times = 1;
            hBaseNotificationStore.store(notification);
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) MockUp(mockit.MockUp) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) NotificationSink(com.hortonworks.streamline.streams.layout.component.impl.NotificationSink) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) HashMap(java.util.HashMap) Map(java.util.Map) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) 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