Search in sources :

Example 6 with Arguments

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

the class ParameterizedTestExtensionTests method argumentsRethrowsOriginalExceptionFromProviderAsUncheckedException.

@Test
void argumentsRethrowsOriginalExceptionFromProviderAsUncheckedException() {
    ArgumentsProvider failingProvider = (context) -> {
        throw new FileNotFoundException("a message");
    };
    var exception = assertThrows(FileNotFoundException.class, () -> arguments(failingProvider, null));
    assertEquals("a message", exception.getMessage());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ParameterizedTestExtension.arguments(org.junit.jupiter.params.ParameterizedTestExtension.arguments) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Function(java.util.function.Function) TestInstances(org.junit.jupiter.api.extension.TestInstances) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExecutableInvoker(org.junit.jupiter.api.extension.ExecutableInvoker) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) Method(java.lang.reflect.Method) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) JUnitException(org.junit.platform.commons.JUnitException) Set(java.util.Set) Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) Arguments(org.junit.jupiter.params.provider.Arguments) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.jupiter.api.Test) NamespaceAwareStore(org.junit.jupiter.engine.execution.NamespaceAwareStore) ExtensionValuesStore(org.junit.jupiter.engine.execution.ExtensionValuesStore) Stream(java.util.stream.Stream) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) AnnotatedElement(java.lang.reflect.AnnotatedElement) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.jupiter.api.Test)

Example 7 with Arguments

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

the class DateFunctionsTest method parametersForFunctionTest.

