use of org.seasar.doma.internal.jdbc.mock.ColumnMetaData in project doma by domaframework.
the class BasicSingleResultHandlerTest method testHandle_NonUniqueResultException.
@Test
public void testHandle_NonUniqueResultException() 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();
BasicSingleResultHandler<String> handler = new BasicSingleResultHandler<>(StringWrapper::new);
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonUniqueResultException ignore) {
}
}
use of org.seasar.doma.internal.jdbc.mock.ColumnMetaData in project doma by domaframework.
the class SelectCommandTest method testExecute_NoResultException.
@Test
public void testExecute_NoResultException() 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);
runtimeConfig.dataSource.connection = new MockConnection(new MockPreparedStatement(resultSet));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.addParameter("name", String.class, "hoge");
query.addParameter("salary", BigDecimal.class, new BigDecimal(10000));
query.setMethod(getClass().getMethod(method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setResultEnsured(true);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
SelectCommand<Emp> command = new SelectCommand<>(query, new EntitySingleResultHandler<>(_Emp.getSingletonInternal()));
try {
command.execute();
fail();
} catch (Exception expected) {
}
}
use of org.seasar.doma.internal.jdbc.mock.ColumnMetaData in project doma by domaframework.
the class SelectCommandTest method testExecute_singleResult.
@Test
public void testExecute_singleResult() 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, "hoge", new BigDecimal(10000), 100));
runtimeConfig.dataSource.connection = new MockConnection(new MockPreparedStatement(resultSet));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.addParameter("name", String.class, "hoge");
query.addParameter("salary", BigDecimal.class, new BigDecimal(10000));
query.setMethod(getClass().getMethod(method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
SelectCommand<Emp> command = new SelectCommand<>(query, new EntitySingleResultHandler<>(_Emp.getSingletonInternal()));
Emp entity = command.execute();
query.complete();
assertNotNull(entity);
assertEquals(new Integer(1), entity.getId());
assertEquals("hoge", entity.getName());
assertEquals(new BigDecimal(10000), entity.getSalary());
assertEquals(new Integer(100), entity.getVersion());
List<BindValue> bindValues = runtimeConfig.dataSource.connection.preparedStatement.bindValues;
BindValue bindValue = bindValues.get(0);
assertEquals("hoge", bindValue.getValue());
assertEquals(1, bindValue.getIndex());
bindValue = bindValues.get(1);
assertEquals(new BigDecimal(10000), bindValue.getValue());
assertEquals(2, bindValue.getIndex());
}
use of org.seasar.doma.internal.jdbc.mock.ColumnMetaData 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.ColumnMetaData 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);
}
Aggregations