Search in sources :

Example 16 with ServiceException

use of com.adaptris.core.ServiceException 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 17 with ServiceException

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

the class RetryingServiceWrapperTest method testFailsOnceNoRestarts.

@Test
public void testFailsOnceNoRestarts() throws Exception {
    // Fail once, then pass
    doThrow(new ServiceException("Expected fail.")).doNothing().when(wrappedService).doService(any(AdaptrisMessage.class));
    // now setup the retrying service wrapper;
    retryingServiceWrapper.setDelayBetweenRetries(new TimeInterval(1L, TimeUnit.SECONDS));
    retryingServiceWrapper.setNumRetries(3);
    retryingServiceWrapper.setService(wrappedService);
    retryingServiceWrapper.setRestartOnFailure(false);
    LifecycleHelper.init(retryingServiceWrapper);
    LifecycleHelper.start(retryingServiceWrapper);
    retryingServiceWrapper.doService(DefaultMessageFactory.getDefaultInstance().newMessage());
    verify(wrappedService, times(2)).doService(any(AdaptrisMessage.class));
    // init and start will be called once at RetryServiceWrapper init and start and then again on the restart.
    verify(wrappedService, times(1)).requestInit();
    verify(wrappedService, times(1)).requestStart();
}
Also used : ServiceException(com.adaptris.core.ServiceException) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 18 with ServiceException

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

the class DoWhileTest method testInnerServiceExceptionPropagated.

@Test
public void testInnerServiceExceptionPropagated() throws Exception {
    when(mockCondition.evaluate(message)).thenReturn(true);
    doThrow(new ServiceException()).when(mockService).doService(message);
    try {
        doWhile.doService(message);
        fail("Expected a service exception");
    } catch (ServiceException ex) {
    // expected.
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) Test(org.junit.Test)

Example 19 with ServiceException

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

the class ForEachTest method testBadThenService.

@Test
public void testBadThenService() throws Exception {
    doThrow(new ServiceException()).when(mock).doService(any(AdaptrisMessage.class));
    forEach.doService(message);
    verify(mock, times(2)).doService(any(AdaptrisMessage.class));
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 20 with ServiceException

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

the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId_NotFound.

@Test
public void testDoService_MimeServiceExtractor_ByContentId_NotFound() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Blah")));
    AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_BASE64);
    try {
        execute(dynamicService, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) SelectByContentId(com.adaptris.util.text.mime.SelectByContentId) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) 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