Support implicit ports in MHSR.getRequestURL()
Prior to this commit, MockHttpServletRequest.getRequestURL() always included the server port number in the reconstructed request URL, even for implicit ports (i.e., 80 and 443) and negative ports. MockHttpServletRequest.getRequestURL() now omits the port number when reconstructing a URL that has an implicit or negative port. Issue: SPR-9726
This commit is contained in:
@@ -193,6 +193,39 @@ public class MockHttpServletRequestTests {
|
||||
assertEqualEnumerations(Collections.enumeration(preferredLocales), request.getLocales());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURL() {
|
||||
request.setServerPort(8080);
|
||||
request.setRequestURI("/path");
|
||||
assertEquals("http://localhost:8080/path", request.getRequestURL().toString());
|
||||
|
||||
request.setScheme("https");
|
||||
request.setServerName("example.com");
|
||||
request.setServerPort(8443);
|
||||
assertEquals("https://example.com:8443/path", request.getRequestURL().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURLWithDefaults() {
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://localhost", requestURL.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURLWithDefaultsAndHttps() {
|
||||
request.setScheme("https");
|
||||
request.setServerPort(443);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("https://localhost", requestURL.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURLWithNegativePort() {
|
||||
request.setServerPort(-99);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://localhost", requestURL.toString());
|
||||
}
|
||||
|
||||
private void assertEqualEnumerations(Enumeration<?> enum1, Enumeration<?> enum2) {
|
||||
assertNotNull(enum1);
|
||||
assertNotNull(enum2);
|
||||
|
||||
Reference in New Issue
Block a user