Search in sources :

Example 1 with example.entity._Emp

use of example.entity._Emp 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 2 with example.entity._Emp

use of example.entity._Emp 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)

Example 3 with example.entity._Emp

use of example.entity._Emp 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());
}
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) 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

Emp (example.entity.Emp)3 example.entity._Emp (example.entity._Emp)3 BigDecimal (java.math.BigDecimal)3 Test (org.junit.jupiter.api.Test)3 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)3 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)3 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)3 RowData (org.seasar.doma.internal.jdbc.mock.RowData)3 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)2 UnknownColumnException (org.seasar.doma.jdbc.UnknownColumnException)1