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());
}
}
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);
}
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));
}
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));
}
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) {
}
}
}
Aggregations