Search in sources :

Example 46 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource 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)

Example 47 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource 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)

Example 48 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource 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 49 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project siesta by cadenzauk.

the class DatabaseIntegrationTest method currentTimestampTest.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void currentTimestampTest(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = TemporalTestUtil.withTimeZone(timeZone)) {
        ZonedDateTime before = ZonedDateTime.now(ZoneId.of("UTC")).minusSeconds(10);
        ZonedDateTime now = database.select(currentTimestamp()).single();
        ZonedDateTime after = ZonedDateTime.now(ZoneId.of("UTC")).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 : ZonedDateTime(java.time.ZonedDateTime) RandomValues.randomZonedDateTime(com.cadenzauk.core.RandomValues.randomZonedDateTime) 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 50 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project junit5 by junit-team.

the class ParameterizedTestExtension method provideTestTemplateInvocationContexts.

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
    Method templateMethod = context.getRequiredTestMethod();
    ParameterizedTestNameFormatter formatter = createNameFormatter(templateMethod);
    AtomicLong invocationCount = new AtomicLong(0);
    // @formatter:off
    return findRepeatableAnnotations(templateMethod, ArgumentsSource.class).stream().map(ArgumentsSource::value).map(ReflectionUtils::newInstance).map(provider -> AnnotationConsumerInitializer.initialize(templateMethod, provider)).flatMap(provider -> arguments(provider, context)).map(Arguments::get).map(arguments -> consumedArguments(arguments, templateMethod)).map(arguments -> createInvocationContext(formatter, arguments)).peek(invocationContext -> invocationCount.incrementAndGet()).onClose(() -> Preconditions.condition(invocationCount.get() > 0, () -> "Configuration error: You must provide at least one argument for this @" + ParameterizedTest.class.getSimpleName()));
// @formatter:on
}
Also used : AnnotationConsumerInitializer(org.junit.jupiter.params.support.AnnotationConsumerInitializer) Preconditions(org.junit.platform.commons.util.Preconditions) Arrays(java.util.Arrays) AnnotationUtils.isAnnotated(org.junit.platform.commons.util.AnnotationUtils.isAnnotated) AnnotationUtils.findAnnotation(org.junit.platform.commons.util.AnnotationUtils.findAnnotation) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Arguments(org.junit.jupiter.params.provider.Arguments) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) TestTemplateInvocationContext(org.junit.jupiter.api.extension.TestTemplateInvocationContext) ExceptionUtils(org.junit.platform.commons.util.ExceptionUtils) TestTemplateInvocationContextProvider(org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider) AnnotationUtils.findRepeatableAnnotations(org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Method(java.lang.reflect.Method) AtomicLong(java.util.concurrent.atomic.AtomicLong) Arguments(org.junit.jupiter.params.provider.Arguments) Method(java.lang.reflect.Method) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)49 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)27 PatternGenerator (common.pattern.PatternGenerator)27 AnalyzeTree (common.tree.AnalyzeTree)27 LongTest (module.LongTest)16 Log (_usecase.Log)10 TestCase (com.cadenzauk.core.junit.TestCase)7 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)7 Action (common.datastore.action.Action)7 Field (core.field.Field)7 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)6 LockedCandidate (core.action.candidate.LockedCandidate)6 Piece (core.mino.Piece)5 LockedReachable (core.action.reachable.LockedReachable)4 RandomValues.randomZonedDateTime (com.cadenzauk.core.RandomValues.randomZonedDateTime)3 TestRow (com.cadenzauk.siesta.model.TestRow)3 MinoFactory (core.mino.MinoFactory)3 MinoShifter (core.mino.MinoShifter)3 MinoRotation (core.srs.MinoRotation)3