|
36 | 36 | import org.junit.jupiter.api.Test; |
37 | 37 |
|
38 | 38 | import org.springframework.cloud.openfeign.CollectionFormat; |
| 39 | +import org.springframework.cloud.openfeign.FeignClientProperties; |
39 | 40 | import org.springframework.cloud.openfeign.SpringQueryMap; |
40 | 41 | import org.springframework.core.convert.ConversionService; |
41 | 42 | import org.springframework.data.domain.Page; |
@@ -189,8 +190,23 @@ void testProcessAnnotations_SimpleNoPath() throws Exception { |
189 | 190 | } |
190 | 191 |
|
191 | 192 | @Test |
192 | | - void testProcessAnnotations_SimplePathIsOnlyASlash() throws Exception { |
193 | | - Method method = TestTemplate_Simple.class.getDeclaredMethod("getSlashPath", String.class); |
| 193 | + void testProcessAnnotations_SimplePathIsOnlyASlashWithParam() throws Exception { |
| 194 | + Method method = TestTemplate_Simple.class.getDeclaredMethod("getSlashPathWithParam", String.class); |
| 195 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 196 | + |
| 197 | + assertThat(data.template().url()).isEqualTo("/?id=" + "{id}"); |
| 198 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 199 | + assertThat(data.template().headers().get("Accept").iterator().next()) |
| 200 | + .isEqualTo(MediaType.APPLICATION_JSON_VALUE); |
| 201 | + } |
| 202 | + |
| 203 | + @Test |
| 204 | + void testProcessAnnotations_SimplePathIsOnlyASlashWithParamWithTrailingSlashRemoval() throws Exception { |
| 205 | + FeignClientProperties properties = new FeignClientProperties(); |
| 206 | + properties.setRemoveTrailingSlash(true); |
| 207 | + contract = new SpringMvcContract(Collections.emptyList(), getConversionService(), properties); |
| 208 | + Method method = TestTemplate_Simple.class.getDeclaredMethod("getSlashPathWithParam", String.class); |
| 209 | + |
194 | 210 | MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
195 | 211 |
|
196 | 212 | assertThat(data.template().url()).isEqualTo("/?id=" + "{id}"); |
@@ -284,6 +300,48 @@ void testProcessAnnotations_SimplePostMapping() throws Exception { |
284 | 300 |
|
285 | 301 | } |
286 | 302 |
|
| 303 | + @Test |
| 304 | + void testProcessAnnotations_SimplePathIsOnlyASlashWithTrailingSlashRemoval() throws Exception { |
| 305 | + FeignClientProperties properties = new FeignClientProperties(); |
| 306 | + properties.setRemoveTrailingSlash(true); |
| 307 | + contract = new SpringMvcContract(Collections.emptyList(), getConversionService(), properties); |
| 308 | + Method method = TestTemplate_Simple.class.getDeclaredMethod("getSlashPath"); |
| 309 | + |
| 310 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 311 | + |
| 312 | + assertThat(data.template().url()).isEqualTo("/"); |
| 313 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 314 | + assertThat(data.template().headers().get("Accept").iterator().next()) |
| 315 | + .isEqualTo(MediaType.APPLICATION_JSON_VALUE); |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + void testProcessAnnotations_SimplePathHasTrailingSlash() throws Exception { |
| 320 | + Method method = TestTemplate_Simple.class.getDeclaredMethod("getTrailingSlash"); |
| 321 | + |
| 322 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 323 | + |
| 324 | + assertThat(data.template().url()).isEqualTo("/test1/test2/"); |
| 325 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 326 | + assertThat(data.template().headers().get("Accept").iterator().next()) |
| 327 | + .isEqualTo(MediaType.APPLICATION_JSON_VALUE); |
| 328 | + } |
| 329 | + |
| 330 | + @Test |
| 331 | + void testProcessAnnotations_SimplePathHasTrailingSlashWithTrailingSlashRemoval() throws Exception { |
| 332 | + FeignClientProperties properties = new FeignClientProperties(); |
| 333 | + properties.setRemoveTrailingSlash(true); |
| 334 | + contract = new SpringMvcContract(Collections.emptyList(), getConversionService(), properties); |
| 335 | + Method method = TestTemplate_Simple.class.getDeclaredMethod("getTrailingSlash"); |
| 336 | + |
| 337 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 338 | + |
| 339 | + assertThat(data.template().url()).isEqualTo("/test1/test2"); |
| 340 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 341 | + assertThat(data.template().headers().get("Accept").iterator().next()) |
| 342 | + .isEqualTo(MediaType.APPLICATION_JSON_VALUE); |
| 343 | + } |
| 344 | + |
287 | 345 | @Test |
288 | 346 | void testProcessAnnotationsOnMethod_Advanced() throws Exception { |
289 | 347 | Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest", String.class, String.class, |
@@ -738,7 +796,13 @@ public interface TestTemplate_Simple { |
738 | 796 | TestObject postMappingTest(@RequestBody TestObject object); |
739 | 797 |
|
740 | 798 | @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) |
741 | | - ResponseEntity<TestObject> getSlashPath(@RequestParam("id") String id); |
| 799 | + ResponseEntity<TestObject> getSlashPathWithParam(@RequestParam("id") String id); |
| 800 | + |
| 801 | + @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) |
| 802 | + ResponseEntity<TestObject> getSlashPath(); |
| 803 | + |
| 804 | + @GetMapping(value = "test1/test2/", produces = MediaType.APPLICATION_JSON_VALUE) |
| 805 | + ResponseEntity<TestObject> getTrailingSlash(); |
742 | 806 |
|
743 | 807 | @GetMapping(path = "test", produces = MediaType.APPLICATION_JSON_VALUE) |
744 | 808 | ResponseEntity<TestObject> getTestNoLeadingSlash(@RequestParam("name") String name); |
|
0 commit comments