use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_KVP.
@Test
public void testInterceptor_KVP() throws Exception {
KeyValuePairList kvp = new KeyValuePairList();
kvp.add(new KeyValuePair("key1", "value1"));
kvp.add(new KeyValuePair("key2", "value2"));
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setValuesToSet(kvp);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
assertTrue(metadata.containsKey("key1"));
assertEquals("value1", metadata.get("key1"));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_Defaults_NoWorkflowId.
// For coverage in the addDefaults section.
@Test
public void testInterceptor_Defaults_NoWorkflowId() throws Exception {
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setAddDefaultKeysAsObjectMetadata(true);
StandardWorkflow wf = new StandardWorkflow();
wf.addInterceptor(interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
// MockChannel gives itself an ID.
MockChannel c = new MockChannel();
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertTrue(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class MessageCountNotificationTest method testNotification_BelowThreshold_MaxExceeded.
@Test
public void testNotification_BelowThreshold_MaxExceeded() throws Exception {
MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
notif.setMessageCount(2);
notif.setMaxNotifications(1);
StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
Adapter adapter = createAdapter(getName(), workflow);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
assertNotNull(notifier);
ObjectName notifObjName = notifier.createObjectName();
SimpleNotificationListener listener = new SimpleNotificationListener();
try {
start(adapter);
register(mBeans);
mBeanServer.addNotificationListener(notifObjName, listener, null, null);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
submitWithDelay(msg, workflow, 6, 5);
LifecycleHelper.waitQuietly(200);
submitWithDelay(msg, workflow, 1, 0);
LifecycleHelper.waitQuietly(200);
submitWithDelay(msg, workflow, 1, 0);
LifecycleHelper.waitQuietly(200);
submitWithDelay(msg, workflow, 1, 0);
listener.waitForMessages(2);
assertEquals(2, listener.getNotifications().size());
Notification n1 = listener.getNotifications().get(0);
Notification n2 = listener.getNotifications().get(1);
assertTrue(n1.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_ABOVE_THRESHOLD));
assertTrue(n2.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_BELOW_THRESHOLD));
} finally {
stop(adapter);
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class MessageCountNotificationTest method testNotification_StaysBelowThreshold.
@Test
public void testNotification_StaysBelowThreshold() throws Exception {
MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(1L, TimeUnit.SECONDS));
notif.setMessageCount(5);
StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
Adapter adapter = createAdapter(getName(), workflow);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
assertNotNull(notifier);
ObjectName notifObjName = notifier.createObjectName();
SimpleNotificationListener listener = new SimpleNotificationListener();
try {
start(adapter);
register(mBeans);
mBeanServer.addNotificationListener(notifObjName, listener, null, null);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
submitWithDelay(msg, workflow, 1, 5);
LifecycleHelper.waitQuietly(200);
submitWithDelay(msg, workflow, 1, 5);
LifecycleHelper.waitQuietly(200);
submitWithDelay(msg, workflow, 1, 5);
LifecycleHelper.waitQuietly(200);
submitWithDelay(msg, workflow, 1, 5);
} finally {
stop(adapter);
}
assertEquals(0, listener.getNotifications().size());
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class MessageCountNotificationTest method testNotification_NoNotifications.
@Test
public void testNotification_NoNotifications() throws Exception {
MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(10L, TimeUnit.SECONDS));
StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
Adapter adapter = createAdapter(getName(), workflow);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
assertNotNull(notifier);
ObjectName notifObjName = notifier.createObjectName();
SimpleNotificationListener listener = new SimpleNotificationListener();
try {
start(adapter);
register(mBeans);
mBeanServer.addNotificationListener(notifObjName, listener, null, null);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
submitWithDelay(msg, workflow, 5, 5);
} finally {
stop(adapter);
}
assertEquals(0, listener.getNotifications().size());
}
Aggregations