Skip to content

Commit b2338ed

Browse files
authored
Merge pull request #160 from aguibert/quarkus-121
Fix issue where injected REST Clients could use incorrect HTTP port
2 parents 091e34a + 15f71e9 commit b2338ed

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

modules/quarkus/src/main/java/org/microshed/testing/quarkus/QuarkusConfiguration.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.lang.annotation.Annotation;
2222
import java.util.List;
23+
import java.util.Properties;
2324
import java.util.stream.Collectors;
2425

2526
import org.junit.jupiter.api.extension.ExtensionConfigurationException;
@@ -60,9 +61,30 @@ public boolean configureRestAssured() {
6061
@Override
6162
public String getApplicationURL() {
6263
try {
63-
Class<?> TestHTTPResourceManager = Class.forName("io.quarkus.test.common.http.TestHTTPResourceManager");
64-
String testUrl = (String) TestHTTPResourceManager.getMethod("getUri").invoke(null);
65-
return testUrl;
64+
// First check for 'test.url' set directly
65+
String testUrl = System.getProperty("test.url", "");
66+
if (!testUrl.isEmpty())
67+
return testUrl;
68+
69+
// Next, check application.properties
70+
Properties props = new Properties();
71+
props.load(getClass().getClassLoader().getResourceAsStream("application.properties"));
72+
String testPort = props.getProperty("quarkus.http.test-port", "");
73+
if (!testPort.isEmpty())
74+
return "http://localhost:" + testPort;
75+
testPort = props.getProperty("%test.quarkus.http.port", "");
76+
if (!testPort.isEmpty())
77+
return "http://localhost:" + testPort;
78+
79+
// Otherwise, assume we are running on the default test url
80+
return "http://localhost:8081/";
81+
82+
// TODO: Need to handle running tests during dev mode somehow, which can result
83+
// in the default HTTP port being 8080 instead of 8081. Below is the previous approach
84+
// but it doesn't always work because REST clients get injected before quarkus is started
85+
// Class<?> TestHTTPResourceManager = Class.forName("io.quarkus.test.common.http.TestHTTPResourceManager");
86+
// String testUrl = (String) TestHTTPResourceManager.getMethod("getUri").invoke(null);
87+
// return testUrl;
6688
} catch (Throwable e) {
6789
if (LOG.isDebugEnabled())
6890
LOG.debug("Unable to determine Quarkus application URL", e);
@@ -84,7 +106,10 @@ else if (foundQuarkusTest && anno.annotationType().equals(MicroShedTest.class))
84106
}
85107
}
86108

87-
ManuallyStartedConfiguration.setRuntimeURL(getApplicationURL());
109+
String appUrl = getApplicationURL();
110+
LOG.info("Using Quarkus application URL: " + appUrl);
111+
112+
ManuallyStartedConfiguration.setRuntimeURL(appUrl);
88113
super.applyConfiguration(testClass);
89114
}
90115

sample-apps/quarkus-app/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<maven.compiler.target>1.8</maven.compiler.target>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
15-
<quarkus-plugin.version>1.2.0.Final</quarkus-plugin.version>
15+
<quarkus-plugin.version>1.2.1.Final</quarkus-plugin.version>
1616
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
1717
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
18-
<quarkus.platform.version>1.2.0.Final</quarkus.platform.version>
18+
<quarkus.platform.version>1.2.1.Final</quarkus.platform.version>
1919
<surefire-plugin.version>2.22.1</surefire-plugin.version>
2020
</properties>
2121
<dependencyManagement>

0 commit comments

Comments
 (0)