@@ -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,23 +59,30 @@ 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 );
63
62
for (Field f : c .getDeclaredFields ()) {
64
63
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 ) {
67
65
TestHTTPResourceProvider <?> provider = providers .get (f .getType ());
68
66
if (provider == null ) {
69
67
throw new RuntimeException (
70
68
"Unable to inject TestHTTPResource field " + f + " as no provider exists for the type" );
71
69
}
72
- String path = resource != null ? resource .value () : "" ;
70
+ String path = resource .value ();
73
71
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
+ }
79
86
}
80
87
if (!path .isEmpty () && endpointPath != null ) {
81
88
if (!endpointPath .endsWith ("/" )) {
@@ -87,7 +94,7 @@ public static void inject(Object testCase, List<Function<Class<?>, String>> endp
87
94
path = endpointPath ;
88
95
}
89
96
String val ;
90
- if (resource != null && ( resource .ssl () || resource .tls () )) {
97
+ if (resource .ssl () || resource .tls ()) {
91
98
if (management ) {
92
99
if (path .startsWith ("/" )) {
93
100
val = getManagementSslUri () + path ;
@@ -136,18 +143,4 @@ private static Map<Class<?>, TestHTTPResourceProvider<?>> getProviders() {
136
143
}
137
144
return Collections .unmodifiableMap (map );
138
145
}
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
-
153
146
}
0 commit comments