@SuppressWarnings("unused")
private static Stream<Arguments> parametersForFunctionTest() {
    LocalDate randomLocalDate = RandomValues.randomLocalDate();
    LocalDateTime randomLocalDateTime = RandomValues.randomLocalDateTime();
    ZonedDateTime randomZonedDateTime = RandomValues.randomZonedDateTime(ZoneId.systemDefault());
    return Stream.of(testCase(s -> DateFunctions.currentDate(), "current_date", toArray()), testCase(s -> DateFunctions.currentTimestampLocal(), "current_timestamp", toArray()), testCase(s -> DateFunctions.currentTimestamp(), "current_timestamp", toArray()), testCase(s -> year(randomLocalDate), "year(cast(? as date))", toArray(Date.valueOf(randomLocalDate))), testCase(s -> year(randomLocalDateTime), "year(cast(? as timestamp))", toArray(Timestamp.valueOf(randomLocalDateTime))), testCase(s -> year(randomZonedDateTime), "year(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> year(TypedExpression.value(randomZonedDateTime)), "year(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> year(TestRow::localDateReq), "year(s.LOCAL_DATE_REQ)", toArray()), testCase(s -> year(TestRow::localDateOpt), "year(s.LOCAL_DATE_OPT)", toArray()), testCase(s -> year("s", TestRow::localDateReq), "year(s.LOCAL_DATE_REQ)", toArray()), testCase(s -> year("s", TestRow::localDateOpt), "year(s.LOCAL_DATE_OPT)", toArray()), testCase(s -> year(s, TestRow::localDateReq), "year(s.LOCAL_DATE_REQ)", toArray()), testCase(s -> year(s, TestRow::localDateOpt), "year(s.LOCAL_DATE_OPT)", toArray()), testCase(s -> month(randomLocalDate), "month(cast(? as date))", toArray(Date.valueOf(randomLocalDate))), testCase(s -> month(randomLocalDateTime), "month(cast(? as timestamp))", toArray(Timestamp.valueOf(randomLocalDateTime))), testCase(s -> month(randomZonedDateTime), "month(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> month(TypedExpression.value(randomZonedDateTime)), "month(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> month(TestRow::localDateTimeReq), "month(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> month(TestRow::localDateTimeOpt), "month(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> month("s", TestRow::localDateTimeReq), "month(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> month("s", TestRow::localDateTimeOpt), "month(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> month(s, TestRow::localDateTimeReq), "month(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> month(s, TestRow::localDateTimeOpt), "month(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> day(randomLocalDate), "day(cast(? as date))", toArray(Date.valueOf(randomLocalDate))), testCase(s -> day(randomLocalDateTime), "day(cast(? as timestamp))", toArray(Timestamp.valueOf(randomLocalDateTime))), testCase(s -> day(randomZonedDateTime), "day(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> day(TypedExpression.value(randomZonedDateTime)), "day(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> day(TestRow::utcDateTimeReq), "day(s.UTC_DATE_TIME_REQ)", toArray()), testCase(s -> day(TestRow::utcDateTimeOpt), "day(s.UTC_DATE_TIME_OPT)", toArray()), testCase(s -> day("s", TestRow::utcDateTimeReq), "day(s.UTC_DATE_TIME_REQ)", toArray()), testCase(s -> day("s", TestRow::utcDateTimeOpt), "day(s.UTC_DATE_TIME_OPT)", toArray()), testCase(s -> day(s, TestRow::utcDateTimeReq), "day(s.UTC_DATE_TIME_REQ)", toArray()), testCase(s -> day(s, TestRow::utcDateTimeOpt), "day(s.UTC_DATE_TIME_OPT)", toArray()), testCase(s -> hour(randomLocalDateTime), "hour(cast(? as timestamp))", toArray(Timestamp.valueOf(randomLocalDateTime))), testCase(s -> hour(randomZonedDateTime), "hour(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> hour(TypedExpression.value(randomZonedDateTime)), "hour(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> hour(TestRow::localDateTimeReq), "hour(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> hour(TestRow::localDateTimeOpt), "hour(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> hour("s", TestRow::localDateTimeReq), "hour(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> hour("s", TestRow::localDateTimeOpt), "hour(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> hour(s, TestRow::localDateTimeReq), "hour(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> hour(s, TestRow::localDateTimeOpt), "hour(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> minute(randomLocalDateTime), "minute(cast(? as timestamp))", toArray(Timestamp.valueOf(randomLocalDateTime))), testCase(s -> minute(randomZonedDateTime), "minute(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> minute(TypedExpression.value(randomZonedDateTime)), "minute(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> minute(TestRow::utcDateTimeReq), "minute(s.UTC_DATE_TIME_REQ)", toArray()), testCase(s -> minute(TestRow::utcDateTimeOpt), "minute(s.UTC_DATE_TIME_OPT)", toArray()), testCase(s -> minute("s", TestRow::utcDateTimeReq), "minute(s.UTC_DATE_TIME_REQ)", toArray()), testCase(s -> minute("s", TestRow::utcDateTimeOpt), "minute(s.UTC_DATE_TIME_OPT)", toArray()), testCase(s -> minute(s, TestRow::utcDateTimeReq), "minute(s.UTC_DATE_TIME_REQ)", toArray()), testCase(s -> minute(s, TestRow::utcDateTimeOpt), "minute(s.UTC_DATE_TIME_OPT)", toArray()), testCase(s -> second(randomLocalDateTime), "second(cast(? as timestamp))", toArray(Timestamp.valueOf(randomLocalDateTime))), testCase(s -> second(randomZonedDateTime), "second(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> second(TypedExpression.value(randomZonedDateTime)), "second(cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> second(TestRow::localDateTimeReq), "second(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> second(TestRow::localDateTimeOpt), "second(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> second("s", TestRow::localDateTimeReq), "second(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> second("s", TestRow::localDateTimeOpt), "second(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> second(s, TestRow::localDateTimeReq), "second(s.LOCAL_DATE_TIME_REQ)", toArray()), testCase(s -> second(s, TestRow::localDateTimeOpt), "second(s.LOCAL_DATE_TIME_OPT)", toArray()), testCase(s -> addDays(TypedExpression.value(randomZonedDateTime), 1), "dateadd(day, ?, cast(? as timestamp))", toArray(1, Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> addDays(TypedExpression.value(randomZonedDateTime), literal(4)), "dateadd(day, 4, cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> addDays(TestRow::localDateTimeReq, 1), "dateadd(day, ?, s.LOCAL_DATE_TIME_REQ)", toArray(1)), testCase(s -> addDays(TestRow::localDateTimeOpt, 1), "dateadd(day, ?, s.LOCAL_DATE_TIME_OPT)", toArray(1)), testCase(s -> addDays("s", TestRow::localDateTimeReq, 2), "dateadd(day, ?, s.LOCAL_DATE_TIME_REQ)", toArray(2)), testCase(s -> addDays("s", TestRow::localDateTimeOpt, 2), "dateadd(day, ?, s.LOCAL_DATE_TIME_OPT)", toArray(2)), testCase(s -> addDays(s, TestRow::localDateTimeReq, 3), "dateadd(day, ?, s.LOCAL_DATE_TIME_REQ)", toArray(3)), testCase(s -> addDays(s, TestRow::localDateTimeOpt, 3), "dateadd(day, ?, s.LOCAL_DATE_TIME_OPT)", toArray(3)), testCase(s -> secondDiff(TypedExpression.value(randomZonedDateTime), literal(LocalDate.of(2013, 12, 25))), "datediff(second, DATE '2013-12-25', cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> secondDiff(TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(second, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> secondDiff(TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(second, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> secondDiff("s", TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(second, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> secondDiff("s", TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(second, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> secondDiff(s, TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(second, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> secondDiff(s, TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(second, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> minuteDiff(TypedExpression.value(randomZonedDateTime), literal(LocalDate.of(2013, 12, 25))), "datediff(minute, DATE '2013-12-25', cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> minuteDiff(TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(minute, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> minuteDiff(TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(minute, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> minuteDiff("s", TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(minute, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> minuteDiff("s", TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(minute, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> minuteDiff(s, TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(minute, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> minuteDiff(s, TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(minute, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> hourDiff(TypedExpression.value(randomZonedDateTime), literal(LocalDate.of(2013, 12, 25))), "datediff(hour, DATE '2013-12-25', cast(? as timestamp))", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> hourDiff(TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(hour, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> hourDiff(TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(hour, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> hourDiff("s", TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(hour, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> hourDiff("s", TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(hour, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> hourDiff(s, TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "datediff(hour, cast(? as date), s.LOCAL_DATE_TIME_REQ)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> hourDiff(s, TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "datediff(hour, cast(? as date), s.LOCAL_DATE_TIME_OPT)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> dayDiff(TypedExpression.value(randomZonedDateTime), literal(LocalDate.of(2013, 12, 25))), "cast(? as timestamp) - DATE '2013-12-25'", toArray(Timestamp.valueOf(randomZonedDateTime.toLocalDateTime()))), testCase(s -> dayDiff(TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "s.LOCAL_DATE_TIME_REQ - cast(? as date)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> dayDiff(TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "s.LOCAL_DATE_TIME_OPT - cast(? as date)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> dayDiff("s", TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "s.LOCAL_DATE_TIME_REQ - cast(? as date)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> dayDiff("s", TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "s.LOCAL_DATE_TIME_OPT - cast(? as date)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> dayDiff(s, TestRow::localDateTimeReq, LocalDate.of(2013, 12, 25)), "s.LOCAL_DATE_TIME_REQ - cast(? as date)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))), testCase(s -> dayDiff(s, TestRow::localDateTimeOpt, LocalDate.of(2013, 12, 25)), "s.LOCAL_DATE_TIME_OPT - cast(? as date)", toArray(Date.valueOf(LocalDate.of(2013, 12, 25)))));
}
Also used : LocalDateTime(java.time.LocalDateTime) TestRow(com.cadenzauk.siesta.model.TestRow) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) TypedExpression.literal(com.cadenzauk.siesta.grammar.expression.TypedExpression.literal) DateFunctions.month(com.cadenzauk.siesta.grammar.expression.DateFunctions.month) DateFunctions.hourDiff(com.cadenzauk.siesta.grammar.expression.DateFunctions.hourDiff) DateFunctions.second(com.cadenzauk.siesta.grammar.expression.DateFunctions.second) DateFunctions.year(com.cadenzauk.siesta.grammar.expression.DateFunctions.year) DateFunctions.minuteDiff(com.cadenzauk.siesta.grammar.expression.DateFunctions.minuteDiff) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DateFunctions.addDays(com.cadenzauk.siesta.grammar.expression.DateFunctions.addDays) RandomValues(com.cadenzauk.core.RandomValues) Timestamp(java.sql.Timestamp) DateFunctions.day(com.cadenzauk.siesta.grammar.expression.DateFunctions.day) Arguments(org.junit.jupiter.params.provider.Arguments) ZoneId(java.time.ZoneId) Date(java.sql.Date) Test(org.junit.jupiter.api.Test) DateFunctions.secondDiff(com.cadenzauk.siesta.grammar.expression.DateFunctions.secondDiff) Stream(java.util.stream.Stream) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) LocalDate(java.time.LocalDate) DateFunctions.hour(com.cadenzauk.siesta.grammar.expression.DateFunctions.hour) DateFunctions.minute(com.cadenzauk.siesta.grammar.expression.DateFunctions.minute) IsUtilityClass.isUtilityClass(com.cadenzauk.core.testutil.IsUtilityClass.isUtilityClass) DateFunctions.dayDiff(com.cadenzauk.siesta.grammar.expression.DateFunctions.dayDiff) ZonedDateTime(java.time.ZonedDateTime) TestRow(com.cadenzauk.siesta.model.TestRow) LocalDate(java.time.LocalDate)

Example 8 with Arguments

use of org.junit.jupiter.params.provider.Arguments in project jmeter by apache.

the class ParallelResourcesAndIpSource method implementationsAndIps.

public static Iterable<Arguments> implementationsAndIps() throws SocketException {
    List<Arguments> res = new ArrayList<>();
    // Caveat: 127.0.0.1
    InetAddress local4 = null;
    InetAddress local6 = null;
    List<InetAddress> localIps = Collections.list(NetworkInterface.getNetworkInterfaces()).stream().filter(networkInterface -> {
        try {
            return networkInterface.isLoopback();
        } catch (SocketException e) {
            return false;
        }
    }).flatMap(ni -> ni.getInterfaceAddresses().stream()).map(InterfaceAddress::getAddress).collect(Collectors.toList());
    // We don't want to have accidental O(N^2) in case there are lots of source IPs
    // So we use just two for the source IP
    // So we shuffle them to use different ones every time
    Collections.shuffle(localIps);
    for (InetAddress localIp : localIps) {
        if (local4 == null && localIp instanceof Inet4Address) {
            local4 = localIp;
        } else if (local6 == null && localIp instanceof Inet6Address) {
            local6 = localIp;
        }
    }
    // This is to allow the variables for use in lambda below (the vars should be effectively final)
    InetAddress finalLocal4 = local4;
    InetAddress finalLocal6 = local6;
    // This is to make test names pretty
    localIps.sort(Comparator.comparing(InetAddress::toString));
    for (String impl : HTTPSamplerFactory.getImplementations()) {
        for (String targetHost : new String[] { "127.0.0.1", "[::1]", "localhost" }) {
            if ("localhost".equals(targetHost)) {
                // with the given source IP
                continue;
            }
            localIps.forEach(localIp -> {
                if (finalLocal4 != null) {
                    res.add(arguments(impl, targetHost, finalLocal4));
                }
                if (finalLocal6 != null) {
                    res.add(arguments(impl, targetHost, finalLocal6));
                }
            });
        }
    }
    return res;
}
Also used : JMeterContextExtension(org.apache.jmeter.util.JMeterContextExtension) BugId(org.apache.jmeter.testkit.BugId) SampleResult(org.apache.jmeter.samplers.SampleResult) ArrayList(java.util.ArrayList) WireMock(com.github.tomakehurst.wiremock.client.WireMock) InetAddress(java.net.InetAddress) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) SocketException(java.net.SocketException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) MethodSource(org.junit.jupiter.params.provider.MethodSource) InterfaceAddress(java.net.InterfaceAddress) WireMockExtension(org.apache.jmeter.wiremock.WireMockExtension) NetworkInterface(java.net.NetworkInterface) Arguments(org.junit.jupiter.params.provider.Arguments) Inet4Address(java.net.Inet4Address) Collectors(java.util.stream.Collectors) FunctionProperty(org.apache.jmeter.testelement.property.FunctionProperty) TestInfo(org.junit.jupiter.api.TestInfo) Inet6Address(java.net.Inet6Address) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Assumptions(org.junit.jupiter.api.Assumptions) LagartoBasedHtmlParser(org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser) Assertions(org.junit.jupiter.api.Assertions) Comparator(java.util.Comparator) Collections(java.util.Collections) HTTPConstants(org.apache.jmeter.protocol.http.util.HTTPConstants) SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) Arguments(org.junit.jupiter.params.provider.Arguments) ArrayList(java.util.ArrayList) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 9 with Arguments

use of org.junit.jupiter.params.provider.Arguments in project kafka by apache.

the class ApiErrorTest method parameters.

private static Collection<Arguments> parameters() {
    List<Arguments> arguments = new ArrayList<>();
    arguments.add(Arguments.of(new UnknownServerException("Don't leak sensitive information "), Errors.UNKNOWN_SERVER_ERROR, null));
    arguments.add(Arguments.of(new NotEnoughReplicasException(), Errors.NOT_ENOUGH_REPLICAS, null));
    // avoid populating the error message if it's a generic one
    arguments.add(Arguments.of(new UnknownTopicOrPartitionException(Errors.UNKNOWN_TOPIC_OR_PARTITION.message()), Errors.UNKNOWN_TOPIC_OR_PARTITION, null));
    String notCoordinatorErrorMsg = "Not coordinator";
    arguments.add(Arguments.of(new NotCoordinatorException(notCoordinatorErrorMsg), Errors.NOT_COORDINATOR, notCoordinatorErrorMsg));
    String notControllerErrorMsg = "Not controller";
    // test the NotControllerException is wrapped in the CompletionException, should return correct error
    arguments.add(Arguments.of(new CompletionException(new NotControllerException(notControllerErrorMsg)), Errors.NOT_CONTROLLER, notControllerErrorMsg));
    String requestTimeoutErrorMsg = "request time out";
    // test the TimeoutException is wrapped in the ExecutionException, should return correct error
    arguments.add(Arguments.of(new ExecutionException(new TimeoutException(requestTimeoutErrorMsg)), Errors.REQUEST_TIMED_OUT, requestTimeoutErrorMsg));
    // test the exception not in the Errors list, should return UNKNOWN_SERVER_ERROR
    arguments.add(Arguments.of(new IOException(), Errors.UNKNOWN_SERVER_ERROR, null));
    return arguments;
}
Also used : NotCoordinatorException(org.apache.kafka.common.errors.NotCoordinatorException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Arguments(org.junit.jupiter.params.provider.Arguments) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) CompletionException(java.util.concurrent.CompletionException) NotEnoughReplicasException(org.apache.kafka.common.errors.NotEnoughReplicasException) ExecutionException(java.util.concurrent.ExecutionException) NotControllerException(org.apache.kafka.common.errors.NotControllerException) TimeoutException(org.apache.kafka.common.errors.TimeoutException)

Example 10 with Arguments

use of org.junit.jupiter.params.provider.Arguments in project kafka by apache.

the class HeaderFromTest method data.

public static List<Arguments> data() {
    List<Arguments> result = new ArrayList<>();
    for (Boolean testKeyTransform : asList(true, false)) {
        result.add(Arguments.of("basic copy", testKeyTransform, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value"), singletonList("field1"), singletonList("inserted1"), HeaderFrom.Operation.COPY, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value").addHeader("inserted1", STRING_SCHEMA, "field1-value")));
        result.add(Arguments.of("basic move", testKeyTransform, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value"), singletonList("field1"), singletonList("inserted1"), HeaderFrom.Operation.MOVE, new RecordBuilder().withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value").addHeader("inserted1", STRING_SCHEMA, "field1-value")));
        result.add(Arguments.of("copy with preexisting header", testKeyTransform, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("inserted1", STRING_SCHEMA, "existing-value"), singletonList("field1"), singletonList("inserted1"), HeaderFrom.Operation.COPY, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("inserted1", STRING_SCHEMA, "existing-value").addHeader("inserted1", STRING_SCHEMA, "field1-value")));
        result.add(Arguments.of("move with preexisting header", testKeyTransform, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("inserted1", STRING_SCHEMA, "existing-value"), singletonList("field1"), singletonList("inserted1"), HeaderFrom.Operation.MOVE, new RecordBuilder().withField("field2", STRING_SCHEMA, "field2-value").addHeader("inserted1", STRING_SCHEMA, "existing-value").addHeader("inserted1", STRING_SCHEMA, "field1-value")));
        Schema schema = new SchemaBuilder(Schema.Type.STRUCT).field("foo", STRING_SCHEMA).build();
        Struct struct = new Struct(schema).put("foo", "foo-value");
        result.add(Arguments.of("copy with struct value", testKeyTransform, new RecordBuilder().withField("field1", schema, struct).withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value"), singletonList("field1"), singletonList("inserted1"), HeaderFrom.Operation.COPY, new RecordBuilder().withField("field1", schema, struct).withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value").addHeader("inserted1", schema, struct)));
        result.add(Arguments.of("move with struct value", testKeyTransform, new RecordBuilder().withField("field1", schema, struct).withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value"), singletonList("field1"), singletonList("inserted1"), HeaderFrom.Operation.MOVE, new RecordBuilder().withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value").addHeader("inserted1", schema, struct)));
        result.add(Arguments.of("two headers from same field", testKeyTransform, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value"), // two headers from the same field
        asList("field1", "field1"), asList("inserted1", "inserted2"), HeaderFrom.Operation.MOVE, new RecordBuilder().withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value").addHeader("inserted1", STRING_SCHEMA, "field1-value").addHeader("inserted2", STRING_SCHEMA, "field1-value")));
        result.add(Arguments.of("two fields to same header", testKeyTransform, new RecordBuilder().withField("field1", STRING_SCHEMA, "field1-value").withField("field2", STRING_SCHEMA, "field2-value").addHeader("header1", STRING_SCHEMA, "existing-value"), // two headers from the same field
        asList("field1", "field2"), asList("inserted1", "inserted1"), HeaderFrom.Operation.MOVE, new RecordBuilder().addHeader("header1", STRING_SCHEMA, "existing-value").addHeader("inserted1", STRING_SCHEMA, "field1-value").addHeader("inserted1", STRING_SCHEMA, "field2-value")));
    }
    return result;
}
Also used : Schema(org.apache.kafka.connect.data.Schema) Arguments(org.junit.jupiter.params.provider.Arguments) ArrayList(java.util.ArrayList) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Struct(org.apache.kafka.connect.data.Struct)

Aggregations

Arguments (org.junit.jupiter.params.provider.Arguments)14 ArrayList (java.util.ArrayList)11 Arrays (java.util.Arrays)3 Stream (java.util.stream.Stream)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 Path (java.nio.file.Path)2 List (java.util.List)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 RandomValues (com.cadenzauk.core.RandomValues)1 IsUtilityClass.isUtilityClass (com.cadenzauk.core.testutil.IsUtilityClass.isUtilityClass)1 DateFunctions.addDays (com.cadenzauk.siesta.grammar.expression.DateFunctions.addDays)1 DateFunctions.day (com.cadenzauk.siesta.grammar.expression.DateFunctions.day)1 DateFunctions.dayDiff (com.cadenzauk.siesta.grammar.expression.DateFunctions.dayDiff)1 DateFunctions.hour (com.cadenzauk.siesta.grammar.expression.DateFunctions.hour)1 DateFunctions.hourDiff (com.cadenzauk.siesta.grammar.expression.DateFunctions.hourDiff)1 DateFunctions.minute (com.cadenzauk.siesta.grammar.expression.DateFunctions.minute)1 DateFunctions.minuteDiff (com.cadenzauk.siesta.grammar.expression.DateFunctions.minuteDiff)1 DateFunctions.month (com.cadenzauk.siesta.grammar.expression.DateFunctions.month)1