Search in sources :

Example 26 with ServiceException

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

the class ThrowExceptionServiceTest method testLastKnownExceptionAvailableException.

@Test
public void testLastKnownExceptionAvailableException() throws Exception {
    ThrowExceptionService service = new ThrowExceptionService(new LastKnownException());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.getObjectHeaders().put(CoreConstants.OBJ_METADATA_EXCEPTION, new ServiceException(CONFIGURED));
    try {
        execute(service, msg);
        fail("Expected Exception");
    } catch (ServiceException e) {
        assertEquals(CONFIGURED, e.getMessage());
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 27 with ServiceException

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

the class ThrowExceptionServiceTest method testExceptionFromMetadataConfiguredMessage.

@Test
public void testExceptionFromMetadataConfiguredMessage() throws Exception {
    ThrowExceptionService service = new ThrowExceptionService(new ExceptionFromMetadata(CONFIGURED));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    try {
        execute(service, msg);
        fail("Expected Exception");
    } catch (ServiceException e) {
        assertEquals(CONFIGURED, e.getMessage());
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 28 with ServiceException

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

the class ThrowExceptionServiceTest method testExceptionFromMetadataMetadataOverride.

@Test
public void testExceptionFromMetadataMetadataOverride() throws Exception {
    ThrowExceptionService service = new ThrowExceptionService(new ExceptionFromMetadata(CONFIGURED, METADATA_KEY));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(METADATA_KEY, METADATA_VALUE);
    try {
        execute(service, msg);
        fail("Expected Exception");
    } catch (ServiceException e) {
        assertEquals(METADATA_VALUE, e.getMessage());
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 29 with ServiceException

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

the class MetadataIdentitySequenceNumberServiceTest method test_Failure.

@Test
public void test_Failure() throws Exception {
    createDatabase();
    AdaptrisMessage msg = createMessageForTests();
    MetadataIdentitySequenceNumberService service = configureForTests(new MetadataIdentitySequenceNumberService() {

        @Override
        protected Connection getConnection(AdaptrisMessage msg) throws SQLException {
            throw new SQLException();
        }
    }, true);
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException ex) {
    // pass
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SQLException(java.sql.SQLException) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Connection(java.sql.Connection) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Test(org.junit.Test)

Example 30 with ServiceException

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

the class NamedParameterApplicatorTest method testParameterApplicatorServiceException.

@Test
public void testParameterApplicatorServiceException() throws Exception {
    doThrow(new SQLException("Expected")).when(mockStatement).setObject(anyInt(), anyString());
    try {
        parameterApplicator.applyStatementParameters(message, mockStatement, parameters, twoParamSqlStatement);
        fail("Should throw service exception.");
    } catch (ServiceException ex) {
    // expected
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) SQLException(java.sql.SQLException) 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