Add consumes attribute to @GetMapping

Issue: SPR-14988
This commit is contained in:
bedrin
2016-12-08 01:29:48 +03:00
committed by Rossen Stoyanchev
parent 1b0e95d7d8
commit 8315a4033f
3 changed files with 34 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@@ -44,7 +45,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link RequestMappingHandlerMapping}.
@@ -145,6 +150,14 @@ public class RequestMappingHandlerMappingTests {
info.getProducesCondition().getProducibleMediaTypes().iterator().next().toString());
}
@Test // SPR-14988
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.GET);
assertArrayEquals(new MediaType[]{MediaType.ALL}, new ArrayList<>(
requestMappingInfo.getConsumesCondition().getConsumableMediaTypes()).toArray());
}
@Test
public void getMapping() throws Exception {
assertComposedAnnotationMapping(RequestMethod.GET);
@@ -199,6 +212,7 @@ public class RequestMappingHandlerMappingTests {
@Controller
@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
static class ComposedAnnotationController {
@RequestMapping
@@ -209,7 +223,7 @@ public class RequestMappingHandlerMappingTests {
public void postJson() {
}
@GetMapping("/get")
@GetMapping(value = "/get", consumes = MediaType.ALL_VALUE)
public void get() {
}