Skip to content

Commit 213f178

Browse files
authored
Merge pull request #46337 from quarkusio/revert-46157-feature/testhttpendpoint-inheritance
Revert "Make URL inherit TestHTTPEndpoint from class level"
2 parents 0af5881 + a9e251e commit 213f178

File tree

3 files changed

+21
-124
lines changed

3 files changed

+21
-124
lines changed

integration-tests/main/src/test/java/io/quarkus/it/main/TestHTTPResourceClassTestCase.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

integration-tests/main/src/test/java/io/quarkus/it/main/TestHTTPResourceFieldTestCase.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public static String getUri() {
1919
try {
2020
return ConfigProvider.getConfig().getValue("test.url", String.class);
2121
} catch (IllegalStateException e) {
22-
// massive hack for dev mode tests, dev mode has not started yet
23-
// so we don't have any way to load this correctly from config
22+
//massive hack for dev mode tests, dev mode has not started yet
23+
//so we don't have any way to load this correctly from config
2424
return "http://localhost:8080";
2525
}
2626
}
@@ -29,8 +29,8 @@ public static String getManagementUri() {
2929
try {
3030
return ConfigProvider.getConfig().getValue("test.management.url", String.class);
3131
} catch (IllegalStateException e) {
32-
// massive hack for dev mode tests, dev mode has not started yet
33-
// so we don't have any way to load this correctly from config
32+
//massive hack for dev mode tests, dev mode has not started yet
33+
//so we don't have any way to load this correctly from config
3434
return "http://localhost:9000";
3535
}
3636
}
@@ -59,23 +59,30 @@ public static void inject(Object testCase, List<Function<Class<?>, String>> endp
5959
Map<Class<?>, TestHTTPResourceProvider<?>> providers = getProviders();
6060
Class<?> c = testCase.getClass();
6161
while (c != Object.class) {
62-
TestHTTPEndpoint classEndpointAnnotation = c.getAnnotation(TestHTTPEndpoint.class);
6362
for (Field f : c.getDeclaredFields()) {
6463
TestHTTPResource resource = f.getAnnotation(TestHTTPResource.class);
65-
TestHTTPEndpoint fieldEndpointAnnotation = f.getAnnotation(TestHTTPEndpoint.class);
66-
if (resource != null || classEndpointAnnotation != null || fieldEndpointAnnotation != null) {
64+
if (resource != null) {
6765
TestHTTPResourceProvider<?> provider = providers.get(f.getType());
6866
if (provider == null) {
6967
throw new RuntimeException(
7068
"Unable to inject TestHTTPResource field " + f + " as no provider exists for the type");
7169
}
72-
String path = resource != null ? resource.value() : "";
70+
String path = resource.value();
7371
String endpointPath = null;
74-
boolean management = resource != null && resource.management();
75-
if (fieldEndpointAnnotation != null) {
76-
endpointPath = getEndpointPath(endpointProviders, f, fieldEndpointAnnotation);
77-
} else if (classEndpointAnnotation != null) {
78-
endpointPath = getEndpointPath(endpointProviders, f, classEndpointAnnotation);
72+
boolean management = resource.management();
73+
TestHTTPEndpoint endpointAnnotation = f.getAnnotation(TestHTTPEndpoint.class);
74+
if (endpointAnnotation != null) {
75+
for (Function<Class<?>, String> func : endpointProviders) {
76+
endpointPath = func.apply(endpointAnnotation.value());
77+
if (endpointPath != null) {
78+
break;
79+
}
80+
}
81+
if (endpointPath == null) {
82+
throw new RuntimeException(
83+
"Could not determine the endpoint path for " + endpointAnnotation.value() + " to inject "
84+
+ f);
85+
}
7986
}
8087
if (!path.isEmpty() && endpointPath != null) {
8188
if (!endpointPath.endsWith("/")) {
@@ -87,7 +94,7 @@ public static void inject(Object testCase, List<Function<Class<?>, String>> endp
8794
path = endpointPath;
8895
}
8996
String val;
90-
if (resource != null && (resource.ssl() || resource.tls())) {
97+
if (resource.ssl() || resource.tls()) {
9198
if (management) {
9299
if (path.startsWith("/")) {
93100
val = getManagementSslUri() + path;
@@ -136,18 +143,4 @@ private static Map<Class<?>, TestHTTPResourceProvider<?>> getProviders() {
136143
}
137144
return Collections.unmodifiableMap(map);
138145
}
139-
140-
private static String getEndpointPath(List<Function<Class<?>, String>> endpointProviders, Field field,
141-
TestHTTPEndpoint endpointAnnotation) {
142-
for (Function<Class<?>, String> func : endpointProviders) {
143-
String endpointPath = func.apply(endpointAnnotation.value());
144-
if (endpointPath != null) {
145-
return endpointPath;
146-
}
147-
}
148-
throw new RuntimeException(
149-
"Could not determine the endpoint path for " + endpointAnnotation.value()
150-
+ " to inject " + field);
151-
}
152-
153146
}

0 commit comments

Comments
 (0)