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());
}
}
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));
}
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();
}
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());
}
}
Aggregations