Search in sources :

Example 21 with StandardWorkflow

use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.

the class LoggingContextInterceptorTest method testInterceptor_Defaults.

@Test
public void testInterceptor_Defaults() throws Exception {
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    interceptor.setAddDefaultKeysAsObjectMetadata(true);
    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();
        Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
        assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertTrue(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertEquals("channelName", object.get(CoreConstants.CHANNEL_ID_KEY));
        assertTrue(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertEquals("workflowName", object.get(CoreConstants.WORKFLOW_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertEquals(msg.getUniqueId(), object.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 22 with StandardWorkflow

use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.

the class LoggingContextInterceptorTest method testInterceptor_KVP_Expression.

@Test
public void testInterceptor_KVP_Expression() throws Exception {
    KeyValuePairList kvp = new KeyValuePairList();
    kvp.add(new KeyValuePair("key1", "%message{mk1}"));
    kvp.add(new KeyValuePair("key2", "%message{mk2}"));
    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();
        msg.addMetadata("mk1", "mv1");
        msg.addMetadata("mk2", "mv2");
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        assertTrue(metadata.containsKey("key1"));
        assertEquals("mv1", metadata.get("key1"));
        assertTrue(metadata.containsKey("key2"));
        assertEquals("mv2", metadata.get("key2"));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) KeyValuePair(com.adaptris.util.KeyValuePair) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) KeyValuePairList(com.adaptris.util.KeyValuePairList) Test(org.junit.Test)

Example 23 with StandardWorkflow

use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_BelowThreshold.

@Test
public void testNotification_BelowThreshold() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(2);
    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(3);
        assertEquals(3, 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);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 24 with StandardWorkflow

use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_AboveThreshold.

@Test
public void testNotification_AboveThreshold() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(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, 5);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        assertTrue(notification.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_ABOVE_THRESHOLD));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 25 with StandardWorkflow

use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_AboveThreshold_MaxExceeded.

@Test
public void testNotification_AboveThreshold_MaxExceeded() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(1);
    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();
    System.err.println(notifObjName);
    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, 10, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 6, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 0);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        assertTrue(notification.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_ABOVE_THRESHOLD));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

StandardWorkflow (com.adaptris.core.StandardWorkflow)102 Test (org.junit.Test)78 Channel (com.adaptris.core.Channel)67 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)55 Adapter (com.adaptris.core.Adapter)53 ObjectName (javax.management.ObjectName)41 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)38 TimeInterval (com.adaptris.util.TimeInterval)25 StandaloneProducer (com.adaptris.core.StandaloneProducer)20 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)16 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)16 ArrayList (java.util.ArrayList)14 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)12 MockChannel (com.adaptris.core.stubs.MockChannel)11 Notification (javax.management.Notification)11 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)10 ServiceList (com.adaptris.core.ServiceList)10 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)10 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)9 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)9