Search in sources :

Example 6 with Service

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

the class LargeMessageWorkflowTest method testProduceException.

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

        @Override
        protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
            throw new ProduceException();
        }
    };
    ;
    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) ProduceException(com.adaptris.core.ProduceException) 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)

Example 7 with Service

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

the class StatelessServiceWrapperTest method testWrappedServiceCreateName.

@Test
public void testWrappedServiceCreateName() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
    MockMessageProducer prod = new MockMessageProducer();
    Service s = create(prod);
    assertNotSame(StatelessServiceWrapper.class.getName(), s.createName());
    assertEquals(MockMessageProducer.class.getName(), s.createName());
    StatelessServiceWrapper sw = new StatelessServiceWrapper();
    assertEquals(StatelessServiceWrapper.class.getName(), sw.createName());
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExampleBranchingService(com.adaptris.core.stubs.ExampleBranchingService) NullService(com.adaptris.core.NullService) Service(com.adaptris.core.Service) Test(org.junit.Test)

Example 8 with Service

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

the class DoWhileTest method testStopProcessingServiceCancelsLoop.

@Test
public void testStopProcessingServiceCancelsLoop() throws Exception {
    when(mockCondition.evaluate(message)).thenReturn(true);
    Service stopProcessingService = new StopProcessingService();
    ServiceList services = new ServiceList();
    services.add(stopProcessingService);
    services.add(mockService);
    thenService = new ThenService();
    thenService.setService(services);
    doWhile = new DoWhile().withThen(thenService).withCondition(mockCondition);
    LifecycleHelper.init(doWhile);
    LifecycleHelper.start(doWhile);
    doWhile.doService(message);
    // The default would loop 10 times, but the stop-processing-service should
    // limit us to only a single loop and the condition will never be tested.
    verify(mockCondition, times(0)).evaluate(message);
}
Also used : ServiceList(com.adaptris.core.ServiceList) StopProcessingService(com.adaptris.core.services.StopProcessingService) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) StopProcessingService(com.adaptris.core.services.StopProcessingService) Test(org.junit.Test)

Example 9 with Service

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

the class DynamicServiceExecutorTest method testDoService_DefaultServiceExtractor_WithMarshaller.

@Test
public void testDoService_DefaultServiceExtractor_WithMarshaller() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setMarshaller(new XStreamMarshaller());
    AdaptrisMessage msg = createMessage(new ServiceList(new Service[] { metadataService }));
    execute(dynamicService, msg);
    assertEquals(getName(), msg.getMetadataValue(getName()));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 10 with Service

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

the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId_NotFound.

@Test
public void testDoService_MimeServiceExtractor_ByContentId_NotFound() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Blah")));
    AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_BASE64);
    try {
        execute(dynamicService, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) SelectByContentId(com.adaptris.util.text.mime.SelectByContentId) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Aggregations

Service (com.adaptris.core.Service)49 Test (org.junit.Test)38 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)28 ServiceList (com.adaptris.core.ServiceList)16 ArrayList (java.util.ArrayList)16 ComponentLifecycle (com.adaptris.core.ComponentLifecycle)14 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)12 PooledConnectionHelper (com.adaptris.core.jdbc.PooledConnectionHelper)12 ServiceException (com.adaptris.core.ServiceException)11 MetadataElement (com.adaptris.core.MetadataElement)10 NullService (com.adaptris.core.NullService)10 StandaloneProducer (com.adaptris.core.StandaloneProducer)10 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)10 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 LogMessageService (com.adaptris.core.services.LogMessageService)8 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)7 MockChannel (com.adaptris.core.stubs.MockChannel)7 StandardProcessingExceptionHandler (com.adaptris.core.StandardProcessingExceptionHandler)6 JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)6 GuidGenerator (com.adaptris.util.GuidGenerator)6