|
19 | 19 | import java.lang.reflect.InvocationTargetException; |
20 | 20 | import java.lang.reflect.Method; |
21 | 21 | import java.math.BigDecimal; |
| 22 | +import java.net.URI; |
22 | 23 | import java.time.LocalDateTime; |
23 | 24 | import java.time.format.DateTimeFormatter; |
24 | 25 | import java.util.Collection; |
|
34 | 35 | import feign.Param; |
35 | 36 | import org.junit.jupiter.api.BeforeEach; |
36 | 37 | import org.junit.jupiter.api.Test; |
| 38 | +import org.junit.jupiter.api.extension.ExtendWith; |
37 | 39 |
|
| 40 | +import org.springframework.boot.test.system.CapturedOutput; |
| 41 | +import org.springframework.boot.test.system.OutputCaptureExtension; |
38 | 42 | import org.springframework.cloud.openfeign.CollectionFormat; |
39 | 43 | import org.springframework.cloud.openfeign.FeignClientProperties; |
40 | 44 | import org.springframework.cloud.openfeign.SpringQueryMap; |
|
87 | 91 | * @author Tang Xiong |
88 | 92 | **/ |
89 | 93 |
|
| 94 | +@ExtendWith(OutputCaptureExtension.class) |
90 | 95 | class SpringMvcContractTests { |
91 | 96 |
|
92 | 97 | private static final Class<?> EXECUTABLE_TYPE; |
@@ -216,6 +221,42 @@ void testProcessAnnotations_SimplePathIsOnlyASlashWithParamWithTrailingSlashRemo |
216 | 221 | .isEqualTo(MediaType.APPLICATION_JSON_VALUE); |
217 | 222 | } |
218 | 223 |
|
| 224 | + @Test |
| 225 | + void getWithSingleUriParameterShouldNotWarn(CapturedOutput output) throws Exception { |
| 226 | + Method method = GetWithUriParameter.class.getDeclaredMethod("getValue", URI.class); |
| 227 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 228 | + |
| 229 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 230 | + assertThat(output).doesNotContain("OpenFeign Warning"); |
| 231 | + } |
| 232 | + |
| 233 | + @Test |
| 234 | + void getWithUnannotatedNonUriParameterShouldWarn(CapturedOutput output) throws Exception { |
| 235 | + Method method = GetWithUnannotatedParam.class.getDeclaredMethod("getValue", String.class); |
| 236 | + contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 237 | + |
| 238 | + assertThat(output).contains("OpenFeign Warning", |
| 239 | + "is declared as GET with parameters, but none of the parameters are annotated"); |
| 240 | + } |
| 241 | + |
| 242 | + @Test |
| 243 | + void getWithUriAndUnannotatedParameterShouldWarn(CapturedOutput output) throws Exception { |
| 244 | + Method method = GetWithUriAndUnannotatedParam.class.getDeclaredMethod("getValue", URI.class, String.class); |
| 245 | + contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 246 | + |
| 247 | + assertThat(output).contains("OpenFeign Warning", |
| 248 | + "is declared as GET with parameters, but none of the parameters are annotated"); |
| 249 | + } |
| 250 | + |
| 251 | + @Test |
| 252 | + void getWithUriAndAnnotatedParameterShouldNotWarn(CapturedOutput output) throws Exception { |
| 253 | + Method method = GetWithUriAndAnnotatedParam.class.getDeclaredMethod("getValue", URI.class, String.class); |
| 254 | + MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method); |
| 255 | + |
| 256 | + assertThat(data.template().method()).isEqualTo("GET"); |
| 257 | + assertThat(output).doesNotContain("OpenFeign Warning"); |
| 258 | + } |
| 259 | + |
219 | 260 | @Test |
220 | 261 | void testProcessAnnotations_MissingLeadingSlashInPath() throws Exception { |
221 | 262 | Method method = TestTemplate_Simple.class.getDeclaredMethod("getTestNoLeadingSlash", String.class); |
@@ -810,6 +851,34 @@ public interface TestTemplate_Simple { |
810 | 851 |
|
811 | 852 | } |
812 | 853 |
|
| 854 | + interface GetWithUriParameter { |
| 855 | + |
| 856 | + @GetMapping("/sample/receive") |
| 857 | + String getValue(URI baseUri); |
| 858 | + |
| 859 | + } |
| 860 | + |
| 861 | + interface GetWithUnannotatedParam { |
| 862 | + |
| 863 | + @GetMapping("/test") |
| 864 | + String getValue(String id); |
| 865 | + |
| 866 | + } |
| 867 | + |
| 868 | + interface GetWithUriAndUnannotatedParam { |
| 869 | + |
| 870 | + @GetMapping("/sample/receive") |
| 871 | + String getValue(URI baseUri, String unannotated); |
| 872 | + |
| 873 | + } |
| 874 | + |
| 875 | + interface GetWithUriAndAnnotatedParam { |
| 876 | + |
| 877 | + @GetMapping("/sample/receive") |
| 878 | + String getValue(URI baseUri, @RequestParam("id") String id); |
| 879 | + |
| 880 | + } |
| 881 | + |
813 | 882 | @RequestMapping("/prepend/{classId}") |
814 | 883 | public interface TestTemplate_Class_RequestMapping { |
815 | 884 |
|
|
0 commit comments