Search in sources :

Example 26 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_SendEventsFalse.

@Test
public void testDoServiceWithFailures_SendEventsFalse() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    DefaultEventHandler eh = new DefaultEventHandler();
    MockMessageProducer ehp = new MockMessageProducer();
    eh.setProducer(ehp);
    LifecycleHelper.initAndStart(eh);
    service.registerEventHandler(eh);
    service.setSendEvents(false);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
    LifecycleHelper.stopAndClose(eh);
    assertEvents(ehp, 0, MessageLifecycleEvent.class);
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 27 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures.

@Test
public void testDoServiceWithFailures() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 28 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_NullEventHandler.

@Test
public void testDoServiceWithFailures_NullEventHandler() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    service.registerEventHandler(null);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 29 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class SwitchTest method testService_Failure.

@Test
public void testService_Failure() throws Exception {
    Switch service = createForTests();
    service.getCases().add(new Case().withCondition(new CaseDefault()).withService(new ThrowExceptionService(new ConfiguredException("always-fail"))));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata("myKey", "17");
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) CaseDefault(com.adaptris.core.services.conditional.conditions.CaseDefault) Test(org.junit.Test)

Example 30 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class JmsTransactedWorkflowTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    Channel c = new Channel();
    try {
        c.setUniqueId(UUID.randomUUID().toString());
        c.setConsumeConnection(configure(new JmsConnection()));
        JmsTransactedWorkflow workflow = createWorkflow("Sample_Queue_1");
        workflow.setUniqueId(UUID.randomUUID().toString());
        workflow.setWaitPeriodAfterRollback(new TimeInterval(30L, TimeUnit.SECONDS.name()));
        workflow.getServiceCollection().addService(new WaitService());
        workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
        workflow.setProducer(new FsProducer().withBaseDirectoryUrl("file:////path/to/directory"));
        c.getWorkflowList().add(workflow);
    } catch (CoreException e) {
        throw new RuntimeException(e);
    }
    return c;
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) FsProducer(com.adaptris.core.fs.FsProducer) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException)

Aggregations

ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)45 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)45 Test (org.junit.Test)41 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)26 MockChannel (com.adaptris.core.stubs.MockChannel)18 StandaloneProducer (com.adaptris.core.StandaloneProducer)13 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)13 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)12 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)10 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)10 Channel (com.adaptris.core.Channel)8 ServiceException (com.adaptris.core.ServiceException)7 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)6 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)6 PtpProducer (com.adaptris.core.jms.PtpProducer)5 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)5 TimeInterval (com.adaptris.util.TimeInterval)5 Iterator (java.util.Iterator)5 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)4