Search in sources :

Example 36 with ThrowExceptionService

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

the class RetryMessageErrorHandlerTest method testMultipleErrorHandlers_AlwaysHandle_True.

@Test
public void testMultipleErrorHandlers_AlwaysHandle_True() throws Exception {
    MockMessageProducer aep = new MockMessageProducer();
    MockMessageProducer wep = new MockMessageProducer();
    MockMessageProducer cep = new MockMessageProducer();
    RetryMessageErrorHandler aeh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(aep));
    aeh.setAlwaysHandleException(true);
    RetryMessageErrorHandler ceh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(cep));
    ceh.setAlwaysHandleException(true);
    RetryMessageErrorHandler weh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, 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());
        waitForMessages(wep, 1, 1000);
        waitForMessages(cep, 1, 1000);
        waitForMessages(aep, 1, 1000);
        assertEquals(1, aep.messageCount());
        assertEquals(1, cep.messageCount());
        assertEquals(1, wep.messageCount());
    } finally {
        stop(adapter);
    }
}
Also used : 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) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 37 with ThrowExceptionService

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

the class RetryMessageErrorHandlerTest method testMultipleErrorHandlers_AlwaysHandle_False.

@Test
public void testMultipleErrorHandlers_AlwaysHandle_False() throws Exception {
    MockMessageProducer aep = new MockMessageProducer();
    MockMessageProducer wep = new MockMessageProducer();
    MockMessageProducer cep = new MockMessageProducer();
    RetryMessageErrorHandler aeh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(aep));
    aeh.setAlwaysHandleException(false);
    RetryMessageErrorHandler weh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(wep));
    RetryMessageErrorHandler ceh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(cep));
    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());
        waitForMessages(wep, 1, 1000);
        assertEquals(0, aep.messageCount());
        assertEquals(0, cep.messageCount());
        assertEquals(1, wep.messageCount());
    } finally {
        stop(adapter);
    }
}
Also used : 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) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 38 with ThrowExceptionService

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

the class SharedServiceTest method testDoService_WithFailure.

@Test
public void testDoService_WithFailure() throws Exception {
    ThrowExceptionService mockService = new ThrowExceptionService(getName(), new ConfiguredException("Fail"));
    SharedService sharedService = new SharedService(getName());
    Adapter adapter = createAdapterForSharedService(sharedService, mockService);
    AdaptrisMessage msg = DefaultMessageFactory.getDefaultInstance().newMessage();
    try {
        LifecycleHelper.initAndStart(adapter);
        sharedService.doService(msg);
        fail();
    } catch (ServiceException expected) {
        MleMarker marker = msg.getMessageLifecycleEvent().getMleMarkers().get(0);
        assertEquals(ThrowExceptionService.class.getName(), marker.getName());
        assertEquals(getName(), marker.getQualifier());
        assertEquals(false, marker.getWasSuccessful());
    } finally {
        LifecycleHelper.stopAndClose(adapter);
    }
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 39 with ThrowExceptionService

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

the class ServiceListTest method testFail_NestedServiceList_ObjectMetadata.

@Test
public void testFail_NestedServiceList_ObjectMetadata() throws Exception {
    ServiceList services = createServiceList(false);
    ThrowExceptionService errorService = new ThrowExceptionService(new ConfiguredException("Fail"));
    errorService.setUniqueId(getName());
    services.addService(new ServiceList(new Service[] { errorService }));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String expectedName = String.format("%s(%s)", ThrowExceptionService.class.getSimpleName(), getName());
    try {
        execute(services, msg);
        fail("Expected Service Exception");
    } catch (ServiceException e) {
        assertEquals("Fail", e.getMessage());
        Exception captured = (Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION);
        String problemComponent = (String) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE);
        assertNotNull(captured);
        assertEquals(captured, e);
        assertNotNull(problemComponent);
        assertEquals(expectedName, problemComponent);
    }
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 40 with ThrowExceptionService

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

the class ServiceListTest method testFailWithNoContinueOnFail.

@Test
public void testFailWithNoContinueOnFail() throws Exception {
    ServiceList services = createServiceList(false);
    services.addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    try {
        execute(services, msg);
        fail("Expected Service Exception");
    } catch (ServiceException e) {
        assertEquals("Fail", e.getMessage());
    }
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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