Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for additional configuration parameters resources #3345

Merged
Prev Previous commit
Next Next commit
ConsoleLauncher options for conf param resource
  • Loading branch information
robinjhector committed Jul 3, 2024
commit 5b942d54e410ed874c09ddf93a642f9fd5fc95cf
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@ $ java -jar junit-platform-console-standalone-{platform-version}.jar <OPTIONS> \
--config=junit.platform.reporting.open.xml.enabled=true \
--config=junit.platform.reporting.output.dir=reports
----

Configuration parameters can also be set via a resource path file, by specifying the
`--config-resource` option:
robinjhector marked this conversation as resolved.
Show resolved Hide resolved

[source,console,subs=attributes+]
----
$ java -jar junit-platform-console-standalone-{platform-version}.jar <OPTIONS> \
--config-resource=configuration.properties
----
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ static class RuntimeConfigurationOptions {
// Implementation note: the @Option annotation is on a setter method to allow validation.
private final Map<String, String> configurationParameters = new LinkedHashMap<>();

@Option(names = {
"--config-resource" }, paramLabel = "PATH", arity = "1", description = "Set configuration parameters for test discovery and execution, from a resource file. This option can be repeated.")
robinjhector marked this conversation as resolved.
Show resolved Hide resolved
private List<String> configurationParametersResources = new ArrayList<>();

@Option(names = { "-config-resource" }, arity = "1", hidden = true)
private List<String> configurationParametersResources2 = new ArrayList<>();
marcphilipp marked this conversation as resolved.
Show resolved Hide resolved

@CommandLine.Spec
private CommandLine.Model.CommandSpec spec;

Expand Down Expand Up @@ -296,6 +303,8 @@ private void validateUnique(String key, String newValue) {

private void applyTo(TestDiscoveryOptions result) {
result.setAdditionalClasspathEntries(merge(additionalClasspathEntries, additionalClasspathEntries2));
result.setConfigurationParametersResources(
merge(configurationParametersResources, configurationParametersResources2));
marcphilipp marked this conversation as resolved.
Show resolved Hide resolved
result.setConfigurationParameters(configurationParameters);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,33 @@ void parseValidConfigurationParameters(ArgsType type) {
// @formatter:on
}

@ParameterizedTest
@EnumSource
void parseValidConfigurationParametersResource(ArgsType type) {
// @formatter:off
assertAll(
() -> assertThat(type.parseArgLine("-config-resource foo.properties").discovery.getConfigurationParametersResources())
.containsOnly("foo.properties"),
() -> assertThat(type.parseArgLine("--config-resource foo.properties").discovery.getConfigurationParametersResources())
.containsOnly("foo.properties"),
() -> assertThat(type.parseArgLine("-config-resource foo.properties -config-resource bar.properties").discovery.getConfigurationParametersResources())
.containsExactly("foo.properties", "bar.properties"),
() -> assertThat(type.parseArgLine("--config-resource foo.properties --config-resource bar.properties").discovery.getConfigurationParametersResources())
.containsExactly("foo.properties", "bar.properties")
);
// @formatter:on
}

@Test
void parseInvalidConfigurationParameters() {
assertOptionWithMissingRequiredArgumentThrowsException("-config", "--config");
}

@Test
void parseInvalidConfigurationParametersResource() {
assertOptionWithMissingRequiredArgumentThrowsException("-config-resource", "--config-resource");
}

@ParameterizedTest
@EnumSource
void parseInvalidConfigurationParametersWithDuplicateKey(ArgsType type) {
Expand Down