Search in sources :

Example 1 with TestCase

use of com.cadenzauk.core.junit.TestCase in project siesta by cadenzauk.

the class MethodUtilTest method annotationsMultiple.

@Test
void annotationsMultiple() {
    Method method = MethodUtil.fromReference(TestDerivedClass.class, TestClass::method2);
    Stream<TestCase> annotations = MethodUtil.annotations(TestCase.class, method);
    assertThat(annotations.count(), is(3L));
}
Also used : TestCase(com.cadenzauk.core.junit.TestCase) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 2 with TestCase

use of com.cadenzauk.core.junit.TestCase 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 3 with TestCase

use of com.cadenzauk.core.junit.TestCase 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 4 with TestCase

use of com.cadenzauk.core.junit.TestCase in project siesta by cadenzauk.

the class DatabaseIntegrationTest method currentTimestampLocalTest.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void currentTimestampLocalTest(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = TemporalTestUtil.withTimeZone(timeZone)) {
        LocalDateTime before = LocalDateTime.now(database.databaseTimeZone()).minusSeconds(10);
        LocalDateTime now = database.select(currentTimestampLocal()).single();
        LocalDateTime after = LocalDateTime.now(database.databaseTimeZone()).plusSeconds(10);
        System.out.printf("%s <= %s <= %s%n", before, now, after);
        assertThat(before.isAfter(now), is(false));
        assertThat(now.isAfter(after), is(false));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) RandomValues.randomLocalDateTime(com.cadenzauk.core.RandomValues.randomLocalDateTime) 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 TestCase

use of com.cadenzauk.core.junit.TestCase in project siesta by cadenzauk.

the class DatabaseIntegrationTest method currentDateTest.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void currentDateTest(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = TemporalTestUtil.withTimeZone(timeZone)) {
        LocalDate before = LocalDate.now(database.databaseTimeZone());
        LocalDate now = database.select(currentDate()).single();
        LocalDate after = LocalDate.now(database.databaseTimeZone());
        System.out.printf("%s <= %s <= %s%n", before, now, after);
        assertThat(before.isAfter(now), is(false));
        assertThat(now.isAfter(after), is(false));
    }
}
Also used : TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) LocalDate(java.time.LocalDate) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

TestCase (com.cadenzauk.core.junit.TestCase)8 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)7 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)6 RandomValues.randomZonedDateTime (com.cadenzauk.core.RandomValues.randomZonedDateTime)3 TestRow (com.cadenzauk.siesta.model.TestRow)3 ZonedDateTime (java.time.ZonedDateTime)3 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)2 LocalDateTime (java.time.LocalDateTime)2 RandomValues.randomLocalTime (com.cadenzauk.core.RandomValues.randomLocalTime)1 Method (java.lang.reflect.Method)1 LocalDate (java.time.LocalDate)1 LocalTime (java.time.LocalTime)1 Test (org.junit.jupiter.api.Test)1