diff --git a/integration-tests/test-extension/tests/pom.xml b/integration-tests/test-extension/tests/pom.xml index 923923ac414b2..37f0c9eb05582 100644 --- a/integration-tests/test-extension/tests/pom.xml +++ b/integration-tests/test-extension/tests/pom.xml @@ -109,6 +109,7 @@ ${project.build.directory}/recorded-classpath-entries-failsafe.txt + test diff --git a/integration-tests/test-extension/tests/src/main/java/io/quarkus/it/extension/SystemPropertyTestEndpoint.java b/integration-tests/test-extension/tests/src/main/java/io/quarkus/it/extension/SystemPropertyTestEndpoint.java new file mode 100644 index 0000000000000..b36bd688e728e --- /dev/null +++ b/integration-tests/test-extension/tests/src/main/java/io/quarkus/it/extension/SystemPropertyTestEndpoint.java @@ -0,0 +1,18 @@ +package io.quarkus.it.extension; + +import java.io.IOException; + +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(name = "SystemPropertyTestEndpoint", urlPatterns = "/core/sysprop") +public class SystemPropertyTestEndpoint extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + resp.getWriter().write(System.getProperty("quarkus.dymmy", "unset")); + } + +} diff --git a/integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/SystemPropertyGraalITCase.java b/integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/SystemPropertyGraalITCase.java new file mode 100644 index 0000000000000..be370811db0fe --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/SystemPropertyGraalITCase.java @@ -0,0 +1,18 @@ +package io.quarkus.it.extension; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class SystemPropertyGraalITCase { + + @Test + public void test() { + when().get("/core/sysprop").then() + .body(is("test")); + } +} diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index a9e7a071ddc6d..0aad608c0c2a6 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -213,7 +213,17 @@ private QuarkusTestExtensionState doProcessStart(Properties quarkusArtifactPrope populateCallbacks(requiredTestClass.getClassLoader()); } - Map additionalProperties = new HashMap<>(testProfileAndProperties.properties); + Map additionalProperties = new HashMap<>(); + + // propagate Quarkus properties set from the build tool + Properties existingSysProps = System.getProperties(); + for (String name : existingSysProps.stringPropertyNames()) { + if (name.startsWith("quarkus.")) { + additionalProperties.put(name, existingSysProps.getProperty(name)); + } + } + + additionalProperties.putAll(testProfileAndProperties.properties); Map resourceManagerProps = new HashMap<>(testResourceManager.start()); //we also make the dev services config accessible from the test itself resourceManagerProps.putAll(QuarkusIntegrationTestExtension.devServicesProps); 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 61e70d56f0fca..beb213367a61c 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 @@ -126,7 +126,18 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S testResourceManager.init( testProfileAndProperties.testProfile != null ? testProfileAndProperties.testProfile.getClass().getName() : null); - Map additionalProperties = new HashMap<>(testProfileAndProperties.properties); + + Map additionalProperties = new HashMap<>(); + + // propagate Quarkus properties set from the build tool + Properties existingSysProps = System.getProperties(); + for (String name : existingSysProps.stringPropertyNames()) { + if (name.startsWith("quarkus.")) { + additionalProperties.put(name, existingSysProps.getProperty(name)); + } + } + + additionalProperties.putAll(testProfileAndProperties.properties); Map resourceManagerProps = new HashMap<>(testResourceManager.start()); //also make the dev services props accessible from the test resourceManagerProps.putAll(QuarkusMainIntegrationTestExtension.devServicesProps);