use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class DomainSingleResultHandlerTest method testHandle_NonUniqueResultException.
@Test
public void testHandle_NonUniqueResultException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("phoneNumber"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("01-2345-6789"));
resultSet.rows.add(new RowData("02-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());
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonUniqueResultException expected) {
}
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class EntityProviderTest method testGetEntity_EmptyUnknownColumnHandler.
@Test
public void testGetEntity_EmptyUnknownColumnHandler() 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 EmptyUnknownColumnHandlerConfig()), 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.RowData in project doma by domaframework.
the class EntityResultListHandlerTest 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();
EntityResultListHandler<Emp> handler = new EntityResultListHandler<>(_Emp.getSingletonInternal());
List<Emp> entities = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(2, entities.size());
Emp emp = entities.get(0);
assertEquals(new Integer(1), emp.getId());
assertEquals("aaa", emp.getName());
emp = entities.get(1);
assertEquals(new Integer(2), emp.getId());
assertEquals("bbb", emp.getName());
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class EntitySingleResultHandlerTest method testHandle_NonUniqueResultException.
@Test
public void testHandle_NonUniqueResultException() 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();
EntitySingleResultHandler<Emp> handler = new EntitySingleResultHandler<>(_Emp.getSingletonInternal());
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonUniqueResultException expected) {
}
}
use of org.seasar.doma.internal.jdbc.mock.RowData in project doma by domaframework.
the class ScalarProviderTest method testOptionalDomain.
@Test
public void testOptionalDomain() 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, Optional<PhoneNumber>> provider = new ScalarProvider<>(domainType::createOptionalScalar, new MySelectQuery());
Optional<PhoneNumber> result = provider.get(resultSet);
assertEquals("hoge", result.get().getValue());
}
Aggregations