use of com.adaptris.core.ServiceException 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.ServiceException in project interlok by adaptris.
the class JdbcDataCaptureServiceCase method testServiceInvalidType.
@Test
public void testServiceInvalidType() throws Exception {
createDatabase();
JdbcIteratingDataCaptureServiceImpl service = createBasicService();
service.addStatementParameter(new StatementParameter(null, String.class, null));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_DOCUMENT);
msg.addMetadata(METADATA_KEY, METADATA_VALUE);
try {
execute(service, msg);
fail();
} catch (ServiceException e) {
assertNotNull(e.getCause());
assertEquals(IllegalArgumentException.class, e.getCause().getClass());
// expected service exception;
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class JdbcQueryServiceCase method testBug1762.
@Test
public void testBug1762() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createMetadataService();
ResultSetTranslator t = createTranslatorForConfig();
s.setResultSetTranslator(t);
AdaptrisMessage msg = createMessage(entry);
msg.setContent(STRING_PAYLOAD, msg.getContentEncoding());
try {
execute(s, msg);
assertFalse(msg.containsKey(JdbcDataQueryService.class.getCanonicalName()));
} catch (ServiceException e) {
log.error(e.getMessage(), e);
fail("Service Exception Thrown " + e.getMessage());
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class TestDynamicJmxOperationalService method testService_Mocked_InvokerException.
@Test
public void testService_Mocked_InvokerException() throws Exception {
when(mockInvoker.invoke((MBeanServerConnection) any(), anyString(), anyString(), any(Object[].class), any(String[].class))).thenThrow(new MBeanException(new Exception(), "Expected"));
DynamicJmxOperationService service = new DynamicJmxOperationService();
service.setInvoker(mockInvoker);
service.setObjectName(DEFAULT_OBJECTNAME);
service.setOperationName(DEFAULT_OPERATION);
try {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
execute(service, msg);
fail("Expect a service exception");
} catch (ServiceException ex) {
// expected
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class FormDataToMetadataTest method testService_Failure.
@Test
public void testService_Failure() throws Exception {
String payload = formatAsFormData(createProperties());
AdaptrisMessage msg = new DefectiveMessageFactory(WhenToBreak.METADATA_GET).newMessage(payload);
msg.addMetadata(Http.CONTENT_TYPE, "application/x-www-form-urlencoded");
FormDataToMetadata service = new FormDataToMetadata();
try {
execute(service, msg);
fail();
} catch (ServiceException expected) {
}
}
Aggregations