Skip to content

Commit d1e55cb

Browse files
geoandgsmet
authored andcommitted
Fix @TestHTTPResource when quarkus.http.root-path doesn't start with "/"
Fixes: #47369 (cherry picked from commit 8d08922)
1 parent 73c6fa5 commit d1e55cb

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.quarkus.resteasy.reactive.server.test.path;
2+
3+
import static io.restassured.RestAssured.when;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
6+
import org.hamcrest.Matchers;
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.extension.RegisterExtension;
9+
10+
import io.quarkus.test.QuarkusUnitTest;
11+
import io.quarkus.test.common.http.TestHTTPEndpoint;
12+
import io.quarkus.test.common.http.TestHTTPResource;
13+
import io.restassured.RestAssured;
14+
15+
public class RootPathTestHTTPResourceTestCase {
16+
17+
@RegisterExtension
18+
static QuarkusUnitTest test = new QuarkusUnitTest()
19+
.overrideConfigKey("quarkus.http.root-path", "app/")
20+
.withApplicationRoot((jar) -> jar
21+
.addClass(HelloResource.class));
22+
23+
@TestHTTPEndpoint(HelloResource.class)
24+
@TestHTTPResource
25+
String url;
26+
27+
@Test
28+
public void testRestAssured() {
29+
RestAssured.basePath = "/";
30+
when().get("/app/hello").then().statusCode(200).body(Matchers.is("hello"));
31+
when().get("/app/hello/nested").then().statusCode(200).body(Matchers.is("world hello"));
32+
}
33+
34+
@Test
35+
public void testTestHTTPResource() {
36+
assertThat(url).isEqualTo("http://localhost:8081/app/hello");
37+
}
38+
}

test-framework/common/src/main/java/io/quarkus/test/common/http/TestHTTPConfigSourceInterceptor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.quarkus.test.common.http;
22

3+
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.HTTP_ROOT_PATH_KEY;
4+
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.MANAGEMENT_ROOT_PATH_KEY;
35
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_MANAGEMENT_URL_KEY;
46
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_MANAGEMENT_URL_SSL_KEY;
57
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_URL_KEY;
@@ -28,6 +30,14 @@ public ConfigValue getValue(final ConfigSourceInterceptorContext context, final
2830
name.equals(TEST_MANAGEMENT_URL_SSL_KEY)) {
2931

3032
return sanitizeUrl(super.getValue(context, name));
33+
} else if (name.equals(HTTP_ROOT_PATH_KEY) || name.equals(MANAGEMENT_ROOT_PATH_KEY)) {
34+
ConfigValue configValue = super.getValue(context, name);
35+
if ((configValue == null) || (configValue.getRawValue() == null) || configValue.getRawValue().isEmpty()
36+
|| configValue.getRawValue().startsWith("/")) {
37+
return configValue;
38+
}
39+
return configValue.from().withValue("/" + configValue.getValue()).withRawValue("/" + configValue.getRawValue())
40+
.build();
3141
}
3242

3343
return context.proceed(name);

test-framework/common/src/main/java/io/quarkus/test/common/http/TestHTTPConfigSourceProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TestHTTPConfigSourceProvider implements ConfigSourceProvider {
2424
static final String TEST_MANAGEMENT_URL_SSL_VALUE = "https://${quarkus.management.host:localhost}:${quarkus.management.test-port:9001}${quarkus.management.root-path:/q}";
2525
static final String TEST_MANAGEMENT_URL_SSL_KEY = "test.management.url.ssl";
2626

27+
static final String HTTP_ROOT_PATH_KEY = "quarkus.http.root-path";
28+
static final String MANAGEMENT_ROOT_PATH_KEY = "quarkus.http.management-path";
29+
2730
static final Map<String, String> entries = Map.of(
2831
TEST_URL_KEY, TEST_URL_VALUE,
2932
TEST_URL_SSL_KEY, TEST_URL_SSL_VALUE,

0 commit comments

Comments
 (0)