Search in sources :

Example 31 with ThrowExceptionService

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

the class StandardWorkflowTest method testServiceException.

@Test
public void testServiceException() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")) }));
    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));
            assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
            assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
            assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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) Test(org.junit.Test)

Example 32 with ThrowExceptionService

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

the class StandardWorkflowTest method testProduceException.

@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 ThrowExceptionService(new ConfiguredException("Fail")) }));
    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) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 33 with ThrowExceptionService

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

the class ThreadContextWorkflowTest method testProduceException.

@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 ThrowExceptionService(new ConfiguredException("Fail")) }));
    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);
        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) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 34 with ThrowExceptionService

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

the class StandardProcessingExceptionHandlerTest method testServiceListWithErrorWithServiceId.

@Test
public void testServiceListWithErrorWithServiceId() throws Exception {
    StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
    MockMessageProducer producer = new MockMessageProducer();
    try {
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX");
        ServiceList services = new ServiceList(Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Always Fail")), new StandaloneProducer(producer) }));
        services.setUniqueId("FailingServiceList");
        meh.setProcessingExceptionService(services);
        start(meh);
        meh.handleProcessingException(msg);
        assertTrue("Make sure none produced", producer.getMessages().size() == 0);
    } finally {
        stop(meh);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 35 with ThrowExceptionService

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

the class StandardProcessingExceptionHandlerTest method testMultipleErrorHandlers_AlwaysHandle_True.

@Test
public void testMultipleErrorHandlers_AlwaysHandle_True() throws Exception {
    MockMessageProducer aep = new MockMessageProducer();
    MockMessageProducer wep = new MockMessageProducer();
    MockMessageProducer cep = new MockMessageProducer();
    StandardProcessingExceptionHandler aeh = new StandardProcessingExceptionHandler(new StandaloneProducer(aep));
    aeh.setAlwaysHandleException(true);
    StandardProcessingExceptionHandler ceh = new StandardProcessingExceptionHandler(new StandaloneProducer(cep));
    ceh.setAlwaysHandleException(true);
    StandardProcessingExceptionHandler weh = new StandardProcessingExceptionHandler(new StandaloneProducer(wep));
    Adapter adapter = AdapterTest.createAdapter(getName());
    adapter.setMessageErrorHandler(aeh);
    MockMessageConsumer consumer = new MockMessageConsumer();
    adapter.getChannelList().clear();
    adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
    try {
        start(adapter);
        consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        assertEquals(1, aep.messageCount());
        assertEquals(1, cep.messageCount());
        assertEquals(1, wep.messageCount());
    } finally {
        stop(adapter);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

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