Search in sources :

Example 46 with Something

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

the class TestBindExpression method testExpression.

@Test
public void testExpression() throws Exception {
    DB db = dbRule.getSharedHandle().attach(DB.class);
    db.insert(new Something(1, "syrup"), new Something(2, "whipped cream"));
    Something with_syrup = db.findByBreakfast(new Breakfast());
    assertThat(with_syrup).isEqualTo(new Something(1, "syrup"));
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 47 with Something

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

the class TestCollectorFactory method testWithSqlObjectSetReturnValue.

@Test
public void testWithSqlObjectSetReturnValue() throws Exception {
    Dao dao = dbRule.getJdbi().onDemand(Dao.class);
    dao.insert(new Something(1, "Coda"));
    dao.insert(new Something(2, "Brian"));
    SortedSet<String> rs = dao.findAllAsSet();
    assertThat(rs).containsExactly("Brian", "Coda");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 48 with Something

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

the class TestConsumer method testReturnStream.

@Test
public void testReturnStream() throws Exception {
    Something one = new Something(3, "foo");
    Something two = new Something(4, "bar");
    Something thr = new Something(5, "baz");
    Spiffy dao = dbRule.getJdbi().open().attach(Spiffy.class);
    dao.insert(one);
    dao.insert(thr);
    dao.insert(two);
    List<Something> results = new ArrayList<>();
    dao.forEach(results::add);
    assertThat(results).containsExactly(thr, two, one);
}
Also used : ArrayList(java.util.ArrayList) Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 49 with Something

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

the class TestCustomBinder method testFoo.

@Test
public void testFoo() throws Exception {
    dbRule.getSharedHandle().execute("insert into something (id, name) values (2, 'Martin')");
    dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
        Something s = spiffy.findSame(new Something(2, "Unknown"));
        assertThat(s.getName()).isEqualTo("Martin");
    });
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 50 with Something

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

the class TestDefineListParameter method testEmptyList.

@Test(expected = IllegalArgumentException.class)
public void testEmptyList() {
    TestDao testDao = handle.attach(TestDao.class);
    List<String> noColumns = new ArrayList<>();
    Something something = new Something(1, "Some Pig");
    testDao.insert("test", noColumns, something);
}
Also used : ArrayList(java.util.ArrayList) 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