Search in sources :

Example 16 with PhoneNumber

use of example.domain.PhoneNumber 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());
}
Also used : Optional(java.util.Optional) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) RowData(org.seasar.doma.internal.jdbc.mock.RowData) PhoneNumber(example.domain.PhoneNumber) example.domain._PhoneNumber(example.domain._PhoneNumber) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 17 with PhoneNumber

use of example.domain.PhoneNumber in project doma by domaframework.

the class SelectBuilderTest method testSingleResult_Domain.

@Test
public void testSingleResult_Domain() {
    SelectBuilder builder = SelectBuilder.newInstance(new MockConfig());
    builder.sql("select ccc from Emp");
    builder.sql("where");
    builder.sql("aaa = ").param(String.class, "aaa");
    builder.sql("and");
    builder.sql("bbb = ").param(int.class, 100);
    PhoneNumber phoneNumber = builder.getScalarSingleResult(PhoneNumber.class);
    assertNull(phoneNumber);
}
Also used : PhoneNumber(example.domain.PhoneNumber) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Aggregations

PhoneNumber (example.domain.PhoneNumber)17 Test (org.junit.jupiter.api.Test)17 example.domain._PhoneNumber (example.domain._PhoneNumber)5 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)5 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)5 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)5 RowData (org.seasar.doma.internal.jdbc.mock.RowData)5 ClassHelper (org.seasar.doma.jdbc.ClassHelper)5 InternationalPhoneNumber (example.domain.InternationalPhoneNumber)4 Optional (java.util.Optional)4 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)4 SqlFileSelectQuery (org.seasar.doma.jdbc.query.SqlFileSelectQuery)3 Method (java.lang.reflect.Method)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TestInfo (org.junit.jupiter.api.TestInfo)2 SqlFileUtil (org.seasar.doma.internal.jdbc.util.SqlFileUtil)2 NonUniqueResultException (org.seasar.doma.jdbc.NonUniqueResultException)2 PreparedSql (org.seasar.doma.jdbc.PreparedSql)2 Reference (org.seasar.doma.jdbc.Reference)2