@@ -19,8 +19,8 @@ public static String getUri() {
19
19
try {
20
20
return ConfigProvider .getConfig ().getValue ("test.url" , String .class );
21
21
} 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
24
24
return "http://localhost:8080" ;
25
25
}
26
26
}
@@ -29,8 +29,8 @@ public static String getManagementUri() {
29
29
try {
30
30
return ConfigProvider .getConfig ().getValue ("test.management.url" , String .class );
31
31
} 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
34
34
return "http://localhost:9000" ;
35
35
}
36
36
}
@@ -59,6 +59,7 @@ public static void inject(Object testCase, List<Function<Class<?>, String>> endp
59
59
Map <Class <?>, TestHTTPResourceProvider <?>> providers = getProviders ();
60
60
Class <?> c = testCase .getClass ();
61
61
while (c != Object .class ) {
62
+ TestHTTPEndpoint classEndpointAnnotation = c .getAnnotation (TestHTTPEndpoint .class );
62
63
for (Field f : c .getDeclaredFields ()) {
63
64
TestHTTPResource resource = f .getAnnotation (TestHTTPResource .class );
64
65
if (resource != null ) {
@@ -68,27 +69,22 @@ public static void inject(Object testCase, List<Function<Class<?>, String>> endp
68
69
"Unable to inject TestHTTPResource field " + f + " as no provider exists for the type" );
69
70
}
70
71
String path = resource .value ();
72
+ if (path .startsWith ("/" )) {
73
+ path = path .substring (1 );
74
+ }
71
75
String endpointPath = null ;
72
76
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
- }
77
+ TestHTTPEndpoint fieldEndpointAnnotation = f .getAnnotation (TestHTTPEndpoint .class );
78
+ if (fieldEndpointAnnotation != null ) {
79
+ endpointPath = getEndpointPath (endpointProviders , f , fieldEndpointAnnotation );
80
+ } else if (classEndpointAnnotation != null ) {
81
+ endpointPath = getEndpointPath (endpointProviders , f , classEndpointAnnotation );
86
82
}
87
83
if (!path .isEmpty () && endpointPath != null ) {
88
- if (!endpointPath .endsWith ("/" )) {
89
- path = endpointPath + "/" + path ;
90
- } else {
84
+ if (endpointPath .endsWith ("/" )) {
91
85
path = endpointPath + path ;
86
+ } else {
87
+ path = endpointPath + "/" + path ;
92
88
}
93
89
} else if (endpointPath != null ) {
94
90
path = endpointPath ;
@@ -143,4 +139,18 @@ private static Map<Class<?>, TestHTTPResourceProvider<?>> getProviders() {
143
139
}
144
140
return Collections .unmodifiableMap (map );
145
141
}
142
+
143
+ private static String getEndpointPath (List <Function <Class <?>, String >> endpointProviders , Field field ,
144
+ TestHTTPEndpoint endpointAnnotation ) {
145
+ for (Function <Class <?>, String > func : endpointProviders ) {
146
+ String endpointPath = func .apply (endpointAnnotation .value ());
147
+ if (endpointPath != null ) {
148
+ return endpointPath ;
149
+ }
150
+ }
151
+ throw new RuntimeException (
152
+ "Could not determine the endpoint path for " + endpointAnnotation .value ()
153
+ + " to inject " + field );
154
+ }
155
+
146
156
}
0 commit comments