20
20
21
21
import java .lang .annotation .Annotation ;
22
22
import java .util .List ;
23
+ import java .util .Properties ;
23
24
import java .util .stream .Collectors ;
24
25
25
26
import org .junit .jupiter .api .extension .ExtensionConfigurationException ;
@@ -60,9 +61,30 @@ public boolean configureRestAssured() {
60
61
@ Override
61
62
public String getApplicationURL () {
62
63
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;
66
88
} catch (Throwable e ) {
67
89
if (LOG .isDebugEnabled ())
68
90
LOG .debug ("Unable to determine Quarkus application URL" , e );
@@ -84,7 +106,10 @@ else if (foundQuarkusTest && anno.annotationType().equals(MicroShedTest.class))
84
106
}
85
107
}
86
108
87
- ManuallyStartedConfiguration .setRuntimeURL (getApplicationURL ());
109
+ String appUrl = getApplicationURL ();
110
+ LOG .info ("Using Quarkus application URL: " + appUrl );
111
+
112
+ ManuallyStartedConfiguration .setRuntimeURL (appUrl );
88
113
super .applyConfiguration (testClass );
89
114
}
90
115
0 commit comments