use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestEnums method testMapToEnum.
@Test
public void testMapToEnum() throws Exception {
Handle h = dbRule.openHandle();
h.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
h.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
List<SomethingElse.Name> results = h.createQuery("select name from something order by id").mapTo(SomethingElse.Name.class).list();
assertThat(results).containsExactly(SomethingElse.Name.eric, SomethingElse.Name.brian);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class BeanMapperTest method testNestedPrefix.
@Test
public void testNestedPrefix() {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(BeanMapper.factory(NestedPrefixBean.class));
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.createQuery("select id nested_id, name nested_name from something").mapTo(NestedPrefixBean.class).findOnly()).extracting("nested.id", "nested.name").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class BeanMapperTest method testNested.
@Test
public void testNested() {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(BeanMapper.factory(NestedBean.class));
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.createQuery("select id, name from something").mapTo(NestedBean.class).findOnly()).extracting("nested.id", "nested.name").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class BeanMapperTest method testColumnNameAnnotation.
@Test
public void testColumnNameAnnotation() {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(BeanMapper.factory(ColumnNameBean.class));
handle.execute("insert into something (id, name) values (1, 'foo')");
ColumnNameBean bean = handle.createQuery("select * from something").mapTo(ColumnNameBean.class).findOnly();
assertThat(bean.getI()).isEqualTo(1);
assertThat(bean.getS()).isEqualTo("foo");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class BeanMapperTest method testNestedPrefixStrict.
@Test
public void testNestedPrefixStrict() {
Handle handle = dbRule.getSharedHandle();
handle.getConfig(ReflectionMappers.class).setStrictMatching(true);
handle.registerRowMapper(BeanMapper.factory(NestedPrefixBean.class));
// three, sir!
handle.execute("insert into something (id, name, integerValue) values (1, 'foo', 5)");
assertThat(handle.createQuery("select id nested_id, name nested_name, integerValue from something").mapTo(NestedPrefixBean.class).findOnly()).extracting("nested.id", "nested.name", "integerValue").containsExactly(1, "foo", 5);
assertThatThrownBy(() -> handle.createQuery("select id nested_id, name nested_name, 1 as other from something").mapTo(NestedPrefixBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match properties for columns: [other]");
assertThatThrownBy(() -> handle.createQuery("select id nested_id, name nested_name, 1 as nested_other from something").mapTo(NestedPrefixBean.class).findOnly()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("could not match properties for columns: [nested_other]");
}
Aggregations