Search in sources :

Example 6 with RowData

use of org.seasar.doma.internal.jdbc.mock.RowData 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());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) SqlFileUtil(org.seasar.doma.internal.jdbc.util.SqlFileUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) PhoneNumber(example.domain.PhoneNumber) example.domain._PhoneNumber(example.domain._PhoneNumber) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) NonUniqueResultException(org.seasar.doma.jdbc.NonUniqueResultException) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Method(java.lang.reflect.Method) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) PhoneNumber(example.domain.PhoneNumber) example.domain._PhoneNumber(example.domain._PhoneNumber) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 7 with RowData

use of org.seasar.doma.internal.jdbc.mock.RowData 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);
}
Also used : SqlFileUtil(org.seasar.doma.internal.jdbc.util.SqlFileUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) Emp(example.entity.Emp) IterationCallback(org.seasar.doma.jdbc.IterationCallback) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) IterationContext(org.seasar.doma.jdbc.IterationContext) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) example.entity._Emp(example.entity._Emp) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Method(java.lang.reflect.Method) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) RowData(org.seasar.doma.internal.jdbc.mock.RowData) IterationContext(org.seasar.doma.jdbc.IterationContext) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 8 with RowData

use of org.seasar.doma.internal.jdbc.mock.RowData 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);
}
Also used : SqlFileUtil(org.seasar.doma.internal.jdbc.util.SqlFileUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) Emp(example.entity.Emp) IterationCallback(org.seasar.doma.jdbc.IterationCallback) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) IterationContext(org.seasar.doma.jdbc.IterationContext) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) example.entity._Emp(example.entity._Emp) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Method(java.lang.reflect.Method) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) RowData(org.seasar.doma.internal.jdbc.mock.RowData) IterationContext(org.seasar.doma.jdbc.IterationContext) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 9 with RowData

use of org.seasar.doma.internal.jdbc.mock.RowData 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());
}
Also used : RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) example.entity._Emp(example.entity._Emp) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 10 with RowData

use of org.seasar.doma.internal.jdbc.mock.RowData 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) {
    }
}
Also used : UnknownColumnException(org.seasar.doma.jdbc.UnknownColumnException) RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) example.entity._Emp(example.entity._Emp) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)27 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)27 RowData (org.seasar.doma.internal.jdbc.mock.RowData)27 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)23 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)23 SqlFileSelectQuery (org.seasar.doma.jdbc.query.SqlFileSelectQuery)16 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)14 Emp (example.entity.Emp)11 example.entity._Emp (example.entity._Emp)11 Method (java.lang.reflect.Method)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 TestInfo (org.junit.jupiter.api.TestInfo)8 SqlFileUtil (org.seasar.doma.internal.jdbc.util.SqlFileUtil)8 SqlLogType (org.seasar.doma.jdbc.SqlLogType)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 BigDecimal (java.math.BigDecimal)6 NonUniqueResultException (org.seasar.doma.jdbc.NonUniqueResultException)6 PhoneNumber (example.domain.PhoneNumber)5 example.domain._PhoneNumber (example.domain._PhoneNumber)5 StringWrapper (org.seasar.doma.wrapper.StringWrapper)5