use of org.apache.wicket.request.Url in project wicket by apache.
the class MockHttpServletRequestTest method setAbsoluteUrlWithoutHost.
@Test
void setAbsoluteUrlWithoutHost() {
MockHttpServletRequest request = tester.getRequest();
assertEquals("http", request.getScheme());
assertEquals("localhost", request.getServerName());
assertEquals(80, request.getServerPort());
request.setURL("/foo/bar/baz.html?a=123&b=456");
assertEquals("http", request.getScheme());
assertEquals("localhost", request.getServerName());
assertEquals(80, request.getServerPort());
Url url = request.getUrl();
assertEquals("http", url.getProtocol());
assertEquals("localhost", url.getHost());
assertEquals(Integer.valueOf(80), url.getPort());
assertEquals("/foo/bar/baz.html", url.getPath());
assertEquals("a=123&b=456", url.getQueryString());
String pathInfo = request.getPathInfo();
assertEquals("/foo/bar/baz.html", pathInfo);
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class CombinedRequestParametersAdapterTest method getParameterValuesSameNameSameValue.
/**
* Tests that org.apache.wicket.request.parameter.CombinedRequestParametersAdapter#getParameterValues(java.lang.String)
* will return all values for a given parameter by name.
*
* https://issues.apache.org/jira/browse/WICKET-4417
*
* @throws Exception
*/
@Test
public void getParameterValuesSameNameSameValue() throws Exception {
Url url = Url.parse("?param1=value1¶m1=value1");
UrlRequestParametersAdapter urlAdapter = new UrlRequestParametersAdapter(url);
CombinedRequestParametersAdapter adapter = new CombinedRequestParametersAdapter(urlAdapter);
List<StringValue> values = adapter.getParameterValues("param1");
assertEquals(2, values.size());
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class UrlPathPageParametersEncoderTest method decodeUrlWithSlashesInTheMiddle.
/**
* Decode encoded parameters with a slashes in the middle. The empty name segments should be
* ignored.
*/
@Test
void decodeUrlWithSlashesInTheMiddle() {
Url url = Url.parse("name1/value1////name2/value2");
UrlPathPageParametersEncoder decoder = new UrlPathPageParametersEncoder();
PageParameters parameters = decoder.decodePageParameters(url);
assertEquals(2, parameters.getAllNamed().size());
assertEquals("value1", parameters.get("name1").toString());
assertEquals("value2", parameters.get("name2").toString());
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class UrlPathPageParametersEncoderTest method encodeNamedParametersWithSpecialChars.
/**
* Encode named parameters in the segments (so they look like indexed parameters) and the name
* and/or value have non-ASCII characters
*/
@Test
void encodeNamedParametersWithSpecialChars() {
// the non-ASCII characters are randomly chosen
PageParameters params = new PageParameters();
params.add("name1", "valueএ", INamedParameters.Type.MANUAL);
params.add("nameㄘ", "value2", INamedParameters.Type.MANUAL);
UrlPathPageParametersEncoder encoder = new UrlPathPageParametersEncoder();
Url url = encoder.encodePageParameters(params);
assertEquals("name1/value%E0%A6%8F/name%E3%84%98/value2", url.toString());
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class AbstractMapper method getMountSegments.
/**
* Convenience method for representing mountPath as array of segments
*
* @param mountPath
* @return array of path segments
*/
protected String[] getMountSegments(String mountPath) {
if (mountPath.charAt(0) == '/') {
mountPath = mountPath.substring(1);
}
Url url = Url.parse(mountPath);
String[] res = new String[url.getSegments().size()];
for (int i = 0; i < res.length; ++i) {
res[i] = url.getSegments().get(i);
}
return res;
}
Aggregations