|
1 | 1 | /* |
2 | | - * Copyright 2013-2023 the original author or authors. |
| 2 | + * Copyright 2013-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
82 | 82 | * @author Szymon Linowski |
83 | 83 | * @author Sam Kruglov |
84 | 84 | * @author Bhavya Agrawal |
| 85 | + * @author Tang Xiong |
85 | 86 | **/ |
86 | 87 |
|
87 | 88 | class SpringMvcContractTests { |
@@ -462,6 +463,60 @@ void testProcessAnnotations_MapParams() throws Exception { |
462 | 463 | assertThat(data.queryMapIndex().intValue()).isEqualTo(0); |
463 | 464 | } |
464 | 465 |
|
| 466 | + @Test |
| 467 | + void testProcessAnnotations_ParseParams_SingleParam() throws Exception { |
| 468 | + Method method = TestTemplate_ParseParams.class.getDeclaredMethod("singleParam"); |
| 469 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 470 | + |
| 471 | + assertThat(data.template().url()).isEqualTo("/test?p1=1"); |
| 472 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 473 | + } |
| 474 | + |
| 475 | + @Test |
| 476 | + void testProcessAnnotations_ParseParams_MultipleParams() throws Exception { |
| 477 | + Method method = TestTemplate_ParseParams.class.getDeclaredMethod("multipleParams"); |
| 478 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 479 | + |
| 480 | + assertThat(data.template().url()).isEqualTo("/test?p1=1&p2=2"); |
| 481 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 482 | + } |
| 483 | + |
| 484 | + @Test |
| 485 | + void testProcessAnnotations_ParseParams_MixParams() throws Exception { |
| 486 | + Method method = TestTemplate_ParseParams.class.getDeclaredMethod("mixParams"); |
| 487 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 488 | + |
| 489 | + assertThat(data.template().url()).isEqualTo("/test?p1=1&p2"); |
| 490 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 491 | + } |
| 492 | + |
| 493 | + @Test |
| 494 | + void testProcessAnnotations_ParseParams_SingleParamWithoutValue() throws Exception { |
| 495 | + Method method = TestTemplate_ParseParams.class.getDeclaredMethod("singleParamWithoutValue"); |
| 496 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 497 | + |
| 498 | + assertThat(data.template().url()).isEqualTo("/test?p1"); |
| 499 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 500 | + } |
| 501 | + |
| 502 | + @Test |
| 503 | + void testProcessAnnotations_ParseParams_MultipleParamsWithoutValue() throws Exception { |
| 504 | + Method method = TestTemplate_ParseParams.class.getDeclaredMethod("multipleParamsWithoutValue"); |
| 505 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 506 | + |
| 507 | + assertThat(data.template().url()).isEqualTo("/test?p1&p2"); |
| 508 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 509 | + } |
| 510 | + |
| 511 | + @Test |
| 512 | + void testProcessAnnotations_ParseParams_NotEqualParams() throws Exception { |
| 513 | + Method method = TestTemplate_ParseParams.class.getDeclaredMethod("notEqualParams"); |
| 514 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 515 | + |
| 516 | + assertThat(data.template().url()).isEqualTo("/test"); |
| 517 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 518 | + } |
| 519 | + |
465 | 520 | @Test |
466 | 521 | void testProcessHeaders() throws Exception { |
467 | 522 | Method method = TestTemplate_Headers.class.getDeclaredMethod("getTest", String.class); |
@@ -750,6 +805,28 @@ public interface TestTemplate_MapParams { |
750 | 805 |
|
751 | 806 | } |
752 | 807 |
|
| 808 | + public interface TestTemplate_ParseParams { |
| 809 | + |
| 810 | + @GetMapping(value = "test", params = "p1=1") |
| 811 | + ResponseEntity<TestObject> singleParam(); |
| 812 | + |
| 813 | + @GetMapping(value = "test", params = { "p1=1", "p2=2" }) |
| 814 | + ResponseEntity<TestObject> multipleParams(); |
| 815 | + |
| 816 | + @GetMapping(value = "test", params = { "p1" }) |
| 817 | + ResponseEntity<TestObject> singleParamWithoutValue(); |
| 818 | + |
| 819 | + @GetMapping(value = "test", params = { "p1", "p2" }) |
| 820 | + ResponseEntity<TestObject> multipleParamsWithoutValue(); |
| 821 | + |
| 822 | + @GetMapping(value = "test", params = { "p1=1", "p2" }) |
| 823 | + ResponseEntity<TestObject> mixParams(); |
| 824 | + |
| 825 | + @GetMapping(value = "test", params = { "p1!=1" }) |
| 826 | + ResponseEntity<TestObject> notEqualParams(); |
| 827 | + |
| 828 | + } |
| 829 | + |
753 | 830 | public interface TestTemplate_HeaderMap { |
754 | 831 |
|
755 | 832 | @GetMapping("/headerMap") |
|
0 commit comments