Search in sources :

Example 11 with NullService

use of com.adaptris.core.NullService 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 12 with NullService

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

the class IfElseTest method testNoElseService.

@Test
public void testNoElseService() throws Exception {
    logicalExpression.getOtherwise().setService(new NullService());
    when(mockCondition.evaluate(message)).thenReturn(true);
    // purely to re-initiate the NoOpService
    LifecycleHelper.stopAndClose(logicalExpression);
    LifecycleHelper.initAndStart(logicalExpression);
    logicalExpression.doService(message);
    verify(mockService, times(1)).doService(message);
}
Also used : NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Example 13 with NullService

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

the class JdbcServiceListTest method testServiceList_RuntimeExceptionRollsback.

@Test
public void testServiceList_RuntimeExceptionRollsback() throws Exception {
    createDatabase();
    JdbcServiceList service = createServiceCollection();
    DatabaseConnection c = createJdbcConnection();
    c.setAutoCommit(false);
    service.setConnection(c);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    service.add(createSequenceNumberService(null, getName(), SequenceNumberCase.DEFAULT_ID));
    service.add(new NullService() {

        @Override
        public void doService(AdaptrisMessage msg) throws ServiceException {
            throw new RuntimeException("testServiceList_RuntimeExceptionRollsback");
        }
    });
    try {
        execute(service, msg);
    } catch (ServiceException expected) {
    }
    assertTrue(msg.getObjectHeaders().containsKey(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY));
    Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY);
    assertTrue(conn.isClosed());
    // Here, we will expect there to be in row inserted.
    // getCurrentSequenceNumber returns -1 in that instance, C-Styley
    assertEquals(-1, getCurrentSequenceNumber(SequenceNumberCase.DEFAULT_ID));
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NullService(com.adaptris.core.NullService) Connection(java.sql.Connection) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 14 with NullService

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

the class ServiceUtilTest method testRewriteForTesting_NoConnection.

@Test
public void testRewriteForTesting_NoConnection() throws Exception {
    NullService nullService = new NullService();
    JdbcServiceList jdbcService = new JdbcServiceList();
    StatelessServiceWrapper stateless = new StatelessServiceWrapper(new StandaloneProducer());
    assertTrue(nullService == rewriteConnectionsForTesting(nullService));
    assertTrue(jdbcService == rewriteConnectionsForTesting(jdbcService));
    assertTrue(stateless == rewriteConnectionsForTesting(stateless));
    ServiceList nestedList = new ServiceList();
    ServiceList list = new ServiceList();
    list.add(nestedList);
    assertTrue(list == rewriteConnectionsForTesting(list));
}
Also used : ServiceList(com.adaptris.core.ServiceList) JdbcServiceList(com.adaptris.core.services.jdbc.JdbcServiceList) NullService(com.adaptris.core.NullService) JdbcServiceList(com.adaptris.core.services.jdbc.JdbcServiceList) StatelessServiceWrapper(com.adaptris.core.services.StatelessServiceWrapper) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 15 with NullService

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

the class UnmodifiableListIteratorTest method testIteratorIsReadOnly.

@Test
public void testIteratorIsReadOnly() {
    ListContainer list = new ListContainer();
    list.add(new NullService(UUID.randomUUID().toString()));
    list.add(new NullService(UUID.randomUUID().toString()));
    list.add(new NullService(UUID.randomUUID().toString()));
    list.add(new NullService(UUID.randomUUID().toString()));
    list.add(new NullService(UUID.randomUUID().toString()));
    int count = 0;
    for (ListIterator<NullService> i = list.listIterator(); i.hasNext(); ) {
        switch(count) {
            case 0:
                {
                    assertEquals(-1, i.previousIndex());
                    assertFalse(i.hasPrevious());
                    assertTrue(i.hasNext());
                    break;
                }
            case 5:
                {
                    assertEquals(5, i.nextIndex());
                    assertTrue(i.hasPrevious());
                    assertFalse(i.hasNext());
                    break;
                }
            default:
                {
                    assertEquals(count, i.nextIndex());
                    assertNotNull(i.previous());
                    assertNotNull(i.next());
                    assertTrue(i.hasPrevious());
                    assertTrue(i.hasNext());
                }
        }
        i.next();
        count++;
        try {
            i.remove();
            fail();
        } catch (UnsupportedOperationException e) {
        }
        try {
            i.add(new NullService());
            fail();
        } catch (UnsupportedOperationException e) {
        }
        try {
            i.set(new NullService());
            fail();
        } catch (UnsupportedOperationException e) {
        }
    }
}
Also used : NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Aggregations

NullService (com.adaptris.core.NullService)54 Test (org.junit.Test)53 ServiceCollectionImp (com.adaptris.core.ServiceCollectionImp)16 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)15 WaitService (com.adaptris.core.services.WaitService)9 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)9 TimeInterval (com.adaptris.util.TimeInterval)9 Service (com.adaptris.core.Service)5 XpathMessageSplitter (com.adaptris.core.services.splitter.XpathMessageSplitter)5 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)5 InsertNode (com.adaptris.util.text.xml.InsertNode)5 XPath (com.adaptris.util.text.xml.XPath)5 Adapter (com.adaptris.core.Adapter)4 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)4 ServiceException (com.adaptris.core.ServiceException)4 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)4 BodyPartIterator (com.adaptris.util.text.mime.BodyPartIterator)4 ObjectName (javax.management.ObjectName)4 SharedService (com.adaptris.core.SharedService)3 ComponentLifecycle (com.adaptris.core.ComponentLifecycle)2