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());
}
};
}
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);
}
};
}
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);
}
};
}
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);
}
};
}
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;
}
};
}
Aggregations