Search in sources :

Example 16 with AddMetadataService

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

the class ServiceListTest method createServiceList.

private ServiceList createServiceList(boolean assignId) {
    ServiceList services = createServiceCollection();
    services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY1, VAL1))));
    services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY2, VAL2))));
    if (assignId) {
        for (Service s : services) {
            s.setUniqueId(new PlainIdGenerator().create(s));
        }
    }
    return services;
}
Also used : PlainIdGenerator(com.adaptris.util.PlainIdGenerator) CheckComponentStateService(com.adaptris.core.stubs.CheckComponentStateService) MockStopProcessingService(com.adaptris.core.stubs.MockStopProcessingService) WaitService(com.adaptris.core.services.WaitService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService)

Example 17 with AddMetadataService

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

the class ServiceListTest method testFailWithContinueOnFail.

@Test
public void testFailWithContinueOnFail() throws Exception {
    ServiceList services = createServiceList(true);
    ThrowExceptionService service3 = new ThrowExceptionService(new ConfiguredException("Fail"));
    service3.setContinueOnFail(true);
    services.addService(service3);
    services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY4, VAL4))));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    execute(services, msg);
    assertTrue(msg.getMetadataValue(KEY4).equals(VAL4));
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 18 with AddMetadataService

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

the class ServiceListTest method testAddService.

@Override
public void testAddService() {
    ServiceList services = createServiceList(false);
    AddMetadataService newService = new AddMetadataService(Arrays.asList(new MetadataElement(KEY3, VAL3)));
    services.addService(newService);
    Collection tmp = services.getServices();
    assertTrue(tmp.contains(newService));
}
Also used : Collection(java.util.Collection) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService)

Example 19 with AddMetadataService

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

the class ThreadContextWorkflowTest method testBrokenPool.

@Test
public void testBrokenPool() 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) }));
    MockMessageProducer meh = new MockMessageProducer();
    try {
        ThreadContextWorkflow workflow = (ThreadContextWorkflow) 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);
        // close the pool which should cause an IllegalStateException
        workflow.getObjectPool().close();
        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.headersContainsKey(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) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) 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) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Iterator(java.util.Iterator) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Test(org.junit.Test)

Example 20 with AddMetadataService

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

the class ThreadContextWorkflowTest 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 {
        ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
        workflow.setAdditionalDebug(Boolean.TRUE);
        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.headersContainsKey(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) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) 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) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) 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