Search in sources :

Example 1 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection 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 2 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testConnectionWhenStarted.

@Test
public void testConnectionWhenStarted() throws Exception {
    DatabaseConnection con = configure(createConnection());
    LifecycleHelper.init(con);
    LifecycleHelper.start(con);
    con.connect();
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 3 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testEquality.

@Test
public void testEquality() throws Exception {
    DatabaseConnection conn1 = configure(createConnection());
    DatabaseConnection conn2 = roundTrip(conn1, DefaultMarshaller.getDefaultMarshaller());
    assertRoundtripEquality(conn1, conn2);
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 4 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testConnectWithAlwaysValidate.

@Test
public void testConnectWithAlwaysValidate() throws Exception {
    DatabaseConnection conn = configure(createConnection());
    conn.setAlwaysValidateConnection(true);
    LifecycleHelper.init(conn);
    conn.connect();
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 5 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testConnectionWhenClosed.

@Test
public void testConnectionWhenClosed() throws Exception {
    DatabaseConnection con = configure(createConnection());
    LifecycleHelper.init(con);
    LifecycleHelper.start(con);
    LifecycleHelper.stop(con);
    LifecycleHelper.close(con);
    try {
        con.connect();
        fail("Expected failure as not initialised");
    } catch (Exception e) {
        // Expected
        ;
    }
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Aggregations

DatabaseConnection (com.adaptris.core.jdbc.DatabaseConnection)20 Test (org.junit.Test)20 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)3 JdbcConnection (com.adaptris.core.jdbc.JdbcConnection)3 JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)3 Connection (java.sql.Connection)3 NullService (com.adaptris.core.NullService)2 ServiceException (com.adaptris.core.ServiceException)2 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)1 TimeInterval (com.adaptris.util.TimeInterval)1