Minor fix in PathResourceResolverTests

Closes gh-25671
This commit is contained in:
Rossen Stoyanchev
2020-09-12 02:58:18 +01:00
parent 07d2c08f48
commit 852718ec0e
2 changed files with 23 additions and 16 deletions

View File

@@ -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<Resource> locations = singletonList(location);
List<Resource> 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<Resource> locations = singletonList(location);
List<Resource> 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<Resource> locations = singletonList(location);
List<Resource> 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<Resource> locations = singletonList(location);
List<Resource> 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<Resource> 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<Resource> 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();
}

View File

@@ -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