use of example.domain.PhoneNumber in project doma by domaframework.
the class ScalarsTest method testWrapDomain_null.
@Test
public void testWrapDomain_null() {
Supplier<Scalar<?, ?>> supplier = Scalars.wrap(null, PhoneNumber.class, false, classHelper);
assertNotNull(supplier);
Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof PhoneNumber);
assertTrue(scalar.getAsNonOptional() instanceof PhoneNumber);
PhoneNumber phoneNumber = (PhoneNumber) scalar.get();
assertNull(phoneNumber.getValue());
Wrapper<?> wrapper = scalar.getWrapper();
assertEquals(StringWrapper.class, wrapper.getClass());
assertNull(wrapper.get());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class ScalarsTest method testWrapDomain_subclass.
@Test
public void testWrapDomain_subclass() {
PhoneNumber phoneNumber = new InternationalPhoneNumber("123-456-789");
Supplier<Scalar<?, ?>> supplier = Scalars.wrap(phoneNumber, InternationalPhoneNumber.class, false, classHelper);
assertNotNull(supplier);
Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof InternationalPhoneNumber);
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 SqlParserTest method testBindVariable_domain.
@Test
public void testBindVariable_domain() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("phone", new Value(PhoneNumber.class, new PhoneNumber("01-2345-6789")));
String testSql = "select * from aaa where phone = /*phone*/'111'";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
PreparedSql sql = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
assertEquals("select * from aaa where phone = ?", sql.getRawSql());
assertEquals("select * from aaa where phone = '01-2345-6789'", sql.getFormattedSql());
assertEquals(1, sql.getParameters().size());
assertEquals("01-2345-6789", sql.getParameters().get(0).getWrapper().get());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class DomainResultListHandlerTest 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"));
resultSet.rows.add(new RowData("12-3456-7890"));
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();
DomainResultListHandler<String, PhoneNumber> handler = new DomainResultListHandler<>(_PhoneNumber.getSingletonInternal());
List<PhoneNumber> results = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(2, results.size());
assertEquals("01-2345-6789", results.get(0).getValue());
assertEquals("12-3456-7890", results.get(1).getValue());
}
use of example.domain.PhoneNumber in project doma by domaframework.
the class DomainSingleResultHandlerTest method testHandle_NonUniqueResultException.
@Test
public void testHandle_NonUniqueResultException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("phoneNumber"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("01-2345-6789"));
resultSet.rows.add(new RowData("02-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());
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonUniqueResultException expected) {
}
}
Aggregations