Polishing

This commit is contained in:
Sam Brannen 2021-08-22 14:27:47 +02:00
parent 99970a5ddc
commit 6c71cf2f96
1 changed files with 43 additions and 43 deletions

View File

@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Costin Leau * @author Costin Leau
*/ */
public class UrlPathHelperTests { class UrlPathHelperTests {
private static final String WEBSPHERE_URI_ATTRIBUTE = "com.ibm.websphere.servlet.uri_non_decoded"; private static final String WEBSPHERE_URI_ATTRIBUTE = "com.ibm.websphere.servlet.uri_non_decoded";
@ -41,7 +41,7 @@ public class UrlPathHelperTests {
@Test @Test
public void getPathWithinApplication() { void getPathWithinApplication() {
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
request.setRequestURI("/petclinic/welcome.html"); request.setRequestURI("/petclinic/welcome.html");
@ -49,7 +49,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getPathWithinApplicationForRootWithNoLeadingSlash() { void getPathWithinApplicationForRootWithNoLeadingSlash() {
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
request.setRequestURI("/petclinic"); request.setRequestURI("/petclinic");
@ -57,7 +57,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getPathWithinApplicationForSlashContextPath() { void getPathWithinApplicationForSlashContextPath() {
request.setContextPath("/"); request.setContextPath("/");
request.setRequestURI("/welcome.html"); request.setRequestURI("/welcome.html");
@ -65,7 +65,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getPathWithinServlet() { void getPathWithinServlet() {
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
request.setServletPath("/main"); request.setServletPath("/main");
request.setRequestURI("/petclinic/main/welcome.html"); request.setRequestURI("/petclinic/main/welcome.html");
@ -74,7 +74,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void alwaysUseFullPath() { void alwaysUseFullPath() {
helper.setAlwaysUseFullPath(true); helper.setAlwaysUseFullPath(true);
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
request.setServletPath("/main"); request.setServletPath("/main");
@ -84,7 +84,7 @@ public class UrlPathHelperTests {
} }
@Test // SPR-11101 @Test // SPR-11101
public void getPathWithinServletWithoutUrlDecoding() { void getPathWithinServletWithoutUrlDecoding() {
request.setContextPath("/SPR-11101"); request.setContextPath("/SPR-11101");
request.setServletPath("/test_url_decoding/a/b"); request.setServletPath("/test_url_decoding/a/b");
request.setRequestURI("/test_url_decoding/a%2Fb"); request.setRequestURI("/test_url_decoding/a%2Fb");
@ -96,7 +96,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getRequestUri() { void getRequestUri() {
request.setRequestURI("/welcome.html"); request.setRequestURI("/welcome.html");
assertThat(helper.getRequestUri(request)).isEqualTo("/welcome.html"); assertThat(helper.getRequestUri(request)).isEqualTo("/welcome.html");
@ -111,7 +111,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getRequestRemoveSemicolonContent() { void getRequestRemoveSemicolonContent() {
helper.setRemoveSemicolonContent(true); helper.setRemoveSemicolonContent(true);
request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R"); request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R");
assertThat(helper.getRequestUri(request)).isEqualTo("/foo/bar"); assertThat(helper.getRequestUri(request)).isEqualTo("/foo/bar");
@ -126,7 +126,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getRequestKeepSemicolonContent() { void getRequestKeepSemicolonContent() {
helper.setRemoveSemicolonContent(false); helper.setRemoveSemicolonContent(false);
testKeepSemicolonContent("/foo;a=b;c=d", "/foo;a=b;c=d"); testKeepSemicolonContent("/foo;a=b;c=d", "/foo;a=b;c=d");
@ -145,7 +145,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getLookupPathWithSemicolonContent() { void getLookupPathWithSemicolonContent() {
helper.setRemoveSemicolonContent(false); helper.setRemoveSemicolonContent(false);
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
@ -156,7 +156,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getLookupPathWithSemicolonContentAndNullPathInfo() { void getLookupPathWithSemicolonContentAndNullPathInfo() {
helper.setRemoveSemicolonContent(false); helper.setRemoveSemicolonContent(false);
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
@ -167,7 +167,7 @@ public class UrlPathHelperTests {
} }
@Test // gh-27303 @Test // gh-27303
public void defaultInstanceReadOnlyBehavior() { void defaultInstanceReadOnlyBehavior() {
UrlPathHelper helper = UrlPathHelper.defaultInstance; UrlPathHelper helper = UrlPathHelper.defaultInstance;
assertThatExceptionOfType(IllegalArgumentException.class) assertThatExceptionOfType(IllegalArgumentException.class)
@ -199,7 +199,7 @@ public class UrlPathHelperTests {
// //
@Test @Test
public void tomcatDefaultServletRoot() { void tomcatDefaultServletRoot() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setServletPath("/"); request.setServletPath("/");
request.setPathInfo(null); request.setPathInfo(null);
@ -208,7 +208,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatDefaultServletFile() { void tomcatDefaultServletFile() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setServletPath("/foo"); request.setServletPath("/foo");
request.setPathInfo(null); request.setPathInfo(null);
@ -218,7 +218,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatDefaultServletFolder() { void tomcatDefaultServletFolder() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setServletPath("/foo/"); request.setServletPath("/foo/");
request.setPathInfo(null); request.setPathInfo(null);
@ -228,7 +228,7 @@ public class UrlPathHelperTests {
} }
@Test //SPR-12372, SPR-13455 @Test //SPR-12372, SPR-13455
public void removeDuplicateSlashesInPath() { void removeDuplicateSlashesInPath() {
request.setContextPath("/SPR-12372"); request.setContextPath("/SPR-12372");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo/bar/"); request.setServletPath("/foo/bar/");
@ -249,7 +249,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletRoot() { void wasDefaultServletRoot() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/"); request.setPathInfo("/");
request.setServletPath(""); request.setServletPath("");
@ -260,13 +260,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletRootWithCompliantSetting() { void wasDefaultServletRootWithCompliantSetting() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/");
tomcatDefaultServletRoot(); tomcatDefaultServletRoot();
} }
@Test @Test
public void wasDefaultServletFile() { void wasDefaultServletFile() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo"); request.setPathInfo("/foo");
request.setServletPath(""); request.setServletPath("");
@ -277,13 +277,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletFileWithCompliantSetting() { void wasDefaultServletFileWithCompliantSetting() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo");
tomcatDefaultServletFile(); tomcatDefaultServletFile();
} }
@Test @Test
public void wasDefaultServletFolder() { void wasDefaultServletFolder() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo/"); request.setPathInfo("/foo/");
request.setServletPath(""); request.setServletPath("");
@ -294,7 +294,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletFolderWithCompliantSetting() { void wasDefaultServletFolderWithCompliantSetting() {
UrlPathHelper.websphereComplianceFlag = true; UrlPathHelper.websphereComplianceFlag = true;
try { try {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/");
@ -311,7 +311,7 @@ public class UrlPathHelperTests {
// //
@Test @Test
public void tomcatCasualServletRoot() { void tomcatCasualServletRoot() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/"); request.setPathInfo("/");
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -321,9 +321,9 @@ public class UrlPathHelperTests {
} }
@Disabled @Disabled
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
@Test @Test
public void tomcatCasualServletRootWithMissingSlash() { // test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
void tomcatCasualServletRootWithMissingSlash() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -333,7 +333,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatCasualServletFile() { void tomcatCasualServletFile() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo"); request.setPathInfo("/foo");
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -343,7 +343,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatCasualServletFolder() { void tomcatCasualServletFolder() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo/"); request.setPathInfo("/foo/");
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -353,7 +353,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletRoot() { void wasCasualServletRoot() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo/"); request.setServletPath("/foo/");
@ -364,15 +364,15 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletRootWithCompliantSetting() { void wasCasualServletRootWithCompliantSetting() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/");
tomcatCasualServletRoot(); tomcatCasualServletRoot();
} }
@Disabled @Disabled
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
@Test @Test
public void wasCasualServletRootWithMissingSlash() { // test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
void wasCasualServletRootWithMissingSlash() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -384,13 +384,13 @@ public class UrlPathHelperTests {
@Disabled @Disabled
@Test @Test
public void wasCasualServletRootWithMissingSlashWithCompliantSetting() { void wasCasualServletRootWithMissingSlashWithCompliantSetting() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo");
tomcatCasualServletRootWithMissingSlash(); tomcatCasualServletRootWithMissingSlash();
} }
@Test @Test
public void wasCasualServletFile() { void wasCasualServletFile() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo"); request.setPathInfo("/foo");
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -401,13 +401,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletFileWithCompliantSetting() { void wasCasualServletFileWithCompliantSetting() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo");
tomcatCasualServletFile(); tomcatCasualServletFile();
} }
@Test @Test
public void wasCasualServletFolder() { void wasCasualServletFolder() {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo/"); request.setPathInfo("/foo/");
request.setServletPath("/foo"); request.setServletPath("/foo");
@ -418,33 +418,33 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletFolderWithCompliantSetting() { void wasCasualServletFolderWithCompliantSetting() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo/");
tomcatCasualServletFolder(); tomcatCasualServletFolder();
} }
@Test @Test
public void getOriginatingRequestUri() { void getOriginatingRequestUri() {
request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path"); request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path");
request.setRequestURI("/forwarded"); request.setRequestURI("/forwarded");
assertThat(helper.getOriginatingRequestUri(request)).isEqualTo("/path"); assertThat(helper.getOriginatingRequestUri(request)).isEqualTo("/path");
} }
@Test @Test
public void getOriginatingRequestUriWebsphere() { void getOriginatingRequestUriWebsphere() {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/path"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/path");
request.setRequestURI("/forwarded"); request.setRequestURI("/forwarded");
assertThat(helper.getOriginatingRequestUri(request)).isEqualTo("/path"); assertThat(helper.getOriginatingRequestUri(request)).isEqualTo("/path");
} }
@Test @Test
public void getOriginatingRequestUriDefault() { void getOriginatingRequestUriDefault() {
request.setRequestURI("/forwarded"); request.setRequestURI("/forwarded");
assertThat(helper.getOriginatingRequestUri(request)).isEqualTo("/forwarded"); assertThat(helper.getOriginatingRequestUri(request)).isEqualTo("/forwarded");
} }
@Test @Test
public void getOriginatingQueryString() { void getOriginatingQueryString() {
request.setQueryString("forward=on"); request.setQueryString("forward=on");
request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path"); request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path");
request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "original=on"); request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "original=on");
@ -452,13 +452,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getOriginatingQueryStringNotPresent() { void getOriginatingQueryStringNotPresent() {
request.setQueryString("forward=true"); request.setQueryString("forward=true");
assertThat(this.helper.getOriginatingQueryString(request)).isEqualTo("forward=true"); assertThat(this.helper.getOriginatingQueryString(request)).isEqualTo("forward=true");
} }
@Test @Test
public void getOriginatingQueryStringIsNull() { void getOriginatingQueryStringIsNull() {
request.setQueryString("forward=true"); request.setQueryString("forward=true");
request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path"); request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path");
assertThat(this.helper.getOriginatingQueryString(request)).isNull(); assertThat(this.helper.getOriginatingQueryString(request)).isNull();