Search in sources :

Example 6 with Something

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

the class TestUseClasspathSqlLocator method testBam.

@Test
public void testBam() throws Exception {
    Something s = handle.attach(Cromulence.class).findById(6L);
    assertThat(s.getName()).isEqualTo("Martin");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 7 with Something

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

the class TestUseClasspathSqlLocator method testOverride.

@Test
public void testOverride() throws Exception {
    Something s = handle.attach(SubCromulence.class).findById(6L);
    assertThat(s.getName()).isEqualTo("overridden");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 8 with Something

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

the class TestVariousOddities method testAttach.

@Test
public void testAttach() throws Exception {
    Spiffy s = dbRule.getSharedHandle().attach(Spiffy.class);
    s.insert(new Something(14, "Tom"));
    Something tom = s.byId(14);
    assertThat(tom.getName()).isEqualTo("Tom");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 9 with Something

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

the class TestRegisteredMappersWork method testNoErrorOnNoData.

@Test
public void testNoErrorOnNoData() throws Exception {
    Kabob bob = dbRule.getJdbi().onDemand(Kabob.class);
    Something henning = bob.find(1);
    assertThat(henning).isNull();
    List<Something> rs = bob.listAll();
    assertThat(rs).isEmpty();
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 10 with Something

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

the class TestRegisteredMappersWork method testNoRootRegistrations.

@Test(expected = NoSuchMapperException.class)
public void testNoRootRegistrations() throws Exception {
    try (Handle h = dbRule.openHandle()) {
        h.execute("insert into something (id, name) values (1, 'Henning')");
        h.createQuery("select id, name from something where id = 1").mapTo(Something.class).findFirst();
    }
}
Also used : Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) 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