Search in sources :

Example 11 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestRegisteredMappersWork method testRegisterRowMapperAnnotationWorks.

@Test
public void testRegisterRowMapperAnnotationWorks() throws Exception {
    Kabob bob = dbRule.getJdbi().onDemand(Kabob.class);
    bob.insert(1, "Henning");
    Something henning = bob.find(1);
    assertThat(henning).isEqualTo(new Something(1, "Henning"));
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 12 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestReturningQuery method testWithExplicitMapper.

@Test
public void testWithExplicitMapper() throws Exception {
    handle.execute("insert into something (id, name) values (7, 'Tim')");
    dbRule.getJdbi().useExtension(Spiffy2.class, spiffy -> {
        Something s = spiffy.findByIdWithExplicitMapper(7).findOnly();
        assertThat(s.getName()).isEqualTo("Tim");
    });
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 13 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestReturningQuery method testWithRegisteredMapper.

@Test
public void testWithRegisteredMapper() throws Exception {
    handle.execute("insert into something (id, name) values (7, 'Tim')");
    dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
        Something s = spiffy.findById(7).findOnly();
        assertThat(s.getName()).isEqualTo("Tim");
    });
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 14 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestReturningQueryResults method testSingleValue.

@Test
public void testSingleValue() throws Exception {
    handle.execute("insert into something (id, name) values (7, 'Tim')");
    dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
        Something s = spiffy.findById(7);
        assertThat(s.getName()).isEqualTo("Tim");
    });
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 15 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestReturningQueryResults method testList.

@Test
public void testList() throws Exception {
    handle.execute("insert into something (id, name) values (7, 'Tim')");
    handle.execute("insert into something (id, name) values (3, 'Diego')");
    dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
        List<Something> all = spiffy.findTwoByIds(3, 7);
        assertThat(all).containsOnlyOnce(new Something(7, "Tim"), new Something(3, "Diego"));
    });
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)170 Something (org.jdbi.v3.core.Something)123 Handle (org.jdbi.v3.core.Handle)80 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)17 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)6 Jdbi (org.jdbi.v3.core.Jdbi)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 GenericType (org.jdbi.v3.core.generic.GenericType)5 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 H2DatabaseRule (org.jdbi.v3.core.rule.H2DatabaseRule)4 Rule (org.junit.Rule)4 Connection (java.sql.Connection)3 LinkedHashMap (java.util.LinkedHashMap)3 Collector (java.util.stream.Collector)3 Collectors.toList (java.util.stream.Collectors.toList)3 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)3 NoSuchMapperException (org.jdbi.v3.core.mapper.NoSuchMapperException)3