use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class FieldMapperTest method testNestedPrefix.
@Test
public void testNestedPrefix() {
Handle handle = dbRule.getSharedHandle();
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.registerRowMapper(FieldMapper.factory(NestedPrefixThing.class)).select("select id nested_id, name nested_name from something").mapTo(NestedPrefixThing.class).findOnly()).extracting("nested.i", "nested.s").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class FieldMapperTest method shouldSetValuesOnAllFieldAccessTypes.
@Test
public void shouldSetValuesOnAllFieldAccessTypes() throws Exception {
mockColumns("longField", "protectedStringField", "packagePrivateIntField", "privateBigDecimalField");
Long aLongVal = 100L;
String aStringVal = "something";
int aIntVal = 1;
BigDecimal aBigDecimal = BigDecimal.TEN;
when(resultSet.getLong(1)).thenReturn(aLongVal);
when(resultSet.getString(2)).thenReturn(aStringVal);
when(resultSet.getInt(3)).thenReturn(aIntVal);
when(resultSet.getBigDecimal(4)).thenReturn(aBigDecimal);
when(resultSet.wasNull()).thenReturn(false);
SampleBean sampleBean = mapper.map(resultSet, ctx);
assertThat(sampleBean.getLongField()).isEqualTo(aLongVal);
assertThat(sampleBean.getPrivateBigDecimalField()).isEqualTo(aBigDecimal);
assertThat(sampleBean.getPackagePrivateIntField()).isEqualTo(aIntVal);
assertThat(sampleBean.getProtectedStringField()).isEqualTo(aStringVal);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class FieldMapperTest method testColumnNameAnnotation.
@Test
public void testColumnNameAnnotation() {
Handle handle = dbRule.getSharedHandle();
handle.execute("insert into something (id, name) values (1, 'foo')");
ColumnNameThing thing = handle.createQuery("select * from something").map(FieldMapper.of(ColumnNameThing.class)).findOnly();
assertThat(thing.i).isEqualTo(1);
assertThat(thing.s).isEqualTo("foo");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class FieldMapperTest method testNested.
@Test
public void testNested() {
Handle handle = dbRule.getSharedHandle();
handle.execute("insert into something (id, name) values (1, 'foo')");
assertThat(handle.registerRowMapper(FieldMapper.factory(NestedThing.class)).select("SELECT id, name FROM something").mapTo(NestedThing.class).findOnly()).extracting("nested.i", "nested.s").containsExactly(1, "foo");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestReducing method setUp.
@Before
public void setUp() {
Handle h = dbRule.getSharedHandle();
h.execute("CREATE TABLE something_location (id int, location varchar)");
h.execute("INSERT INTO something (id, name) VALUES (1, 'tree')");
h.execute("INSERT INTO something (id, name) VALUES (2, 'apple')");
h.execute("INSERT INTO something_location (id, location) VALUES (1, 'outside')");
h.execute("INSERT INTO something_location (id, location) VALUES (2, 'tree')");
h.execute("INSERT INTO something_location (id, location) VALUES (2, 'pie')");
h.registerRowMapper(new SomethingMapper());
}
Aggregations