|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -28,7 +28,7 @@ import org.springframework.web.accept.FixedContentNegotiationStrategy; |
|
|
|
import org.springframework.web.context.request.NativeWebRequest; |
|
|
|
import org.springframework.web.context.request.NativeWebRequest; |
|
|
|
import org.springframework.web.context.request.ServletWebRequest; |
|
|
|
import org.springframework.web.context.request.ServletWebRequest; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Test fixture for {@link ContentNegotiationConfigurer} tests. |
|
|
|
* Test fixture for {@link ContentNegotiationConfigurer} tests. |
|
|
|
@ -56,7 +56,7 @@ public class ContentNegotiationConfigurerTests { |
|
|
|
this.servletRequest.setRequestURI("/flower.gif"); |
|
|
|
this.servletRequest.setRequestURI("/flower.gif"); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Should be able to resolve file extensions by default", |
|
|
|
assertEquals("Should be able to resolve file extensions by default", |
|
|
|
Arrays.asList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
MediaType.IMAGE_GIF, manager.resolveMediaTypes(this.webRequest).get(0)); |
|
|
|
|
|
|
|
|
|
|
|
this.servletRequest.setRequestURI("/flower?format=gif"); |
|
|
|
this.servletRequest.setRequestURI("/flower?format=gif"); |
|
|
|
this.servletRequest.addParameter("format", "gif"); |
|
|
|
this.servletRequest.addParameter("format", "gif"); |
|
|
|
@ -68,7 +68,7 @@ public class ContentNegotiationConfigurerTests { |
|
|
|
this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE); |
|
|
|
this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Should resolve Accept header by default", |
|
|
|
assertEquals("Should resolve Accept header by default", |
|
|
|
Arrays.asList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
MediaType.IMAGE_GIF, manager.resolveMediaTypes(this.webRequest).get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -77,7 +77,7 @@ public class ContentNegotiationConfigurerTests { |
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
|
|
|
|
|
|
|
|
this.servletRequest.setRequestURI("/flower.json"); |
|
|
|
this.servletRequest.setRequestURI("/flower.json"); |
|
|
|
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
assertEquals(MediaType.APPLICATION_JSON, manager.resolveMediaTypes(this.webRequest).get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -90,7 +90,7 @@ public class ContentNegotiationConfigurerTests { |
|
|
|
this.servletRequest.setRequestURI("/flower"); |
|
|
|
this.servletRequest.setRequestURI("/flower"); |
|
|
|
this.servletRequest.addParameter("f", "json"); |
|
|
|
this.servletRequest.addParameter("f", "json"); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
assertEquals(MediaType.APPLICATION_JSON, manager.resolveMediaTypes(this.webRequest).get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -109,7 +109,15 @@ public class ContentNegotiationConfigurerTests { |
|
|
|
this.configurer.defaultContentType(MediaType.APPLICATION_JSON); |
|
|
|
this.configurer.defaultContentType(MediaType.APPLICATION_JSON); |
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
assertEquals(MediaType.APPLICATION_JSON, manager.resolveMediaTypes(this.webRequest).get(0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void setMultipleDefaultContentTypes() throws Exception { |
|
|
|
|
|
|
|
this.configurer.defaultContentType(MediaType.APPLICATION_JSON, MediaType.ALL); |
|
|
|
|
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.ALL), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -117,6 +125,6 @@ public class ContentNegotiationConfigurerTests { |
|
|
|
this.configurer.defaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); |
|
|
|
this.configurer.defaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); |
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
ContentNegotiationManager manager = this.configurer.getContentNegotiationManager(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); |
|
|
|
assertEquals(MediaType.APPLICATION_JSON, manager.resolveMediaTypes(this.webRequest).get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|