Search in sources :

Example 1 with RandomValues.randomLocalDateTime

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

the class DatabaseIntegrationTest method localDateTimePartFuncs.

@Test
void localDateTimePartFuncs() {
    LocalDateTime dateTime = RandomValues.randomLocalDateTime();
    Database database = testDatabase(dataSource, dialect);
    Tuple6<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(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.getMinute()));
    assertThat(result.item6(), is(dateTime.getSecond()));
}
Also used : LocalDateTime(java.time.LocalDateTime) RandomValues.randomLocalDateTime(com.cadenzauk.core.RandomValues.randomLocalDateTime) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RandomValues.randomLocalDateTime

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

the class DataTypeTest method toDatabaseLocalDateTime.

@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDateTime(String jvmTimeZone) {
    try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
        LocalDateTime input = RandomValues.randomLocalDateTime();
        Timestamp expected = Timestamp.valueOf(input);
        when(db.dialect()).thenReturn(new AnsiDialect());
        Object result = DataType.LOCAL_DATE_TIME.toDatabase(db, input);
        assertThat(result, is(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) Timestamp(java.sql.Timestamp) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)2 LocalDateTime (java.time.LocalDateTime)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)1 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)1 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)1 Timestamp (java.sql.Timestamp)1 Test (org.junit.jupiter.api.Test)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1