Merge branch '5.3.x'
This commit is contained in:
@@ -27,7 +27,6 @@ import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
@@ -64,7 +63,7 @@ public class ResourceHandlerRegistryTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
GenericWebApplicationContext appContext = new GenericWebApplicationContext();
|
||||
appContext.refresh();
|
||||
|
||||
@@ -76,8 +75,14 @@ public class ResourceHandlerRegistryTests {
|
||||
this.response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
private ResourceHttpRequestHandler getHandler(String pathPattern) {
|
||||
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.registry.getHandlerMapping();
|
||||
return (ResourceHttpRequestHandler) hm.getUrlMap().get(pathPattern);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void noResourceHandlers() throws Exception {
|
||||
public void noResourceHandlers() {
|
||||
this.registry = new ResourceHandlerRegistry(new GenericWebApplicationContext(), new MockServletContext());
|
||||
assertThat((Object) this.registry.getHandlerMapping()).isNull();
|
||||
}
|
||||
@@ -126,7 +131,7 @@ public class ResourceHandlerRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceChain() throws Exception {
|
||||
public void resourceChain() {
|
||||
ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
|
||||
ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
|
||||
this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);
|
||||
@@ -148,7 +153,7 @@ public class ResourceHandlerRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceChainWithoutCaching() throws Exception {
|
||||
public void resourceChainWithoutCaching() {
|
||||
this.registration.resourceChain(false);
|
||||
|
||||
ResourceHttpRequestHandler handler = getHandler("/resources/**");
|
||||
@@ -163,7 +168,7 @@ public class ResourceHandlerRegistryTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void resourceChainWithVersionResolver() throws Exception {
|
||||
public void resourceChainWithVersionResolver() {
|
||||
VersionResourceResolver versionResolver = new VersionResourceResolver()
|
||||
.addFixedVersionStrategy("fixed", "/**/*.js")
|
||||
.addContentVersionStrategy("/**");
|
||||
@@ -188,7 +193,7 @@ public class ResourceHandlerRegistryTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void resourceChainWithOverrides() throws Exception {
|
||||
public void resourceChainWithOverrides() {
|
||||
CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class);
|
||||
VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class);
|
||||
WebJarsResourceResolver webjarsResolver = Mockito.mock(WebJarsResourceResolver.class);
|
||||
@@ -224,13 +229,11 @@ public class ResourceHandlerRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlResourceWithCharset() throws Exception {
|
||||
public void urlResourceWithCharset() {
|
||||
this.registration.addResourceLocations("[charset=ISO-8859-1]file:///tmp");
|
||||
this.registration.resourceChain(true);
|
||||
|
||||
ResourceHttpRequestHandler handler = getHandler("/resources/**");
|
||||
UrlResource resource = (UrlResource) handler.getLocations().get(1);
|
||||
assertThat(resource.getURL().toString()).isEqualTo("file:/tmp");
|
||||
assertThat(handler.getUrlPathHelper()).isNotNull();
|
||||
|
||||
List<ResourceResolver> resolvers = handler.getResourceResolvers();
|
||||
@@ -241,15 +244,10 @@ public class ResourceHandlerRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void lastModifiedDisabled() {
|
||||
public void lastModifiedDisabled() {
|
||||
this.registration.setUseLastModified(false);
|
||||
ResourceHttpRequestHandler handler = getHandler("/resources/**");
|
||||
assertThat(handler.isUseLastModified()).isFalse();
|
||||
}
|
||||
|
||||
private ResourceHttpRequestHandler getHandler(String pathPattern) {
|
||||
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.registry.getHandlerMapping();
|
||||
return (ResourceHttpRequestHandler) hm.getUrlMap().get(pathPattern);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -289,7 +289,6 @@ public class ResourceHttpRequestHandlerTests {
|
||||
|
||||
@Test // SPR-14368
|
||||
public void getResourceWithMediaTypeResolvedThroughServletContext() throws Exception {
|
||||
|
||||
MockServletContext servletContext = new MockServletContext() {
|
||||
@Override
|
||||
public String getMimeType(String filePath) {
|
||||
@@ -311,7 +310,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
assertThat(this.response.getContentAsString()).isEqualTo("h1 { color:red; }");
|
||||
}
|
||||
|
||||
@Test // gh-27538
|
||||
@Test // gh-27538
|
||||
public void filterNonExistingLocations() throws Exception {
|
||||
List<Resource> inputLocations = Arrays.asList(
|
||||
new ClassPathResource("test/", getClass()),
|
||||
@@ -331,7 +330,6 @@ public class ResourceHttpRequestHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testInvalidPath() throws Exception {
|
||||
|
||||
// Use mock ResourceResolver: i.e. we're only testing upfront validations...
|
||||
|
||||
Resource resource = mock(Resource.class);
|
||||
@@ -677,7 +675,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
assertThat(ranges[11]).isEqualTo("t.");
|
||||
}
|
||||
|
||||
@Test // gh-25976
|
||||
@Test // gh-25976
|
||||
public void partialContentByteRangeWithEncodedResource(GzipSupport.GzippedFiles gzippedFiles) throws Exception {
|
||||
String path = "js/foo.js";
|
||||
gzippedFiles.create(path);
|
||||
@@ -706,7 +704,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
assertThat(this.response.getHeaderValues("Vary")).containsExactly("Accept-Encoding");
|
||||
}
|
||||
|
||||
@Test // gh-25976
|
||||
@Test // gh-25976
|
||||
public void partialContentWithHttpHead() throws Exception {
|
||||
this.request.setMethod("HEAD");
|
||||
this.request.addHeader("Range", "bytes=0-1");
|
||||
|
||||
Reference in New Issue
Block a user