Search in sources :

Example 21 with AddMetadataService

use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.

the class ThreadContextWorkflowTest method testOnMessageWithSendEvents.

@Test
public void testOnMessageWithSendEvents() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    MockMessageProducer eventProd = new MockMessageProducer();
    DefaultEventHandler evtHandler = new DefaultEventHandler(eventProd);
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    try {
        channel.setEventHandler(evtHandler);
        ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
        workflow.setSendEvents(true);
        channel.prepare();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make sure all produced", 1, producer.getMessages().size());
        for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
            AdaptrisMessage m = (AdaptrisMessage) i.next();
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
        waitForMessages(eventProd, 1);
        assertEquals(1, eventProd.messageCount());
    } finally {
        stop(channel);
        stop(evtHandler);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) Iterator(java.util.Iterator) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 22 with AddMetadataService

use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.

the class StandardWorkflowTest method testHandleChannelUnavailable.

@Test
public void testHandleChannelUnavailable() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    final MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    try {
        StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
        workflow.setChannelUnavailableWaitInterval(new TimeInterval(1200L, TimeUnit.MILLISECONDS));
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        channel.prepare();
        start(channel);
        channel.toggleAvailability(false);
        Timer t = new Timer(true);
        t.schedule(new TimerTask() {

            @Override
            public void run() {
                channel.toggleAvailability(true);
            }
        }, 500);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make sure all produced", 1, producer.getMessages().size());
        for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
            AdaptrisMessage m = (AdaptrisMessage) i.next();
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Iterator(java.util.Iterator) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Test(org.junit.Test)

Example 23 with AddMetadataService

use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.

the class StandardWorkflowTest method testOnMessageWithInterceptors.

@Test
public void testOnMessageWithInterceptors() throws Exception {
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    MockMessageProducer producer = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    int count = 10;
    try {
        StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
        workflow.addInterceptor(interceptor);
        channel.prepare();
        start(channel);
        for (int i = 0; i < count; i++) {
            AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
            workflow.onAdaptrisMessage(msg);
        }
        assertEquals("Make sure all produced", count, producer.messageCount());
        assertEquals("Make sure all intercepted", count, interceptor.messageCount());
        for (AdaptrisMessage m : producer.getMessages()) {
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 24 with AddMetadataService

use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.

the class StandardWorkflowTest method testObtainWorkflowIdWithUniqueId.

@Test
public void testObtainWorkflowIdWithUniqueId() throws Exception {
    MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    channel.setUniqueId("Channel");
    StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
    workflow.setUniqueId("Workflow");
    channel.prepare();
    assertEquals("Workflow@Channel", workflow.obtainWorkflowId());
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 25 with AddMetadataService

use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.

the class StandardWorkflowTest method testOnMessageWithoutEvents.

@Test
public void testOnMessageWithoutEvents() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    MockMessageProducer eventProd = new MockMessageProducer();
    DefaultEventHandler evtHandler = new DefaultEventHandler(eventProd);
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    try {
        channel.setEventHandler(evtHandler);
        StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
        workflow.setSendEvents(false);
        channel.prepare();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make sure all produced", 1, producer.getMessages().size());
        for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
            AdaptrisMessage m = (AdaptrisMessage) i.next();
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
        waitForMessages(eventProd, 0);
        assertEquals(0, eventProd.messageCount());
    } finally {
        stop(channel);
        stop(evtHandler);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) Iterator(java.util.Iterator) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Aggregations

AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)46 Test (org.junit.Test)35 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)22 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)20 MetadataElement (com.adaptris.core.MetadataElement)18 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)18 MockChannel (com.adaptris.core.stubs.MockChannel)18 ServiceList (com.adaptris.core.ServiceList)16 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)15 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)15 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)15 Service (com.adaptris.core.Service)10 Iterator (java.util.Iterator)10 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)9 StandaloneProducer (com.adaptris.core.StandaloneProducer)8 LogMessageService (com.adaptris.core.services.LogMessageService)7 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)6 Channel (com.adaptris.core.Channel)5 ArrayList (java.util.ArrayList)4 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)3