Search in sources :

Example 36 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestVavrValueArgumentFactoryWithDB method testGetOption_shouldReturnCorrectRow.

@Test
public void testGetOption_shouldReturnCorrectRow() {
    Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Option.of("eric")).mapToBean(Something.class).findOnly();
    assertThat(result).isEqualTo(ERIC_SOMETHING);
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 37 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestVavrValueArgumentFactoryWithDB method testGetTrySuccess_shouldReturnCorrectRow.

@Test
public void testGetTrySuccess_shouldReturnCorrectRow() {
    Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Try.success("brian")).mapToBean(Something.class).findOnly();
    assertThat(result).isEqualTo(BRIAN_SOMETHING);
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 38 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project providence by morimekta.

the class MessageInserterTest method testDefaultMapping.

@Test
public void testDefaultMapping() {
    generator.setFillRate(1.0).setMaxCollectionItems(16);
    OptionalFields expected = generator.generate(OptionalFields.kDescriptor).mutate().setId(1234).setTimestampS((int) clock.instant().getEpochSecond()).setTimestampMs(clock.instant().getEpochSecond() * 1000).build();
    OptionalFields empty = OptionalFields.builder().setId(2345).build();
    try (Handle handle = db.getDBI().open()) {
        INSERTER.execute(handle, expected, empty);
        OptionalFields val = handle.createQuery("SELECT * FROM mappings_v3.default_mappings WHERE id = :id").bind("id", expected.getId()).map(toMessage(OptionalFields.kDescriptor, columnsFromAllFields(), withColumn("compact", MESSAGE), withColumn("other_message", CLOB_MESSAGE))).findFirst().orElseThrow(() -> new AssertionError("No content in default_mappings"));
        OptionalFields val2 = handle.createQuery("SELECT * FROM mappings_v3.default_mappings WHERE id = :id").bind("id", empty.getId()).map(toMessage(OptionalFields.kDescriptor, columnsFromAllFields(), withColumn("compact", MESSAGE), withColumn("other_message", CLOB_MESSAGE))).findFirst().orElseThrow(() -> new AssertionError("No content in default_mappings"));
        assertThat(val, is(equalToMessage(expected)));
        assertThat(val2, is(equalToMessage(empty)));
    }
}
Also used : OptionalFields(net.morimekta.test.providence.storage.jdbc.OptionalFields) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Handle (org.jdbi.v3.core.Handle)18 Something (org.jdbi.v3.core.Something)15 Jdbi (org.jdbi.v3.core.Jdbi)4 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 Parameter (java.lang.reflect.Parameter)2 Type (java.lang.reflect.Type)2 OptionalFields (net.morimekta.test.providence.storage.jdbc.OptionalFields)2 PreparedBatch (org.jdbi.v3.core.statement.PreparedBatch)2 Query (org.jdbi.v3.core.statement.Query)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Types (java.sql.Types)1 Clock (java.time.Clock)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 ProvidenceJdbi.columnsFromAllFields (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.columnsFromAllFields)1 ProvidenceJdbi.forMessage (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.forMessage)1 ProvidenceJdbi.toField (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.toField)1 ProvidenceJdbi.toMessage (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.toMessage)1