Skip to content

Commit

Permalink
Fix issue where injected REST Clients could use incorrect HTTP port
Browse files Browse the repository at this point in the history
  • Loading branch information
aguibert committed Mar 5, 2020
1 parent 6c10259 commit 15f71e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

import org.junit.jupiter.api.extension.ExtensionConfigurationException;
Expand Down Expand Up @@ -60,9 +61,30 @@ public boolean configureRestAssured() {
@Override
public String getApplicationURL() {
try {
Class<?> TestHTTPResourceManager = Class.forName("io.quarkus.test.common.http.TestHTTPResourceManager");
String testUrl = (String) TestHTTPResourceManager.getMethod("getUri").invoke(null);
return testUrl;
// First check for 'test.url' set directly
String testUrl = System.getProperty("test.url", "");
if (!testUrl.isEmpty())
return testUrl;

// Next, check application.properties
Properties props = new Properties();
props.load(getClass().getClassLoader().getResourceAsStream("application.properties"));
String testPort = props.getProperty("quarkus.http.test-port", "");
if (!testPort.isEmpty())
return "http://localhost:" + testPort;
testPort = props.getProperty("%test.quarkus.http.port", "");
if (!testPort.isEmpty())
return "http://localhost:" + testPort;

// Otherwise, assume we are running on the default test url
return "http://localhost:8081/";

// TODO: Need to handle running tests during dev mode somehow, which can result
// in the default HTTP port being 8080 instead of 8081. Below is the previous approach
// but it doesn't always work because REST clients get injected before quarkus is started
// Class<?> TestHTTPResourceManager = Class.forName("io.quarkus.test.common.http.TestHTTPResourceManager");
// String testUrl = (String) TestHTTPResourceManager.getMethod("getUri").invoke(null);
// return testUrl;
} catch (Throwable e) {
if (LOG.isDebugEnabled())
LOG.debug("Unable to determine Quarkus application URL", e);
Expand All @@ -84,7 +106,10 @@ else if (foundQuarkusTest && anno.annotationType().equals(MicroShedTest.class))
}
}

ManuallyStartedConfiguration.setRuntimeURL(getApplicationURL());
String appUrl = getApplicationURL();
LOG.info("Using Quarkus application URL: " + appUrl);

ManuallyStartedConfiguration.setRuntimeURL(appUrl);
super.applyConfiguration(testClass);
}

Expand Down
4 changes: 2 additions & 2 deletions sample-apps/quarkus-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.2.0.Final</quarkus-plugin.version>
<quarkus-plugin.version>1.2.1.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.2.0.Final</quarkus.platform.version>
<quarkus.platform.version>1.2.1.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
Expand Down

0 comments on commit 15f71e9

Please sign in to comment.