From 3bebb40887068ff6a5fad87f62372e347297ced3 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 22 Apr 2022 09:40:02 +0300 Subject: [PATCH] Support QuarkusTestResourceLifecycleManager#inject in CLI test classes Fixes: #25065 --- .../io/quarkus/it/picocli/PicocliTest.java | 40 +++++++++++++++++++ .../QuarkusMainIntegrationTestExtension.java | 2 + .../test/junit/QuarkusMainTestExtension.java | 3 ++ 3 files changed, 45 insertions(+) diff --git a/integration-tests/picocli-native/src/test/java/io/quarkus/it/picocli/PicocliTest.java b/integration-tests/picocli-native/src/test/java/io/quarkus/it/picocli/PicocliTest.java index 3d7e0a4493087..82a50a386a060 100644 --- a/integration-tests/picocli-native/src/test/java/io/quarkus/it/picocli/PicocliTest.java +++ b/integration-tests/picocli-native/src/test/java/io/quarkus/it/picocli/PicocliTest.java @@ -3,17 +3,24 @@ import static org.assertj.core.api.Assertions.assertThat; import java.net.UnknownHostException; +import java.util.Collections; +import java.util.Map; import org.junit.jupiter.api.Test; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; import io.quarkus.test.junit.main.Launch; import io.quarkus.test.junit.main.LaunchResult; import io.quarkus.test.junit.main.QuarkusMainLauncher; import io.quarkus.test.junit.main.QuarkusMainTest; @QuarkusMainTest +@QuarkusTestResource(PicocliTest.TestResource.class) public class PicocliTest { + private String value; + @Test @Launch({ "test-command", "-f", "test.txt", "-f", "test2.txt", "-f", "test3.txt", "-s", "ERROR", "-h", "SOCKS=5.5.5.5", "-p", "privateValue", "pos1", "pos2" }) @@ -23,6 +30,8 @@ public void testBasicReflection(LaunchResult result) throws UnknownHostException .contains("-p:privateValue") .contains("-p:privateValue") .contains("positional:[pos1, pos2]"); + + assertThat(value).isNotNull(); } @Test @@ -57,6 +66,8 @@ public void testIncludeLogCommand(QuarkusMainLauncher launcher) { @Launch({ "command-used-as-parent", "-p", "testValue", "child" }) public void testParentCommand(LaunchResult result) { assertThat(result.getOutput()).isEqualTo("testValue"); + + assertThat(value).isNotNull(); } @Test @@ -66,18 +77,24 @@ public void testCommandWithArgGroup(LaunchResult result) { .contains("-a:0") .contains("-b:150") .contains("-c:0"); + + assertThat(value).isNotNull(); } @Test @Launch({ "dynamic-proxy" }) public void testDynamicProxy(LaunchResult result) { assertThat(result.getOutput()).isEqualTo("2007-12-03T10:15:30"); + + assertThat(value).isNotNull(); } @Test @Launch("quarkus") public void testDynamicVersionProvider(LaunchResult launchResult) { assertThat(launchResult.getOutput()).contains("quarkus version 1.0"); + + assertThat(value).isNotNull(); } @Test @@ -88,6 +105,8 @@ public void testUnmatched(LaunchResult launchResult) { .contains("-b:null") .contains("remainder:[More]") .contains("unmatched[-x]"); + + assertThat(value).isNotNull(); } @Test @@ -110,5 +129,26 @@ public void testCompletionReflection() { @Launch("default-value-provider") public void testDefaultValueProvider(LaunchResult result) { assertThat(result.getOutput()).isEqualTo("default:default-value"); + + assertThat(value).isNotNull(); } + + public static class TestResource implements QuarkusTestResourceLifecycleManager { + + @Override + public Map start() { + return Collections.emptyMap(); + } + + @Override + public void inject(TestInjector testInjector) { + testInjector.injectIntoFields("dummy", f -> f.getName().equals("value")); + } + + @Override + public void stop() { + + } + } + } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java index 7500eb795fc7f..aed5af5a8ea86 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java @@ -135,6 +135,8 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S } additionalProperties.putAll(resourceManagerProps); + testResourceManager.inject(context.getRequiredTestInstance()); + ArtifactLauncher launcher = null; ServiceLoader loader = ServiceLoader.load(ArtifactLauncherProvider.class); for (ArtifactLauncherProvider launcherProvider : loader) { diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java index 3dc0bd64f786c..b947bf54ecb98 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java @@ -207,6 +207,9 @@ private int doJavaStart(ExtensionContext context, Class