use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class EntityIterationHandlerTest method testHandle_exits.
@Test
public void testHandle_exits() 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) {
iterationContext.exit();
count++;
return count;
}
});
Integer result = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(new Integer(1), result);
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class EntityProviderTest method testGetEntity.
@Test
public void testGetEntity() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
metaData.columns.add(new ColumnMetaData("salary"));
metaData.columns.add(new ColumnMetaData("version"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100));
resultSet.next();
_Emp entityType = _Emp.getSingletonInternal();
EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
Emp emp = provider.get(resultSet);
assertEquals(1, emp.getId());
assertEquals("aaa", emp.getName());
assertEquals(new BigDecimal(10), emp.getSalary());
assertEquals(100, emp.getVersion());
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class EntityProviderTest method testGetEntity_UnknownColumnException.
@Test
public void testGetEntity_UnknownColumnException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
metaData.columns.add(new ColumnMetaData("salary"));
metaData.columns.add(new ColumnMetaData("version"));
metaData.columns.add(new ColumnMetaData("unknown"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100, "bbb"));
resultSet.next();
_Emp entityType = _Emp.getSingletonInternal();
EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
try {
provider.get(resultSet);
fail();
} catch (UnknownColumnException expected) {
}
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class EntitySingleResultHandlerTest 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"));
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();
EntitySingleResultHandler<Emp> handler = new EntitySingleResultHandler<>(_Emp.getSingletonInternal());
Emp emp = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(1, emp.getId());
assertEquals("aaa", emp.getName());
}
use of org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData in project doma by domaframework.
the class BasicResultListHandlerTest 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.setResultEnsured(true);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicResultListHandler<String> handler = new BasicResultListHandler<>(StringWrapper::new);
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonSingleColumnException expected) {
}
}
Aggregations