Skip to content

Commit 4f02922

Browse files
committed
Propagate Quarkus related failsafe system properties
Closes: #31405
1 parent cb1c4f0 commit 4f02922

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

integration-tests/test-extension/tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<systemPropertyVariables>
110110
<!-- See io.quarkus.extest.runtime.classpath.RecordedClasspathEntries -->
111111
<classpathEntriesRecordingFile>${project.build.directory}/recorded-classpath-entries-failsafe.txt</classpathEntriesRecordingFile>
112+
<quarkus.dymmy>test</quarkus.dymmy>
112113
</systemPropertyVariables>
113114
</configuration>
114115
</plugin>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.quarkus.it.extension;
2+
3+
import java.io.IOException;
4+
5+
import jakarta.servlet.annotation.WebServlet;
6+
import jakarta.servlet.http.HttpServlet;
7+
import jakarta.servlet.http.HttpServletRequest;
8+
import jakarta.servlet.http.HttpServletResponse;
9+
10+
@WebServlet(name = "SystemPropertyTestEndpoint", urlPatterns = "/core/sysprop")
11+
public class SystemPropertyTestEndpoint extends HttpServlet {
12+
13+
@Override
14+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
15+
resp.getWriter().write(System.getProperty("quarkus.dymmy", "unset"));
16+
}
17+
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.quarkus.it.extension;
2+
3+
import static io.restassured.RestAssured.when;
4+
import static org.hamcrest.Matchers.is;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import io.quarkus.test.junit.QuarkusIntegrationTest;
9+
10+
@QuarkusIntegrationTest
11+
public class SystemPropertyGraalITCase {
12+
13+
@Test
14+
public void test() {
15+
when().get("/core/sysprop").then()
16+
.body(is("test"));
17+
}
18+
}

test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,17 @@ private QuarkusTestExtensionState doProcessStart(Properties quarkusArtifactPrope
213213
populateCallbacks(requiredTestClass.getClassLoader());
214214
}
215215

216-
Map<String, String> additionalProperties = new HashMap<>(testProfileAndProperties.properties);
216+
Map<String, String> additionalProperties = new HashMap<>();
217+
218+
// propagate Quarkus properties set from the build tool
219+
Properties existingSysProps = System.getProperties();
220+
for (String name : existingSysProps.stringPropertyNames()) {
221+
if (name.startsWith("quarkus.")) {
222+
additionalProperties.put(name, existingSysProps.getProperty(name));
223+
}
224+
}
225+
226+
additionalProperties.putAll(testProfileAndProperties.properties);
217227
Map<String, String> resourceManagerProps = new HashMap<>(testResourceManager.start());
218228
//we also make the dev services config accessible from the test itself
219229
resourceManagerProps.putAll(QuarkusIntegrationTestExtension.devServicesProps);

test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,18 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S
126126
testResourceManager.init(
127127
testProfileAndProperties.testProfile != null ? testProfileAndProperties.testProfile.getClass().getName()
128128
: null);
129-
Map<String, String> additionalProperties = new HashMap<>(testProfileAndProperties.properties);
129+
130+
Map<String, String> additionalProperties = new HashMap<>();
131+
132+
// propagate Quarkus properties set from the build tool
133+
Properties existingSysProps = System.getProperties();
134+
for (String name : existingSysProps.stringPropertyNames()) {
135+
if (name.startsWith("quarkus.")) {
136+
additionalProperties.put(name, existingSysProps.getProperty(name));
137+
}
138+
}
139+
140+
additionalProperties.putAll(testProfileAndProperties.properties);
130141
Map<String, String> resourceManagerProps = new HashMap<>(testResourceManager.start());
131142
//also make the dev services props accessible from the test
132143
resourceManagerProps.putAll(QuarkusMainIntegrationTestExtension.devServicesProps);

0 commit comments

Comments
 (0)