use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.
the class BuiltinTableIdGeneratorTest method test.
@Test
public void test() {
MockConfig config = new MockConfig();
config.setDialect(new PostgresDialect());
MockConnection connection = new MockConnection();
MockConnection connection2 = new MockConnection();
MockResultSet resultSet2 = connection2.preparedStatement.resultSet;
resultSet2.rows.add(new RowData(11L));
final LinkedList<MockConnection> connections = new LinkedList<>();
connections.add(connection);
connections.add(connection2);
config.dataSource = new MockDataSource() {
@Override
public Connection getConnection() {
return connections.pop();
}
};
BuiltinTableIdGenerator idGenerator = new BuiltinTableIdGenerator();
idGenerator.setQualifiedTableName("aaa");
idGenerator.setPkColumnName("PK");
idGenerator.setPkColumnValue("EMP_ID");
idGenerator.setValueColumnName("VALUE");
idGenerator.setInitialValue(1);
idGenerator.setAllocationSize(1);
idGenerator.initialize();
IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, _IdGeneratedEmp.getSingletonInternal());
Long value = idGenerator.generatePreInsert(idGenerationConfig);
assertEquals(new Long(10), value);
assertEquals("update aaa set VALUE = VALUE + ? where PK = ?", connection.preparedStatement.sql);
assertEquals(2, connection.preparedStatement.bindValues.size());
assertEquals("select VALUE from aaa where PK = ?", connection2.preparedStatement.sql);
assertEquals(1, connection2.preparedStatement.bindValues.size());
}
use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.
the class KeepAliveLocalTransactionTest method testBegin_failedToSetTransactionIsolation.
@Test
public void testBegin_failedToSetTransactionIsolation() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getKeepAliveLocalTransaction(jdbcLogger);
try {
transaction.begin(TransactionIsolationLevel.READ_COMMITTED);
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.
the class LocalTransactionDataSourceTest method testUnwrap.
@Test
public void testUnwrap() throws SQLException {
DataSource dataSource = new LocalTransactionDataSource(new MockDataSource());
assertNotNull(dataSource.unwrap(LocalTransactionDataSource.class));
assertNotNull(dataSource.unwrap(MockDataSource.class));
try {
dataSource.unwrap(Runnable.class);
fail();
} catch (SQLException ignored) {
}
}
use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.
the class LocalTransactionTest method testBegin_failedToSetTransactionIsolation.
@Test
public void testBegin_failedToSetTransactionIsolation() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger);
try {
transaction.begin(TransactionIsolationLevel.READ_COMMITTED);
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
use of org.seasar.doma.internal.jdbc.mock.MockDataSource in project doma by domaframework.
the class KeepAliveLocalTransactionTest method testBegin_failedToBegin.
@Test
public void testBegin_failedToBegin() {
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.getKeepAliveLocalTransaction(jdbcLogger);
try {
transaction.begin();
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
Aggregations