Search in sources :

Example 46 with ServiceException

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

the class RegexpMetadataServiceTest method testServiceNotAllowNulls.

@Test
public void testServiceNotAllowNulls() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
    RegexpMetadataService service = createService();
    execute(service, msg);
    try {
        msg.setContent(ALTERNATE_PAYLOAD, msg.getContentEncoding());
        execute(service, msg);
        fail("Expected serviceException");
    } catch (ServiceException expected) {
        ;
    }
    assertTrue("message contains key1", msg.containsKey("postcode"));
    assertEquals("Found the post-code", "UB3 5AN", msg.getMetadataValue("postcode"));
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 47 with ServiceException

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

the class MetadataToPayloadTest method testService_NoMetadata.

@Test
public void testService_NoMetadata() throws Exception {
    MetadataToPayloadService service = new MetadataToPayloadService("DoesNotExistKey", MetadataSource.Standard);
    AdaptrisMessage msg = createMessage(false);
    try {
        execute(service, msg);
        fail("Should fail with no key found");
    } catch (ServiceException ex) {
    // expected.
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 48 with ServiceException

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

the class PoolingMessageSplitterServiceTest method testServiceWithFailures.

@Test
public void testServiceWithFailures() throws Exception {
    PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new AlwaysFailService()).withWaitWhileBusy(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) Test(org.junit.Test)

Example 49 with ServiceException

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

the class ServiceExceptionHandlerTest method testThrowFirst.

@Test
@SuppressWarnings("deprecation")
public void testThrowFirst() throws Exception {
    ServiceExceptionHandler handler = new ServiceExceptionHandler();
    handler.uncaughtException(Thread.currentThread(), new ServiceException("first"));
    handler.uncaughtException(Thread.currentThread(), new ServiceException("second"));
    try {
        handler.throwFirstException();
        fail();
    } catch (ServiceException expected) {
        assertEquals("first", expected.getMessage());
        assertEquals(1, expected.getSuppressed().length);
    }
    assertNull(handler.getFirstThrowableException());
}
Also used : ServiceException(com.adaptris.core.ServiceException) Test(org.junit.Test)

Example 50 with ServiceException

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_NullEventHandler_SendEvents.

@Test
public void testDoServiceWithFailures_NullEventHandler_SendEvents() 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);
    service.setSendEvents(true);
    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)

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