Search in sources :

Example 36 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class CountTest method countStar.

@Test
void countStar() {
    Database database = TestDatabase.testDatabase(new AnsiDialect());
    database.from(WidgetRow.class, "w").select(count(), "n").where(WidgetRow::manufacturerId).isEqualTo(4002L).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select count(*) as n " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
    assertThat(args.getValue(), arrayWithSize(1));
    assertThat(args.getValue()[0], is(4002L));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase(com.cadenzauk.siesta.model.TestDatabase) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Example 37 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class DataTypeTest method toDatabaseOfOptional.

@ParameterizedTest
@MethodSource("parametersForToDatabase")
<T> void toDatabaseOfOptional(DataType<T> dataType, T input, Object expected) {
    if (input != null) {
        when(db.dialect()).thenReturn(new AnsiDialect());
    }
    Object actual = dataType.toDatabase(db, Optional.ofNullable(input));
    assertThat(actual, is(expected));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 38 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class DataTypeTest method getLocalDate.

@ParameterizedTest
@MethodSource("timeZones")
void getLocalDate(String timeZone) throws SQLException {
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalDate expected = randomLocalDate();
        when(db.dialect()).thenReturn(new AnsiDialect());
        when(rs.getDate(eq("someColumn"), any())).thenReturn(Date.valueOf(expected));
        Optional<LocalDate> result = DataType.LOCAL_DATE.get(rs, "someColumn", db);
        assertThat(result, is(Optional.of(expected)));
    }
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) RandomValues.randomLocalDate(com.cadenzauk.core.RandomValues.randomLocalDate) LocalDate(java.time.LocalDate) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 39 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class DataTypeTest method getLocalDateTime.

@ParameterizedTest
@MethodSource("timeZones")
void getLocalDateTime(String timeZone) throws SQLException {
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalDateTime expected = randomLocalDateTime();
        when(db.dialect()).thenReturn(new AnsiDialect());
        when(rs.getTimestamp(eq("someColumn"), any())).thenReturn(Timestamp.valueOf(expected));
        Optional<LocalDateTime> result = DataType.LOCAL_DATE_TIME.get(rs, "someColumn", db);
        assertThat(result, is(Optional.of(expected)));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) RandomValues.randomLocalDateTime(com.cadenzauk.core.RandomValues.randomLocalDateTime) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 40 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class DataTypeTest method toDatabaseLocalDate.

@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDate(String timeZone) {
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalDate input = RandomValues.randomLocalDate();
        Date expected = Date.valueOf(input);
        when(db.dialect()).thenReturn(new AnsiDialect());
        Object result = DataType.LOCAL_DATE.toDatabase(db, input);
        assertThat(result, is(expected));
    }
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) RandomValues.randomLocalDate(com.cadenzauk.core.RandomValues.randomLocalDate) LocalDate(java.time.LocalDate) Date(java.sql.Date) RandomValues.randomLocalDate(com.cadenzauk.core.RandomValues.randomLocalDate) LocalDate(java.time.LocalDate) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)56 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)36 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)24 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)23 Database (com.cadenzauk.siesta.Database)16 MockitoTest (com.cadenzauk.core.MockitoTest)14 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)10 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)10 ManufacturerRow (com.cadenzauk.siesta.model.ManufacturerRow)8 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)5 InWhereExpectingAnd (com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd)4 Scope (com.cadenzauk.siesta.Scope)3 Timestamp (java.sql.Timestamp)3 RandomValues.randomLocalDate (com.cadenzauk.core.RandomValues.randomLocalDate)2 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)2 InvalidJoinException (com.cadenzauk.siesta.grammar.InvalidJoinException)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2