Search in sources :

Example 21 with PayloadFromTemplateService

use of com.adaptris.core.services.metadata.PayloadFromTemplateService 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 22 with PayloadFromTemplateService

use of com.adaptris.core.services.metadata.PayloadFromTemplateService 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)

Example 23 with PayloadFromTemplateService

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

the class StandardWorkflowTest method testRuntimeException.

@Test
public void testRuntimeException() throws Exception {
    MockMessageProducer producer = new MockMessageProducer() {

        @Override
        protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
            throw new RuntimeException();
        }
    };
    MockMessageProducer meh = 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) }));
    try {
        StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
        channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
        channel.prepare();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make none produced", 0, producer.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        for (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
            AdaptrisMessage m = (AdaptrisMessage) i.next();
            assertEquals(PAYLOAD_1, m.getContent());
            assertFalse("Does not contains correct metadata key", m.containsKey(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) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Iterator(java.util.Iterator) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Test(org.junit.Test)

Example 24 with PayloadFromTemplateService

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

the class HttpHelper method createAndStartChannel.

public static Channel createAndStartChannel(MockMessageProducer mock, String replyPayload, HttpStatusProvider.HttpStatus status) throws Exception {
    JettyMessageConsumer mc = createConsumer(URL_TO_POST_TO);
    mc.setHeaderHandler(new MetadataHeaderHandler());
    HttpConnection jc = createConnection();
    Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList(new Service[] { new PayloadFromTemplateService().withTemplate(replyPayload), new StandaloneProducer(new StandardResponseProducer(status)) })));
    start(c);
    return c;
}
Also used : MetadataHeaderHandler(com.adaptris.core.http.jetty.MetadataHeaderHandler) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer)

Example 25 with PayloadFromTemplateService

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

the class HttpRequestServiceTest method testRequest_GetMethod_NonZeroBytes.

@Test
public void testRequest_GetMethod_NonZeroBytes() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList(new Service[] { new PayloadFromTemplateService().withTemplate(TEXT), new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)) })));
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("Hello World");
    try {
        start(c);
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        stop(c);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(TEXT, msg.getContent());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Aggregations

PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)43 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)42 Test (org.junit.Test)42 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)26 MockChannel (com.adaptris.core.stubs.MockChannel)26 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)23 StandaloneProducer (com.adaptris.core.StandaloneProducer)20 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)19 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)18 Channel (com.adaptris.core.Channel)17 ServiceList (com.adaptris.core.ServiceList)17 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)15 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)14 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)12 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)12 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)12 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)11 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)11 Iterator (java.util.Iterator)10 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)9