From 852718ec0e7a28ef2ae58676a69eb3c25317187e Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Sat, 12 Sep 2020 02:58:18 +0100 Subject: [PATCH] Minor fix in PathResourceResolverTests Closes gh-25671 --- .../resource/PathResourceResolverTests.java | 28 +++++++++++-------- .../resource/PathResourceResolverTests.java | 11 +++++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java index a0019afc02a..8ec93d52e36 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,16 +17,17 @@ package org.springframework.web.reactive.resource; import java.io.IOException; import java.time.Duration; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileUrlResource; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -46,7 +47,7 @@ public class PathResourceResolverTests { public void resolveFromClasspath() throws IOException { Resource location = new ClassPathResource("test/", PathResourceResolver.class); String path = "bar.css"; - List locations = singletonList(location); + List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT); assertThat(actual).isEqualTo(location.createRelative(path)); @@ -56,7 +57,7 @@ public class PathResourceResolverTests { public void resolveFromClasspathRoot() { Resource location = new ClassPathResource("/"); String path = "org/springframework/web/reactive/resource/test/bar.css"; - List locations = singletonList(location); + List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT); assertThat(actual).isNotNull(); @@ -71,7 +72,7 @@ public class PathResourceResolverTests { private void testWithEncodedPath(Resource location) throws IOException { String path = "foo%20foo.txt"; - List locations = singletonList(location); + List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT); assertThat(actual).isNotNull(); @@ -98,7 +99,7 @@ public class PathResourceResolverTests { } private void testCheckResource(Resource location, String requestPath) throws IOException { - List locations = singletonList(location); + List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, requestPath, locations, null).block(TIMEOUT); if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) { fail(requestPath + " doesn't actually exist as a relative path"); @@ -122,17 +123,20 @@ public class PathResourceResolverTests { Resource location = getResource("main.css"); String actual = this.resolver.resolveUrlPath("../testalternatepath/bar.css", - singletonList(location), null).block(TIMEOUT); + Collections.singletonList(location), null).block(TIMEOUT); assertThat(actual).isEqualTo("../testalternatepath/bar.css"); } @Test // SPR-12624 public void checkRelativeLocation() throws Exception { - String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm(); - Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework")); - List locations = singletonList(location); - assertThat(this.resolver.resolveResource(null, "main.css", locations, null).block(TIMEOUT)).isNotNull(); + String location= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm(); + location = location.replace("/test/org/springframework","/test/org/../org/springframework"); + + Mono resourceMono = this.resolver.resolveResource( + null, "main.css", Collections.singletonList(new UrlResource(location)), null); + + assertThat(resourceMono.block(TIMEOUT)).isNotNull(); } @Test // SPR-12747 @@ -145,7 +149,7 @@ public class PathResourceResolverTests { public void resolvePathRootResource() { Resource webjarsLocation = new ClassPathResource("/META-INF/resources/webjars/", PathResourceResolver.class); String path = this.resolver.resolveUrlPathInternal( - "", singletonList(webjarsLocation), null).block(TIMEOUT); + "", Collections.singletonList(webjarsLocation), null).block(TIMEOUT); assertThat(path).isNull(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java index 80146837ab2..a4a93190074 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -125,10 +125,13 @@ public class PathResourceResolverTests { @Test // SPR-12624 public void checkRelativeLocation() throws Exception { - String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm(); - Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework")); + String location= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm(); + location = location.replace("/test/org/springframework","/test/org/../org/springframework"); - assertThat(this.resolver.resolveResource(null, "main.css", Collections.singletonList(location), null)).isNotNull(); + Resource actual = this.resolver.resolveResource( + null, "main.css", Collections.singletonList(new UrlResource(location)), null); + + assertThat(actual).isNotNull(); } @Test // SPR-12747