Polish ContentNegotiationStrategy support
Issue: SPR-8410, SPR-8417, SPR-8418,SPR-8416, SPR-8419,SPR-7722
This commit is contained in:
@@ -35,7 +35,7 @@ public class AbstractMappingContentNegotiationStrategyTests {
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypes() {
|
||||
Map<String, String> mapping = Collections.singletonMap("json", "application/json");
|
||||
Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
|
||||
TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("json", mapping);
|
||||
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(null);
|
||||
@@ -46,7 +46,7 @@ public class AbstractMappingContentNegotiationStrategyTests {
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesNoMatch() {
|
||||
Map<String, String> mapping = null;
|
||||
Map<String, MediaType> mapping = null;
|
||||
TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("blah", mapping);
|
||||
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(null);
|
||||
@@ -56,7 +56,7 @@ public class AbstractMappingContentNegotiationStrategyTests {
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesNoKey() {
|
||||
Map<String, String> mapping = Collections.singletonMap("json", "application/json");
|
||||
Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
|
||||
TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy(null, mapping);
|
||||
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(null);
|
||||
@@ -66,7 +66,7 @@ public class AbstractMappingContentNegotiationStrategyTests {
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesHandleNoMatch() {
|
||||
Map<String, String> mapping = null;
|
||||
Map<String, MediaType> mapping = null;
|
||||
TestMappingContentNegotiationStrategy strategy = new TestMappingContentNegotiationStrategy("xml", mapping);
|
||||
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(null);
|
||||
@@ -80,7 +80,7 @@ public class AbstractMappingContentNegotiationStrategyTests {
|
||||
|
||||
private final String extension;
|
||||
|
||||
public TestMappingContentNegotiationStrategy(String extension, Map<String, String> mapping) {
|
||||
public TestMappingContentNegotiationStrategy(String extension, Map<String, MediaType> mapping) {
|
||||
super(mapping);
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.web.accept;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -25,20 +26,29 @@ import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* Test fixture for MappingMediaTypeExtensionsResolver.
|
||||
* Test fixture for {@link MappingMediaTypeFileExtensionResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MappingMediaTypeExtensionsResolverTests {
|
||||
public class MappingMediaTypeFileExtensionResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveExtensions() {
|
||||
Map<String, String> mapping = Collections.singletonMap("json", "application/json");
|
||||
MappingMediaTypeExtensionsResolver resolver = new MappingMediaTypeExtensionsResolver(mapping);
|
||||
List<String> extensions = resolver.resolveExtensions(MediaType.APPLICATION_JSON);
|
||||
Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
|
||||
MappingMediaTypeFileExtensionResolver resolver = new MappingMediaTypeFileExtensionResolver(mapping);
|
||||
List<String> extensions = resolver.resolveFileExtensions(MediaType.APPLICATION_JSON);
|
||||
|
||||
assertEquals(1, extensions.size());
|
||||
assertEquals("json", extensions.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveExtensionsNoMatch() {
|
||||
Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
|
||||
MappingMediaTypeFileExtensionResolver resolver = new MappingMediaTypeFileExtensionResolver(mapping);
|
||||
List<String> extensions = resolver.resolveFileExtensions(MediaType.TEXT_HTML);
|
||||
|
||||
assertTrue(extensions.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class PathExtensionContentNegotiationStrategyTests {
|
||||
|
||||
assertEquals(Arrays.asList(new MediaType("text", "html")), mediaTypes);
|
||||
|
||||
strategy = new PathExtensionContentNegotiationStrategy(Collections.singletonMap("HTML", "application/xhtml+xml"));
|
||||
strategy = new PathExtensionContentNegotiationStrategy(Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML));
|
||||
mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertEquals(Arrays.asList(new MediaType("application", "xhtml+xml")), mediaTypes);
|
||||
|
||||
Reference in New Issue
Block a user