2020
2121import java .lang .annotation .Annotation ;
2222import java .util .List ;
23+ import java .util .Properties ;
2324import java .util .stream .Collectors ;
2425
2526import 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
0 commit comments