Skip to content

Commit f65e1ed

Browse files
committed
Polish
Group all contextPath tests together
1 parent 0a9f98f commit f65e1ed

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,35 @@ public void contextPathWithTrailingSlashes() throws Exception {
8787
assertEquals("/foo/bar/baz", filterAndGetContextPath());
8888
}
8989

90+
@Test
91+
public void contextPathWithForwardedPrefix() throws Exception {
92+
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix");
93+
this.request.setContextPath("/mvc-showcase");
94+
95+
String actual = filterAndGetContextPath();
96+
assertEquals("/prefix", actual);
97+
}
98+
99+
@Test
100+
public void contextPathWithForwardedPrefixTrailingSlash() throws Exception {
101+
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix/");
102+
this.request.setContextPath("/mvc-showcase");
103+
104+
String actual = filterAndGetContextPath();
105+
assertEquals("/prefix", actual);
106+
}
107+
108+
@Test
109+
public void contextPathPreserveEncoding() throws Exception {
110+
this.request.setContextPath("/app%20");
111+
this.request.setRequestURI("/app%20/path/");
112+
HttpServletRequest actual = filterAndGetWrappedRequest();
113+
114+
assertEquals("/app%20", actual.getContextPath());
115+
assertEquals("/app%20/path/", actual.getRequestURI());
116+
assertEquals("http://localhost/app%20/path/", actual.getRequestURL().toString());
117+
}
118+
90119
@Test
91120
public void requestUri() throws Exception {
92121
this.request.addHeader(X_FORWARDED_PREFIX, "/");
@@ -231,35 +260,6 @@ public void requestURLNewStringBuffer() throws Exception {
231260
assertEquals("http://localhost/prefix/mvc-showcase", actual.getRequestURL().toString());
232261
}
233262

234-
@Test
235-
public void contextPathWithForwardedPrefix() throws Exception {
236-
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix");
237-
this.request.setContextPath("/mvc-showcase");
238-
239-
String actual = filterAndGetContextPath();
240-
assertEquals("/prefix", actual);
241-
}
242-
243-
@Test
244-
public void contextPathWithForwardedPrefixTrailingSlash() throws Exception {
245-
this.request.addHeader(X_FORWARDED_PREFIX, "/prefix/");
246-
this.request.setContextPath("/mvc-showcase");
247-
248-
String actual = filterAndGetContextPath();
249-
assertEquals("/prefix", actual);
250-
}
251-
252-
@Test
253-
public void contextPathPreserveEncoding() throws Exception {
254-
this.request.setContextPath("/app%20");
255-
this.request.setRequestURI("/app%20/path/");
256-
HttpServletRequest actual = filterAndGetWrappedRequest();
257-
258-
assertEquals("/app%20", actual.getContextPath());
259-
assertEquals("/app%20/path/", actual.getRequestURI());
260-
assertEquals("http://localhost/app%20/path/", actual.getRequestURL().toString());
261-
}
262-
263263
@Test
264264
public void sendRedirectWithAbsolutePath() throws Exception {
265265
this.request.addHeader(X_FORWARDED_PROTO, "https");

0 commit comments

Comments
 (0)