From 15f71e9f432e1a502416273705934ac64b049d6b Mon Sep 17 00:00:00 2001 From: Andrew Guibert Date: Thu, 5 Mar 2020 12:48:54 -0600 Subject: [PATCH] Fix issue where injected REST Clients could use incorrect HTTP port --- .../testing/quarkus/QuarkusConfiguration.java | 33 ++++++++++++++++--- sample-apps/quarkus-app/pom.xml | 4 +-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/modules/quarkus/src/main/java/org/microshed/testing/quarkus/QuarkusConfiguration.java b/modules/quarkus/src/main/java/org/microshed/testing/quarkus/QuarkusConfiguration.java index 03455a24..851ce7ad 100644 --- a/modules/quarkus/src/main/java/org/microshed/testing/quarkus/QuarkusConfiguration.java +++ b/modules/quarkus/src/main/java/org/microshed/testing/quarkus/QuarkusConfiguration.java @@ -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; @@ -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); @@ -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); } diff --git a/sample-apps/quarkus-app/pom.xml b/sample-apps/quarkus-app/pom.xml index dd771b57..852221a1 100644 --- a/sample-apps/quarkus-app/pom.xml +++ b/sample-apps/quarkus-app/pom.xml @@ -12,10 +12,10 @@ 1.8 UTF-8 UTF-8 - 1.2.0.Final + 1.2.1.Final quarkus-universe-bom io.quarkus - 1.2.0.Final + 1.2.1.Final 2.22.1