Search in sources :

Example 26 with AddMetadataService

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

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

the class StandardProcessingExceptionHandlerTest method testServiceListWithAddMetadata.

@Test
public void testServiceListWithAddMetadata() throws Exception {
    StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
    MockMessageProducer producer = new MockMessageProducer();
    try {
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX");
        meh.setProcessingExceptionService(new ServiceList(Arrays.asList(new Service[] { new StandaloneProducer(producer), new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("myKey", "myValue") })), new StandaloneProducer(producer) })));
        start(meh);
        meh.handleProcessingException(msg);
        log.debug("Number of messages " + producer.getMessages().size());
        assertTrue("Make sure all produced", producer.getMessages().size() == 2);
        assertTrue(producer.getMessages().get(1).containsKey("myKey"));
        assertEquals("myValue", producer.getMessages().get(1).getMetadataValue("myKey"));
    } finally {
        stop(meh);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 28 with AddMetadataService

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

the class BranchingServiceCollectionTest method setUp.

@Before
public void setUp() throws Exception {
    branchService = new TestBranchingService();
    branchService.setUniqueId(FIRST_SERVICE_ID);
    lowService = new AddMetadataService();
    lowService.setUniqueId(BRANCH_LOW);
    lowService.addMetadataElement("service-id", BRANCH_LOW);
    highService = new AddMetadataService();
    highService.setUniqueId(BRANCH_HIGH);
    highService.addMetadataElement("service-id", BRANCH_HIGH);
    openMocks = MockitoAnnotations.openMocks(this);
}
Also used : TestBranchingService(com.adaptris.core.stubs.TestBranchingService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Before(org.junit.Before)

Example 29 with AddMetadataService

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

the class CloneMessageServiceListTest method createServiceList.

private CloneMessageServiceList createServiceList() {
    CloneMessageServiceList services = createServiceCollection();
    services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY1, VAL1))));
    return services;
}
Also used : AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService)

Example 30 with AddMetadataService

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

the class LargeMessageWorkflowTest method testRuntimeException.

@Override
@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 {
        LargeMessageWorkflow workflow = (LargeMessageWorkflow) 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 (AdaptrisMessage m : meh.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) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Service(com.adaptris.core.Service) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) StandardWorkflowTest(com.adaptris.core.StandardWorkflowTest)

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