use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class BuiltinSequenceIdGeneratorTest method test.
@Test
public void test() {
MockConfig config = new MockConfig();
config.setDialect(new PostgresDialect());
MockResultSet resultSet = config.dataSource.connection.preparedStatement.resultSet;
resultSet.rows.add(new RowData(11L));
BuiltinSequenceIdGenerator idGenerator = new BuiltinSequenceIdGenerator();
idGenerator.setQualifiedSequenceName("aaa");
idGenerator.setInitialValue(1);
idGenerator.setAllocationSize(1);
IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, _IdGeneratedEmp.getSingletonInternal());
Long value = idGenerator.generatePreInsert(idGenerationConfig);
assertEquals(new Long(11), value);
assertEquals("select nextval('aaa')", config.dataSource.connection.preparedStatement.sql);
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class BasicResultListHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("aaa"));
resultSet.rows.add(new RowData("bbb"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicResultListHandler<String> handler = new BasicResultListHandler<>(StringWrapper::new);
List<String> results = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(2, results.size());
assertEquals("aaa", results.get(0));
assertEquals("bbb", results.get(1));
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class BasicSingleResultHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("aaa"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicSingleResultHandler<String> handler = new BasicSingleResultHandler<>(StringWrapper::new);
String result = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals("aaa", result);
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class BasicSingleResultHandlerTest method testHandle_NonSingleColumnException.
@Test
public void testHandle_NonSingleColumnException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
metaData.columns.add(new ColumnMetaData("y"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("aaa", "bbb"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicSingleResultHandler<String> handler = new BasicSingleResultHandler<>(StringWrapper::new);
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonSingleColumnException ignore) {
}
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class DomainResultListHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("01-2345-6789"));
resultSet.rows.add(new RowData("12-3456-7890"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
DomainResultListHandler<String, PhoneNumber> handler = new DomainResultListHandler<>(_PhoneNumber.getSingletonInternal());
List<PhoneNumber> results = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(2, results.size());
assertEquals("01-2345-6789", results.get(0).getValue());
assertEquals("12-3456-7890", results.get(1).getValue());
}
Aggregations