Search in sources :

Example 6 with MockDataSource

use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.

the class LocalTransactionDataSourceTest method testGetConnection_notYetBegun.

@Test
public void testGetConnection_notYetBegun() {
    LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource());
    try {
        dataSource.getConnection();
        fail();
    } catch (TransactionNotYetBegunException expected) {
        System.out.println(expected.getMessage());
    }
}
Also used : MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) Test(org.junit.jupiter.api.Test)

Example 7 with MockDataSource

use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.

the class LocalTransactionDataSourceTest method testIsWrapperFor.

@Test
public void testIsWrapperFor() throws SQLException {
    DataSource dataSource = new LocalTransactionDataSource(new MockDataSource());
    assertTrue(dataSource.isWrapperFor(LocalTransactionDataSource.class));
    assertTrue(dataSource.isWrapperFor(MockDataSource.class));
    assertFalse(dataSource.isWrapperFor(Runnable.class));
}
Also used : MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) DataSource(javax.sql.DataSource) MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) Test(org.junit.jupiter.api.Test)

Example 8 with MockDataSource

use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.

the class LocalTransactionDataSourceTest method testGetConnection.

@Test
public void testGetConnection() {
    UtilLoggingJdbcLogger jdbcLogger = new UtilLoggingJdbcLogger();
    LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource());
    dataSource.getLocalTransaction(jdbcLogger).begin();
    dataSource.getConnection();
    dataSource.getLocalTransaction(jdbcLogger).commit();
}
Also used : MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) UtilLoggingJdbcLogger(org.seasar.doma.jdbc.UtilLoggingJdbcLogger) Test(org.junit.jupiter.api.Test)

Example 9 with MockDataSource

use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.

the class LocalTransactionTest method testBeginAndGetConnection_failedToSetAutoCommit.

@Test
public void testBeginAndGetConnection_failedToSetAutoCommit() {
    final SQLException exception = new SQLException();
    MockConnection connection = new MockConnection() {

        @Override
        public void setAutoCommit(boolean autoCommit) throws SQLException {
            throw exception;
        }
    };
    LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
    LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger);
    try {
        transaction.begin();
        dataSource.getConnection();
        fail();
    } catch (JdbcException expected) {
        System.out.println(expected.getMessage());
        assertEquals(exception, expected.getCause());
    }
}
Also used : SQLException(java.sql.SQLException) MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) MockConnection(org.seasar.doma.internal.jdbc.mock.MockConnection) JdbcException(org.seasar.doma.jdbc.JdbcException) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 MockDataSource (org.seasar.doma.internal.jdbc.mock.MockDataSource)9 SQLException (java.sql.SQLException)5 MockConnection (org.seasar.doma.internal.jdbc.mock.MockConnection)5 JdbcException (org.seasar.doma.jdbc.JdbcException)4 DataSource (javax.sql.DataSource)2 Connection (java.sql.Connection)1 LinkedList (java.util.LinkedList)1 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)1 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)1 RowData (org.seasar.doma.internal.jdbc.mock.RowData)1 UtilLoggingJdbcLogger (org.seasar.doma.jdbc.UtilLoggingJdbcLogger)1 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)1