1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
18
18
import java .io .IOException ;
19
19
import java .time .Duration ;
20
+ import java .util .Collections ;
20
21
import java .util .List ;
21
22
22
23
import org .junit .jupiter .api .Test ;
24
+ import reactor .core .publisher .Mono ;
23
25
24
26
import org .springframework .core .io .ClassPathResource ;
25
27
import org .springframework .core .io .FileUrlResource ;
26
28
import org .springframework .core .io .Resource ;
27
29
import org .springframework .core .io .UrlResource ;
28
30
29
- import static java .util .Collections .singletonList ;
30
31
import static org .assertj .core .api .Assertions .assertThat ;
31
32
import static org .assertj .core .api .Assertions .fail ;
32
33
@@ -46,7 +47,7 @@ public class PathResourceResolverTests {
46
47
public void resolveFromClasspath () throws IOException {
47
48
Resource location = new ClassPathResource ("test/" , PathResourceResolver .class );
48
49
String path = "bar.css" ;
49
- List <Resource > locations = singletonList (location );
50
+ List <Resource > locations = Collections . singletonList (location );
50
51
Resource actual = this .resolver .resolveResource (null , path , locations , null ).block (TIMEOUT );
51
52
52
53
assertThat (actual ).isEqualTo (location .createRelative (path ));
@@ -56,7 +57,7 @@ public void resolveFromClasspath() throws IOException {
56
57
public void resolveFromClasspathRoot () {
57
58
Resource location = new ClassPathResource ("/" );
58
59
String path = "org/springframework/web/reactive/resource/test/bar.css" ;
59
- List <Resource > locations = singletonList (location );
60
+ List <Resource > locations = Collections . singletonList (location );
60
61
Resource actual = this .resolver .resolveResource (null , path , locations , null ).block (TIMEOUT );
61
62
62
63
assertThat (actual ).isNotNull ();
@@ -71,7 +72,7 @@ public void resolveWithEncodedPath() throws IOException {
71
72
72
73
private void testWithEncodedPath (Resource location ) throws IOException {
73
74
String path = "foo%20foo.txt" ;
74
- List <Resource > locations = singletonList (location );
75
+ List <Resource > locations = Collections . singletonList (location );
75
76
Resource actual = this .resolver .resolveResource (null , path , locations , null ).block (TIMEOUT );
76
77
77
78
assertThat (actual ).isNotNull ();
@@ -98,7 +99,7 @@ public void checkResource() throws IOException {
98
99
}
99
100
100
101
private void testCheckResource (Resource location , String requestPath ) throws IOException {
101
- List <Resource > locations = singletonList (location );
102
+ List <Resource > locations = Collections . singletonList (location );
102
103
Resource actual = this .resolver .resolveResource (null , requestPath , locations , null ).block (TIMEOUT );
103
104
if (!location .createRelative (requestPath ).exists () && !requestPath .contains (":" )) {
104
105
fail (requestPath + " doesn't actually exist as a relative path" );
@@ -122,17 +123,20 @@ public void checkResourceWithAllowedLocations() {
122
123
123
124
Resource location = getResource ("main.css" );
124
125
String actual = this .resolver .resolveUrlPath ("../testalternatepath/bar.css" ,
125
- singletonList (location ), null ).block (TIMEOUT );
126
+ Collections . singletonList (location ), null ).block (TIMEOUT );
126
127
127
128
assertThat (actual ).isEqualTo ("../testalternatepath/bar.css" );
128
129
}
129
130
130
131
@ Test // SPR-12624
131
132
public void checkRelativeLocation () throws Exception {
132
- String locationUrl = new UrlResource (getClass ().getResource ("./test/" )).getURL ().toExternalForm ();
133
- Resource location = new UrlResource (locationUrl .replace ("/springframework" ,"/../org/springframework" ));
134
- List <Resource > locations = singletonList (location );
135
- assertThat (this .resolver .resolveResource (null , "main.css" , locations , null ).block (TIMEOUT )).isNotNull ();
133
+ String location = new UrlResource (getClass ().getResource ("./test/" )).getURL ().toExternalForm ();
134
+ location = location .replace ("/test/org/springframework" ,"/test/org/../org/springframework" );
135
+
136
+ Mono <Resource > resourceMono = this .resolver .resolveResource (
137
+ null , "main.css" , Collections .singletonList (new UrlResource (location )), null );
138
+
139
+ assertThat (resourceMono .block (TIMEOUT )).isNotNull ();
136
140
}
137
141
138
142
@ Test // SPR-12747
@@ -145,7 +149,7 @@ public void checkFileLocation() throws Exception {
145
149
public void resolvePathRootResource () {
146
150
Resource webjarsLocation = new ClassPathResource ("/META-INF/resources/webjars/" , PathResourceResolver .class );
147
151
String path = this .resolver .resolveUrlPathInternal (
148
- "" , singletonList (webjarsLocation ), null ).block (TIMEOUT );
152
+ "" , Collections . singletonList (webjarsLocation ), null ).block (TIMEOUT );
149
153
150
154
assertThat (path ).isNull ();
151
155
}
0 commit comments