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

Support QuarkusTestResourceLifecycleManager#inject in CLI test classes #25085

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -88,6 +105,8 @@ public void testUnmatched(LaunchResult launchResult) {
.contains("-b:null")
.contains("remainder:[More]")
.contains("unmatched[-x]");

assertThat(value).isNotNull();
}

@Test
Expand All @@ -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<String, String> start() {
return Collections.emptyMap();
}

@Override
public void inject(TestInjector testInjector) {
testInjector.injectIntoFields("dummy", f -> f.getName().equals("value"));
}

@Override
public void stop() {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S
}
additionalProperties.putAll(resourceManagerProps);

testResourceManager.inject(context.getRequiredTestInstance());

ArtifactLauncher<?> launcher = null;
ServiceLoader<ArtifactLauncherProvider> loader = ServiceLoader.load(ArtifactLauncherProvider.class);
for (ArtifactLauncherProvider launcherProvider : loader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ private int doJavaStart(ExtensionContext context, Class<? extends QuarkusTestPro
hasPerTestResources = (boolean) testResourceManager.getClass().getMethod("hasPerTestResources")
.invoke(testResourceManager);

testResourceManager.getClass().getMethod("inject", Object.class)
.invoke(testResourceManager, context.getRequiredTestInstance());

var result = startupAction.runMainClassBlocking(arguments);
flushAllLoggers();
return result;
Expand Down