Polishing

This commit is contained in:
Sam Brannen
2021-08-22 14:40:55 +02:00
parent 97a89d6db9
commit cecd2ee2e6

View File

@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @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";
@@ -43,7 +43,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");
@@ -51,7 +51,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getPathWithinApplicationForRootWithNoLeadingSlash() { void getPathWithinApplicationForRootWithNoLeadingSlash() {
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
request.setRequestURI("/petclinic"); request.setRequestURI("/petclinic");
@@ -59,7 +59,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getPathWithinApplicationForSlashContextPath() { void getPathWithinApplicationForSlashContextPath() {
request.setContextPath("/"); request.setContextPath("/");
request.setRequestURI("/welcome.html"); request.setRequestURI("/welcome.html");
@@ -67,7 +67,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");
@@ -76,7 +76,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");
@@ -88,7 +88,7 @@ public class UrlPathHelperTests {
// SPR-11101 // SPR-11101
@Test @Test
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");
@@ -100,7 +100,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getRequestUri() { void getRequestUri() {
request.setRequestURI("/welcome.html"); request.setRequestURI("/welcome.html");
assertThat(helper.getRequestUri(request)).as("Incorrect path returned").isEqualTo("/welcome.html"); assertThat(helper.getRequestUri(request)).as("Incorrect path returned").isEqualTo("/welcome.html");
@@ -112,7 +112,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getRequestRemoveSemicolonContent() throws UnsupportedEncodingException { void getRequestRemoveSemicolonContent() throws UnsupportedEncodingException {
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");
@@ -127,7 +127,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");
@@ -146,7 +146,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getLookupPathWithSemicolonContent() { void getLookupPathWithSemicolonContent() {
helper.setRemoveSemicolonContent(false); helper.setRemoveSemicolonContent(false);
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
@@ -157,7 +157,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void getLookupPathWithSemicolonContentAndNullPathInfo() { void getLookupPathWithSemicolonContentAndNullPathInfo() {
helper.setRemoveSemicolonContent(false); helper.setRemoveSemicolonContent(false);
request.setContextPath("/petclinic"); request.setContextPath("/petclinic");
@@ -168,7 +168,7 @@ public class UrlPathHelperTests {
} }
@Test // gh-27303 @Test // gh-27303
public void defaultInstanceReadOnlyBehavior() { void defaultInstanceReadOnlyBehavior() {
UrlPathHelper helper = UrlPathHelper.defaultInstance; UrlPathHelper helper = UrlPathHelper.defaultInstance;
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
@@ -200,7 +200,7 @@ public class UrlPathHelperTests {
// //
@Test @Test
public void tomcatDefaultServletRoot() throws Exception { void tomcatDefaultServletRoot() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/"); request.setServletPath("/");
@@ -209,7 +209,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatDefaultServletFile() throws Exception { void tomcatDefaultServletFile() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -219,7 +219,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatDefaultServletFolder() throws Exception { void tomcatDefaultServletFolder() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo/"); request.setServletPath("/foo/");
@@ -230,7 +230,7 @@ public class UrlPathHelperTests {
//SPR-12372 & SPR-13455 //SPR-12372 & SPR-13455
@Test @Test
public void removeDuplicateSlashesInPath() throws Exception { void removeDuplicateSlashesInPath() throws Exception {
request.setContextPath("/SPR-12372"); request.setContextPath("/SPR-12372");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo/bar/"); request.setServletPath("/foo/bar/");
@@ -251,7 +251,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletRoot() throws Exception { void wasDefaultServletRoot() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/"); request.setPathInfo("/");
request.setServletPath(""); request.setServletPath("");
@@ -262,13 +262,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletRootWithCompliantSetting() throws Exception { void wasDefaultServletRootWithCompliantSetting() throws Exception {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/");
tomcatDefaultServletRoot(); tomcatDefaultServletRoot();
} }
@Test @Test
public void wasDefaultServletFile() throws Exception { void wasDefaultServletFile() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo"); request.setPathInfo("/foo");
request.setServletPath(""); request.setServletPath("");
@@ -279,13 +279,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletFileWithCompliantSetting() throws Exception { void wasDefaultServletFileWithCompliantSetting() throws Exception {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo");
tomcatDefaultServletFile(); tomcatDefaultServletFile();
} }
@Test @Test
public void wasDefaultServletFolder() throws Exception { void wasDefaultServletFolder() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo/"); request.setPathInfo("/foo/");
request.setServletPath(""); request.setServletPath("");
@@ -296,7 +296,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasDefaultServletFolderWithCompliantSetting() throws Exception { void wasDefaultServletFolderWithCompliantSetting() throws Exception {
UrlPathHelper.websphereComplianceFlag = true; UrlPathHelper.websphereComplianceFlag = true;
try { try {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/");
@@ -313,7 +313,7 @@ public class UrlPathHelperTests {
// //
@Test @Test
public void tomcatCasualServletRoot() throws Exception { void tomcatCasualServletRoot() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/"); request.setPathInfo("/");
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -323,9 +323,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() throws Exception { // test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
void tomcatCasualServletRootWithMissingSlash() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -335,7 +335,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatCasualServletFile() throws Exception { void tomcatCasualServletFile() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo"); request.setPathInfo("/foo");
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -345,7 +345,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void tomcatCasualServletFolder() throws Exception { void tomcatCasualServletFolder() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo/"); request.setPathInfo("/foo/");
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -355,7 +355,7 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletRoot() throws Exception { void wasCasualServletRoot() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo/"); request.setServletPath("/foo/");
@@ -366,15 +366,15 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletRootWithCompliantSetting() throws Exception { void wasCasualServletRootWithCompliantSetting() throws Exception {
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() throws Exception { // test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
void wasCasualServletRootWithMissingSlash() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo(null); request.setPathInfo(null);
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -386,13 +386,13 @@ public class UrlPathHelperTests {
@Disabled @Disabled
@Test @Test
public void wasCasualServletRootWithMissingSlashWithCompliantSetting() throws Exception { void wasCasualServletRootWithMissingSlashWithCompliantSetting() throws Exception {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo");
tomcatCasualServletRootWithMissingSlash(); tomcatCasualServletRootWithMissingSlash();
} }
@Test @Test
public void wasCasualServletFile() throws Exception { void wasCasualServletFile() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo"); request.setPathInfo("/foo");
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -403,13 +403,13 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletFileWithCompliantSetting() throws Exception { void wasCasualServletFileWithCompliantSetting() throws Exception {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo");
tomcatCasualServletFile(); tomcatCasualServletFile();
} }
@Test @Test
public void wasCasualServletFolder() throws Exception { void wasCasualServletFolder() throws Exception {
request.setContextPath("/test"); request.setContextPath("/test");
request.setPathInfo("/foo/"); request.setPathInfo("/foo/");
request.setServletPath("/foo"); request.setServletPath("/foo");
@@ -420,33 +420,33 @@ public class UrlPathHelperTests {
} }
@Test @Test
public void wasCasualServletFolderWithCompliantSetting() throws Exception { void wasCasualServletFolderWithCompliantSetting() throws Exception {
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");
@@ -454,13 +454,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();