Search in sources :

Example 1 with RandomValues.randomZonedDateTime

use of com.cadenzauk.core.RandomValues.randomZonedDateTime in project siesta by cadenzauk.

the class DatabaseIntegrationTest method zonedDateTimePartFuncs.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void zonedDateTimePartFuncs(String timeZone) {
    Database database = testDatabaseBuilder(dialect).defaultSqlExecutor(JdbcSqlExecutor.of(dataSource)).databaseTimeZone(ZoneId.of(timeZone)).build();
    ZonedDateTime dateTime = RandomValues.randomZonedDateTime(database.databaseTimeZone());
    Tuple7<Integer, Integer, Integer, Integer, Integer, Integer, Integer> result = database.select(year(LiteralExpression.of(dateTime))).comma(month(ValueExpression.of(dateTime))).comma(day(LiteralExpression.of(dateTime))).comma(hour(ValueExpression.of(dateTime))).comma(hour(LiteralExpression.of(dateTime))).comma(minute(LiteralExpression.of(dateTime))).comma(second(ValueExpression.of(dateTime))).single();
    assertThat(result.item1(), is(dateTime.getYear()));
    assertThat(result.item2(), is(dateTime.getMonthValue()));
    assertThat(result.item3(), is(dateTime.getDayOfMonth()));
    assertThat(result.item4(), is(dateTime.getHour()));
    assertThat(result.item5(), is(dateTime.getHour()));
    assertThat(result.item6(), is(dateTime.getMinute()));
    assertThat(result.item7(), is(dateTime.getSecond()));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) RandomValues.randomZonedDateTime(com.cadenzauk.core.RandomValues.randomZonedDateTime) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

RandomValues.randomZonedDateTime (com.cadenzauk.core.RandomValues.randomZonedDateTime)1 TestCase (com.cadenzauk.core.junit.TestCase)1 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)1 ZonedDateTime (java.time.ZonedDateTime)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)1