use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class ScalarProviderTest method testBasic.
@Test
public void testBasic() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("aaa"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("hoge"));
resultSet.next();
ScalarProvider<String, String> provider = new ScalarProvider<>(() -> new org.seasar.doma.internal.jdbc.scalar.BasicScalar<>(StringWrapper::new), new MySelectQuery());
String result = provider.get(resultSet);
assertEquals("hoge", result);
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class ScalarProviderTest method testOptionalBasic.
@Test
public void testOptionalBasic() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("aaa"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("hoge"));
resultSet.next();
ScalarProvider<String, Optional<String>> provider = new ScalarProvider<>(() -> new org.seasar.doma.internal.jdbc.scalar.OptionalBasicScalar<>(StringWrapper::new), new MySelectQuery());
Optional<String> result = provider.get(resultSet);
assertEquals("hoge", result.get());
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class ScalarProviderTest method testDomain.
@Test
public void testDomain() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("aaa"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("hoge"));
resultSet.next();
DomainType<String, PhoneNumber> domainType = _PhoneNumber.getSingletonInternal();
ScalarProvider<String, PhoneNumber> provider = new ScalarProvider<>(domainType::createScalar, new MySelectQuery());
PhoneNumber result = provider.get(resultSet);
assertEquals("hoge", result.getValue());
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class DomainSingleResultHandlerTest 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"));
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();
DomainSingleResultHandler<String, PhoneNumber> handler = new DomainSingleResultHandler<>(_PhoneNumber.getSingletonInternal());
PhoneNumber result = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals("01-2345-6789", result.getValue());
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class EntityIterationHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa"));
resultSet.rows.add(new RowData(2, "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();
EntityIterationHandler<Emp, Integer> handler = new EntityIterationHandler<>(_Emp.getSingletonInternal(), new IterationCallback<Emp, Integer>() {
private int count;
@Override
public Integer iterate(Emp target, IterationContext iterationContext) {
count++;
return count;
}
});
Integer result = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(new Integer(2), result);
}
Aggregations