use of example.domain.PhoneNumber in project doma by domaframework.
the class ScalarsTest method testWrapDomain_option.
@SuppressWarnings("unchecked")
@Test
public void testWrapDomain_option() {
PhoneNumber phoneNumber = new PhoneNumber("123-456-789");
Supplier<Scalar<?, ?>> supplier = Scalars.wrap(phoneNumber, PhoneNumber.class, true, classHelper);
assertNotNull(supplier);
Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertTrue(scalar.getAsNonOptional() instanceof PhoneNumber);
Optional<PhoneNumber> optional = (Optional<PhoneNumber>) scalar.get();
assertEquals(phoneNumber, optional.get());
Wrapper<?> wrapper = scalar.getWrapper();
assertEquals(StringWrapper.class, wrapper.getClass());
assertEquals("123-456-789", wrapper.get());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class PreparedSqlBuilderTest method testAppendParameter_domain.
@Test
public void testAppendParameter_domain() {
PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.SELECT, SqlLogType.FORMATTED);
builder.appendSql("select * from aaa where phoneNumber = ");
DomainType<String, PhoneNumber> phoneNumberType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
});
PhoneNumber phoneNumber = new PhoneNumber("03-1234-5678");
builder.appendParameter(new DomainInParameter<>(phoneNumberType, phoneNumber));
PreparedSql sql = builder.build(Function.identity());
assertEquals("select * from aaa where phoneNumber = ?", sql.toString());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class ScalarInOutParameterTest method testGetDomainClass_optional.
@Test
public void testGetDomainClass_optional() {
DomainType<String, PhoneNumber> domainType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
});
Scalar<String, Optional<PhoneNumber>> scalar = domainType.createOptionalScalar();
Reference<Optional<PhoneNumber>> ref = new Reference<>();
ScalarInOutParameter<String, Optional<PhoneNumber>> parameter = new ScalarInOutParameter<>(scalar, ref);
Optional<Class<?>> optional = parameter.getDomainClass();
assertEquals(PhoneNumber.class, optional.get());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class ScalarInParameterTest method testGetDomainClass_optional.
@Test
public void testGetDomainClass_optional() {
DomainType<String, PhoneNumber> domainType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
});
Scalar<String, Optional<PhoneNumber>> scalar = domainType.createOptionalScalar();
ScalarInParameter<String, Optional<PhoneNumber>> parameter = new ScalarInParameter<>(scalar);
Optional<Class<?>> optional = parameter.getDomainClass();
assertEquals(PhoneNumber.class, optional.get());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class ScalarProviderTest method testDomain.
@Test
public void testDomain() 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, PhoneNumber> provider = new ScalarProvider<>(domainType::createScalar, new MySelectQuery());
PhoneNumber result = provider.get(resultSet);
assertEquals("hoge", result.getValue());
}
Aggregations