Search in sources :

Example 51 with ServiceException

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_SendEventsTrue.

@Test
public void testDoServiceWithFailures_SendEventsTrue() 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(true);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
    LifecycleHelper.stopAndClose(eh);
    assertEvents(ehp, 1, 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 52 with ServiceException

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

the class MultipartMessageBuilderTest method testService_Exception.

@Test
public void testService_Exception() throws Exception {
    AdaptrisMessage msg = new DefectiveMessageFactory(WhenToBreak.OUTPUT).newMessage("Hello World");
    MultipartMessageBuilder service = new MultipartMessageBuilder().withMimeParts(new InlineMimePartBuilder());
    try {
        ExampleServiceCase.execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 53 with ServiceException

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

the class RegexpServiceTest method testService_Exception.

@Test
public void testService_Exception() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ALTERNATE_PAYLOAD);
    RegexpService s = new RegexpService();
    s.getExecutions().add(new Execution(new DodgyInputParameter(), new MetadataDataOutputParameter(TARGET_METADATA_KEY)));
    try {
        execute(s, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : Execution(com.adaptris.core.common.Execution) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) Test(org.junit.Test)

Example 54 with ServiceException

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

the class SyntaxRoutingServiceTest method testDoServiceNoMatch.

@Test
public void testDoServiceNoMatch() throws Exception {
    SyntaxRoutingService service = new SyntaxRoutingService();
    service.setRoutingKey(ROUTING_KEY);
    service.setSyntaxIdentifiers(createStandardIdentifiers());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("The quick brown fox");
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException e) {
        assertEquals("Unable to identify the message syntax for routing", e.getMessage());
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 55 with ServiceException

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

the class MetadataComparisonServiceTest method testCompareTimestamp_Fails.

@Test
public void testCompareTimestamp_Fails() throws Exception {
    MetadataComparisonService s = new MetadataComparisonService(KEY_1, KEY_2, new CompareTimestamps());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    msg.addMetadata(KEY_1, sdf.format(new Date(1)));
    msg.addMetadata(KEY_2, sdf.format(new Date()));
    try {
        execute(s, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7