Search in sources :

Example 6 with PhoneNumber

use of example.domain.PhoneNumber 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 PhoneNumber

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

the class SelectBuilderTest method testGetResultList_Domain.

@Test
public void testGetResultList_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);
    List<PhoneNumber> list = builder.getScalarResultList(PhoneNumber.class);
    assertNotNull(list);
}
Also used : PhoneNumber(example.domain.PhoneNumber) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 8 with PhoneNumber

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

the class ScalarInOutParameterTest method testGetDomainClass.

@Test
public void testGetDomainClass() {
    DomainType<String, PhoneNumber> domainType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
    });
    Scalar<String, PhoneNumber> scalar = domainType.createScalar();
    Reference<PhoneNumber> ref = new Reference<>();
    ScalarInOutParameter<String, PhoneNumber> parameter = new ScalarInOutParameter<>(scalar, ref);
    Optional<Class<?>> optional = parameter.getDomainClass();
    assertEquals(PhoneNumber.class, optional.get());
}
Also used : ClassHelper(org.seasar.doma.jdbc.ClassHelper) Reference(org.seasar.doma.jdbc.Reference) PhoneNumber(example.domain.PhoneNumber) Test(org.junit.jupiter.api.Test)

Example 9 with PhoneNumber

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

the class ScalarInParameterTest method testGetDomainClass.

@Test
public void testGetDomainClass() {
    DomainType<String, PhoneNumber> domainType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
    });
    Scalar<String, PhoneNumber> scalar = domainType.createScalar();
    ScalarInParameter<String, PhoneNumber> parameter = new ScalarInParameter<>(scalar);
    Optional<Class<?>> optional = parameter.getDomainClass();
    assertEquals(PhoneNumber.class, optional.get());
}
Also used : ClassHelper(org.seasar.doma.jdbc.ClassHelper) PhoneNumber(example.domain.PhoneNumber) Test(org.junit.jupiter.api.Test)

Example 10 with PhoneNumber

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

the class ScalarsTest method testWrapDomain.

@Test
public void testWrapDomain() {
    PhoneNumber phoneNumber = new PhoneNumber("123-456-789");
    Supplier<Scalar<?, ?>> supplier = Scalars.wrap(phoneNumber, PhoneNumber.class, false, classHelper);
    assertNotNull(supplier);
    Scalar<?, ?> scalar = supplier.get();
    assertEquals(phoneNumber, scalar.get());
    assertEquals(phoneNumber, scalar.getAsNonOptional());
    Wrapper<?> wrapper = scalar.getWrapper();
    assertEquals(StringWrapper.class, wrapper.getClass());
    assertEquals("123-456-789", wrapper.get());
}
Also used : PhoneNumber(example.domain.PhoneNumber) InternationalPhoneNumber(example.domain.InternationalPhoneNumber) 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