Polishing

See gh-30980
This commit is contained in:
rstoyanchev
2023-08-04 17:29:00 +03:00
parent d1d5b54f12
commit 6630b16771
4 changed files with 88 additions and 105 deletions

View File

@@ -48,6 +48,7 @@ import org.springframework.web.reactive.result.condition.MediaTypeExpression;
import org.springframework.web.reactive.result.condition.PatternsRequestCondition;
import org.springframework.web.reactive.result.method.RequestMappingInfo;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;
@@ -97,7 +98,7 @@ class RequestMappingHandlerMappingTests {
}
@Test
void resolveRequestMappingViaComposedAnnotation() throws Exception {
void resolveRequestMappingViaComposedAnnotation() {
RequestMappingInfo info = assertComposedAnnotationMapping("postJson", "/postJson", RequestMethod.POST);
assertThat(info.getConsumesCondition().getConsumableMediaTypes().iterator().next().toString()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
@@ -105,7 +106,7 @@ class RequestMappingHandlerMappingTests {
}
@Test // SPR-14988
void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
void getMappingOverridesConsumesFromTypeLevelAnnotation() {
RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.POST);
ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition();
@@ -129,27 +130,27 @@ class RequestMappingHandlerMappingTests {
}
@Test
void getMapping() throws Exception {
void getMapping() {
assertComposedAnnotationMapping(RequestMethod.GET);
}
@Test
void postMapping() throws Exception {
void postMapping() {
assertComposedAnnotationMapping(RequestMethod.POST);
}
@Test
void putMapping() throws Exception {
void putMapping() {
assertComposedAnnotationMapping(RequestMethod.PUT);
}
@Test
void deleteMapping() throws Exception {
void deleteMapping() {
assertComposedAnnotationMapping(RequestMethod.DELETE);
}
@Test
void patchMapping() throws Exception {
void patchMapping() {
assertComposedAnnotationMapping(RequestMethod.PATCH);
}
@@ -165,6 +166,7 @@ class RequestMappingHandlerMappingTests {
assertThat(mappingInfo.getPatternsCondition().getPatterns())
.extracting(PathPattern::toString)
.containsOnly("/exchange");
assertThat(mappingInfo.getMethodsCondition().getMethods()).isEmpty();
assertThat(mappingInfo.getParamsCondition().getExpressions()).isEmpty();
assertThat(mappingInfo.getHeadersCondition().getExpressions()).isEmpty();
@@ -188,27 +190,28 @@ class RequestMappingHandlerMappingTests {
assertThat(mappingInfo.getPatternsCondition().getPatterns())
.extracting(PathPattern::toString)
.containsOnly("/exchange/custom");
assertThat(mappingInfo.getMethodsCondition().getMethods())
.containsOnly(RequestMethod.POST);
assertThat(mappingInfo.getMethodsCondition().getMethods()).containsOnly(RequestMethod.POST);
assertThat(mappingInfo.getParamsCondition().getExpressions()).isEmpty();
assertThat(mappingInfo.getHeadersCondition().getExpressions()).isEmpty();
assertThat(mappingInfo.getConsumesCondition().getExpressions())
.extracting(MediaTypeExpression::getMediaType)
.containsOnly(MediaType.APPLICATION_JSON);
assertThat(mappingInfo.getProducesCondition().getExpressions())
.extracting(MediaTypeExpression::getMediaType)
.containsOnly(MediaType.valueOf("text/plain;charset=UTF-8"));
}
private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) throws Exception {
private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) {
String methodName = requestMethod.name().toLowerCase();
String path = "/" + methodName;
return assertComposedAnnotationMapping(methodName, path, requestMethod);
}
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path,
RequestMethod requestMethod) throws Exception {
private RequestMappingInfo assertComposedAnnotationMapping(
String methodName, String path, RequestMethod requestMethod) {
Class<?> clazz = ComposedAnnotationController.class;
Method method = ClassUtils.getMethod(clazz, methodName, (Class<?>[]) null);
@@ -287,15 +290,15 @@ class RequestMappingHandlerMappingTests {
}
}
@RestController
@HttpExchange("/exchange")
static class HttpExchangeController {
@HttpExchange
public void defaultValuesExchange(){}
public void defaultValuesExchange() {}
@HttpExchange(value = "/custom", accept = "text/plain;charset=UTF-8",
method = "POST", contentType = "application/json")
@PostExchange(url = "/custom", contentType = "application/json", accept = "text/plain;charset=UTF-8")
public void customValuesExchange(){}
}