Search in sources :

Example 1 with TestRow

use of com.cadenzauk.siesta.model.TestRow in project siesta by cadenzauk.

the class DatabaseIntegrationTest method canRoundTripLocalTimes.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripLocalTimes(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalTime expected = randomLocalTime();
        TestRow input = TestRow.of(expected);
        database.insert(input);
        LocalTime result = database.from(TestRow.class).select(TestRow::localTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
        assertThat(result, is(expected));
    }
}
Also used : LocalTime(java.time.LocalTime) RandomValues.randomLocalTime(com.cadenzauk.core.RandomValues.randomLocalTime) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 2 with TestRow

use of com.cadenzauk.siesta.model.TestRow in project siesta by cadenzauk.

the class DatabaseIntegrationTest method canRoundTripZonedDateTimes.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripZonedDateTimes(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        ZonedDateTime expected = randomZonedDateTime(ZoneId.of("UTC"));
        TestRow input = TestRow.of(expected);
        database.insert(input);
        ZonedDateTime result = database.from(TestRow.class).select(TestRow::utcDateTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
        assertThat(result, is(expected));
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) RandomValues.randomZonedDateTime(com.cadenzauk.core.RandomValues.randomZonedDateTime) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 3 with TestRow

use of com.cadenzauk.siesta.model.TestRow in project siesta by cadenzauk.

the class FunctionTest method functionTest.

@ParameterizedTest
@MethodSource("parametersForFunctionTest")
void functionTest(Function<Alias<TestRow>, TypedExpression<?>> sutSupplier, String expectedSql, Object[] expectedArgs) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    Alias<TestRow> alias = database.table(TestRow.class).as("s");
    database.from(alias).select(sutSupplier.apply(alias), "foo").list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select " + expectedSql + " as foo from SIESTA.TEST_TABLE s"));
    assertThat(args.getValue(), is(expectedArgs));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with TestRow

use of com.cadenzauk.siesta.model.TestRow in project siesta by cadenzauk.

the class DatabaseIntegrationTest method canRoundTripLocalDateTimes.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripLocalDateTimes(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalDateTime expected = randomLocalDateTime();
        TestRow input = TestRow.of(expected);
        database.insert(input);
        LocalDateTime result = database.from(TestRow.class).select(TestRow::localDateTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
        assertThat(result, is(expected));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) RandomValues.randomLocalDateTime(com.cadenzauk.core.RandomValues.randomLocalDateTime) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 5 with TestRow

use of com.cadenzauk.siesta.model.TestRow in project siesta by cadenzauk.

the class DatabaseIntegrationTest method roundTripNulls.

@SuppressWarnings("OptionalAssignedToNull")
@Test
void roundTripNulls() {
    Database database = testDatabase(dataSource, dialect);
    UUID guid = UUID.randomUUID();
    database.insert(TestRow.newBuilder().guid(guid).decimalOpt(null).decimalReq(null).integerOpt(null).integerReq(null).localDateOpt(null).localDateReq(null).localDateTimeOpt(null).localDateTimeReq(null).localTimeOpt(null).localTimeReq(null).stringOpt(null).stringReq(null).utcDateTimeOpt(null).utcDateTimeReq(null).build());
    TestRow result = database.from(TestRow.class).where(TestRow::guid).isEqualTo(guid).single();
    assertThat(result.decimalOpt(), is(Optional.empty()));
    assertThat(result.decimalReq(), nullValue());
    assertThat(result.integerOpt(), is(Optional.empty()));
    assertThat(result.integerReq(), nullValue());
    assertThat(result.localDateOpt(), is(Optional.empty()));
    assertThat(result.localDateReq(), nullValue());
    assertThat(result.localDateTimeOpt(), is(Optional.empty()));
    assertThat(result.localDateTimeReq(), nullValue());
    assertThat(result.localTimeOpt(), is(Optional.empty()));
    assertThat(result.localTimeReq(), nullValue());
    assertThat(result.stringOpt(), is(Optional.empty()));
    assertThat(result.stringReq(), nullValue());
    assertThat(result.utcDateTimeOpt(), is(Optional.empty()));
    assertThat(result.utcDateTimeReq(), nullValue());
}
Also used : TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TestRow (com.cadenzauk.siesta.model.TestRow)7 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 TestCase (com.cadenzauk.core.junit.TestCase)3 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)3 Test (org.junit.jupiter.api.Test)3 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)3 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 ZonedDateTime (java.time.ZonedDateTime)2 UUID (java.util.UUID)2 RandomValues (com.cadenzauk.core.RandomValues)1 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)1 RandomValues.randomLocalTime (com.cadenzauk.core.RandomValues.randomLocalTime)1 RandomValues.randomZonedDateTime (com.cadenzauk.core.RandomValues.randomZonedDateTime)1 IsUtilityClass.isUtilityClass (com.cadenzauk.core.testutil.IsUtilityClass.isUtilityClass)1 Database (com.cadenzauk.siesta.Database)1 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)1 DateFunctions.addDays (com.cadenzauk.siesta.grammar.expression.DateFunctions.addDays)1 DateFunctions.day (com.cadenzauk.siesta.grammar.expression.DateFunctions.day)1