Search in sources :

Example 26 with Something

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

the class TestConditionalStringTemplateLocator method setUp.

@Before
public void setUp() throws Exception {
    Handle handle = dbRule.getSharedHandle();
    handle.execute("insert into something (id, name) values (1, 'Martin')");
    handle.execute("insert into something (id, name) values (3, 'David')");
    handle.execute("insert into something (id, name) values (2, 'Joe')");
}
Also used : Handle(org.jdbi.v3.core.Handle) Before(org.junit.Before)

Example 27 with Something

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

the class TestStringTemplateSqlLocator method testBam.

@Test
public void testBam() throws Exception {
    handle.execute("insert into something (id, name) values (6, 'Martin')");
    Something s = handle.attach(Wombat.class).findById(6L);
    assertThat(s.getName()).isEqualTo("Martin");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 28 with Something

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

the class TestStringTemplateSqlLocator method testBaz.

@Test
public void testBaz() throws Exception {
    Wombat wombat = handle.attach(Wombat.class);
    wombat.insert(new Something(7, "Henning"));
    String name = handle.createQuery("select name from something where id = 7").mapTo(String.class).findOnly();
    assertThat(name).isEqualTo("Henning");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 29 with Something

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

the class TestStringTemplateSqlLocator method testBatching.

@Test
public void testBatching() throws Exception {
    Wombat roo = handle.attach(Wombat.class);
    roo.insertBunches(new Something(1, "Jeff"), new Something(2, "Brian"));
    assertThat(roo.findById(1L)).isEqualTo(new Something(1, "Jeff"));
    assertThat(roo.findById(2L)).isEqualTo(new Something(2, "Brian"));
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 30 with Something

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

the class TestVavrValueArgumentFactoryWithDB method testGetValidationValid_shouldReturnCorrectRow.

@Test
public void testGetValidationValid_shouldReturnCorrectRow() {
    Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Validation.valid("brian")).mapToBean(Something.class).findOnly();
    assertThat(result).isEqualTo(BRIAN_SOMETHING);
}
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