Skip to content

Commit

Permalink
Propagate Quarkus related failsafe system properties
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Feb 28, 2023
1 parent cb1c4f0 commit 4f02922
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions integration-tests/test-extension/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<systemPropertyVariables>
<!-- See io.quarkus.extest.runtime.classpath.RecordedClasspathEntries -->
<classpathEntriesRecordingFile>${project.build.directory}/recorded-classpath-entries-failsafe.txt</classpathEntriesRecordingFile>
<quarkus.dymmy>test</quarkus.dymmy>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}

}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,17 @@ private QuarkusTestExtensionState doProcessStart(Properties quarkusArtifactPrope
populateCallbacks(requiredTestClass.getClassLoader());
}

Map<String, String> additionalProperties = new HashMap<>(testProfileAndProperties.properties);
Map<String, String> 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<String, String> resourceManagerProps = new HashMap<>(testResourceManager.start());
//we also make the dev services config accessible from the test itself
resourceManagerProps.putAll(QuarkusIntegrationTestExtension.devServicesProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,18 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S
testResourceManager.init(
testProfileAndProperties.testProfile != null ? testProfileAndProperties.testProfile.getClass().getName()
: null);
Map<String, String> additionalProperties = new HashMap<>(testProfileAndProperties.properties);

Map<String, String> 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<String, String> resourceManagerProps = new HashMap<>(testResourceManager.start());
//also make the dev services props accessible from the test
resourceManagerProps.putAll(QuarkusMainIntegrationTestExtension.devServicesProps);
Expand Down

0 comments on commit 4f02922

Please sign in to comment.