BAEL-276: Added test case for path component

This commit is contained in:
Sunil Gulabani 2016-12-01 11:42:59 +05:30
parent 41992976ec
commit bdeec43f42
1 changed files with 21 additions and 4 deletions

View File

@ -58,10 +58,10 @@ public class EncoderDecoderUnitTest {
requestParams.put("key2", "value@!$2");
requestParams.put("key3", "value%3");
String path = "path 1";
String path = "path+1";
String fragment = "dummy Fragment";
String encodedURL = requestParams.keySet().stream().map(key -> key + "=" + encodeValue(requestParams.get(key))).collect(joining("&", "http://www.baeldung.com/" + encodeValue(path) + "?", "#" + encodeValue(fragment)));
String encodedURL = requestParams.keySet().stream().map(key -> key + "=" + encodeValue(requestParams.get(key))).collect(joining("&", "http://www.baeldung.com/" + getPath(path) + "?", "#" + encodeValue(fragment)));
Assert.assertThat(testUrl, CoreMatchers.is(encodedURL));
}
@ -77,8 +77,25 @@ public class EncoderDecoderUnitTest {
String fragment = uri.getRawFragment();
String decodedQuery = Arrays.stream(query.split("&")).map(param -> param.split("=")[0] + "=" + decode(param.split("=")[1])).collect(joining("&"));
String decodedPath = Arrays.stream(path.split("/")).map(param -> decode(param)).collect(joining("/"));
String decodedPath = Arrays.stream(path.split("/")).map(param -> getPath(param)).collect(joining("/"));
Assert.assertEquals("http://www.baeldung.com/path 1?key1=value 1&key2=value@!$2&key3=value%3#dummy Fragment", scheme + "://" + host + decodedPath + "?" + decodedQuery + "#" + decode(fragment));
Assert.assertEquals("http://www.baeldung.com/path+1?key1=value 1&key2=value@!$2&key3=value%3#dummy Fragment", scheme + "://" + host + decodedPath + "?" + decodedQuery + "#" + decode(fragment));
}
private String getPath(String path) {
try {
path = new URI(null, null, path, null).getPath();
} catch (URISyntaxException e) {
e.printStackTrace();
}
return path;
}
@Test
public void givenPath_thenEncodeDecodePath() throws URISyntaxException {
URI uri = new URI(null, null, "/Path 1/Path+2", null);
Assert.assertEquals("/Path 1/Path+2", uri.getPath());
Assert.assertEquals("/Path%201/Path+2", uri.getRawPath());
}
}