Search in sources :

Example 31 with ServiceException

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));
}
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 32 with ServiceException

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;
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 33 with ServiceException

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());
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 34 with ServiceException

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
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MBeanException(javax.management.MBeanException) ServiceException(com.adaptris.core.ServiceException) MBeanException(javax.management.MBeanException) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 35 with ServiceException

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) {
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) 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