Search in sources :

Example 26 with CoreException

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

the class CheckCacheServiceTest method testDoService_Error.

@Test
public void testDoService_Error() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = new KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
    CheckCacheService service = new CheckCacheService() {

        @Override
        protected boolean eval(AdaptrisMessage msg, FoundInCache callback) throws CoreException {
            throw new CoreException();
        }
    };
    try {
        service.withConnection(new CacheConnection().withCacheInstance(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 27 with CoreException

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

the class ClearCacheServiceTest method testDoService_Exception.

@Test(expected = ServiceException.class)
public void testDoService_Exception() throws Exception {
    Cache mockCache = Mockito.mock(Cache.class);
    Mockito.doThrow(new CoreException()).when(mockCache).clear();
    CacheConnection cache = new CacheConnection(mockCache);
    ClearCacheService service = new ClearCacheService().withIgnoreUnsupported(true).withConnection(cache);
    ExampleServiceCase.execute(service, AdaptrisMessageFactory.getDefaultInstance().newMessage());
}
Also used : CoreException(com.adaptris.core.CoreException) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 28 with CoreException

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

the class XmlAggregatorCase method testJoinMessage_Fails.

@Test
public void testJoinMessage_Fails() throws Exception {
    XmlDocumentAggregator aggr = createAggregatorForTests();
    aggr.setMergeImplementation(new InsertNode(XPATH_ENVELOPE));
    AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>");
    AdaptrisMessage splitMsg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>");
    AdaptrisMessage splitMsg2 = new DefectiveMessageFactory().newMessage("<document>world</document>");
    try {
        aggr.joinMessage(original, Arrays.asList(new AdaptrisMessage[] { splitMsg1, splitMsg2 }));
        fail();
    } catch (CoreException expected) {
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 29 with CoreException

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

the class StatelessServiceWrapperTest method testServiceThatFailsToStart.

@Test
public void testServiceThatFailsToStart() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC");
    StatelessServiceWrapper service = new StatelessServiceWrapper(new NullService() {

        @Override
        public void start() throws CoreException {
            throw new CoreException("testServiceThatFailsToStart");
        }
    });
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException e) {
        assertNotNull(e.getCause());
        assertEquals(CoreException.class, e.getCause().getClass());
        assertEquals("testServiceThatFailsToStart", e.getCause().getMessage());
    }
}
Also used : CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Example 30 with CoreException

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

the class ReadFileServiceTest method testServiceFailedInit.

@Test
public void testServiceFailedInit() throws Exception {
    try {
        final AdaptrisMessage message = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        final ReadFileService service = new ReadFileService();
        execute(service, message);
        fail();
    } catch (@SuppressWarnings("unused") final CoreException expected) {
    /* expected result */
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

CoreException (com.adaptris.core.CoreException)186 Test (org.junit.Test)110 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)44 Adapter (com.adaptris.core.Adapter)32 ObjectName (javax.management.ObjectName)29 Channel (com.adaptris.core.Channel)27 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)20 File (java.io.File)19 ServiceException (com.adaptris.core.ServiceException)14 TimeInterval (com.adaptris.util.TimeInterval)13 Document (org.w3c.dom.Document)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)10 StandardWorkflow (com.adaptris.core.StandardWorkflow)9 URLString (com.adaptris.util.URLString)9 TimeoutException (java.util.concurrent.TimeoutException)9 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)8 Workflow (com.adaptris.core.Workflow)8 XPath (com.adaptris.util.text.xml.XPath)8