use of org.junit.jupiter.params.provider.Arguments in project spring-framework by spring-projects.
the class ClientHttpConnectorTests method basic.
// Do not auto-close arguments since HttpComponentsClientHttpConnector implements
// AutoCloseable and is shared between parameterized test invocations.
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("org.springframework.http.client.reactive.ClientHttpConnectorTests#methodsWithConnectors")
void basic(ClientHttpConnector connector, HttpMethod method) throws Exception {
URI uri = this.server.url("/").uri();
String responseBody = "bar\r\n";
prepareResponse(response -> {
response.setResponseCode(200);
response.addHeader("Baz", "Qux");
response.setBody(responseBody);
});
String requestBody = "foo\r\n";
boolean requestHasBody = METHODS_WITH_BODY.contains(method);
Mono<ClientHttpResponse> futureResponse = connector.connect(method, uri, request -> {
assertThat(request.getMethod()).isEqualTo(method);
assertThat(request.getURI()).isEqualTo(uri);
request.getHeaders().add("Foo", "Bar");
if (requestHasBody) {
Mono<DataBuffer> body = Mono.fromCallable(() -> {
byte[] bytes = requestBody.getBytes(StandardCharsets.UTF_8);
return DefaultDataBufferFactory.sharedInstance.wrap(bytes);
});
return request.writeWith(body);
} else {
return request.setComplete();
}
});
CountDownLatch latch = new CountDownLatch(1);
StepVerifier.create(futureResponse).assertNext(response -> {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().getFirst("Baz")).isEqualTo("Qux");
DataBufferUtils.join(response.getBody()).map(buffer -> {
String s = buffer.toString(StandardCharsets.UTF_8);
DataBufferUtils.release(buffer);
return s;
}).subscribe(s -> assertThat(s).isEqualTo(responseBody), throwable -> {
latch.countDown();
fail(throwable.getMessage(), throwable);
}, latch::countDown);
}).verifyComplete();
latch.await();
expectRequest(request -> {
assertThat(request.getMethod()).isEqualTo(method.name());
assertThat(request.getHeader("Foo")).isEqualTo("Bar");
if (requestHasBody) {
assertThat(request.getBody().readUtf8()).isEqualTo(requestBody);
}
});
}
use of org.junit.jupiter.params.provider.Arguments in project dhis2-core by dhis2.
the class MetadataImportBasedOnSchemasTest method getSchemaEndpoints.
private Stream<Arguments> getSchemaEndpoints() {
ApiResponse apiResponse = schemasActions.get();
String jsonPathIdentifier = "schemas.findAll{it.relativeApiEndpoint && it.metadata && it.singular != 'externalFileResource'}";
List<String> apiEndpoints = apiResponse.extractList(jsonPathIdentifier + ".plural");
List<String> schemaEndpoints = apiResponse.extractList(jsonPathIdentifier + ".singular");
List<Arguments> arguments = new ArrayList<>();
for (int i = 0; i < apiEndpoints.size(); i++) {
arguments.add(Arguments.of(apiEndpoints.get(i), schemaEndpoints.get(i)));
}
return arguments.stream();
}
use of org.junit.jupiter.params.provider.Arguments in project judge by zjnu-acm.
the class JudgeBridgeGroovyTest method data.
public static List<Arguments> data() throws Exception {
Checker[] values = Checker.values();
ArrayList<Arguments> list = new ArrayList<>(values.length);
for (Checker checker : values) {
Path path = program.resolve(checker.name());
Files.list(path).filter(p -> p.getFileName().toString().endsWith(".groovy")).map(Object::toString).forEach(executable -> list.add(arguments(checker, executable)));
}
return list;
}
use of org.junit.jupiter.params.provider.Arguments in project junit5 by junit-team.
the class ParameterizedTestExtension method provideTestTemplateInvocationContexts.
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext extensionContext) {
Method templateMethod = extensionContext.getRequiredTestMethod();
String displayName = extensionContext.getDisplayName();
ParameterizedTestMethodContext methodContext = //
getStore(extensionContext).get(METHOD_CONTEXT_KEY, ParameterizedTestMethodContext.class);
int argumentMaxLength = extensionContext.getConfigurationParameter(ARGUMENT_MAX_LENGTH_KEY, Integer::parseInt).orElse(512);
ParameterizedTestNameFormatter formatter = createNameFormatter(extensionContext, templateMethod, methodContext, displayName, argumentMaxLength);
AtomicLong invocationCount = new AtomicLong(0);
// @formatter:off
return findRepeatableAnnotations(templateMethod, ArgumentsSource.class).stream().map(ArgumentsSource::value).map(this::instantiateArgumentsProvider).map(provider -> AnnotationConsumerInitializer.initialize(templateMethod, provider)).flatMap(provider -> arguments(provider, extensionContext)).map(Arguments::get).map(arguments -> consumedArguments(arguments, methodContext)).map(arguments -> {
invocationCount.incrementAndGet();
return createInvocationContext(formatter, methodContext, arguments);
}).onClose(() -> Preconditions.condition(invocationCount.get() > 0, "Configuration error: You must configure at least one set of arguments for this @ParameterizedTest"));
// @formatter:on
}
Aggregations