1010
1111public class UriUtilsTest {
1212
13+ @ Test
14+ public void testUriWithoutPath () throws MalformedURLException {
15+ URL context = URI .create ("http://user:pswd@host.com:80/context/path?id=123#frag" ).toURL ();
16+ URI pathURI = UriUtils .uriForPath (context );
17+ assertEquals (pathURI .getScheme (), "http" , "Scheme mismatch" );
18+ assertEquals (pathURI .getUserInfo (), null , "User info mismatch" );
19+ assertEquals (pathURI .getHost (), "host.com" , "Host mismatch" );
20+ assertEquals (pathURI .getPort (), 80 , "Post mismatch" );
21+ assertEquals (pathURI .getPath (), "" , "Path mismatch" );
22+ assertEquals (pathURI .getQuery (), null , "Query mismatch" );
23+ assertEquals (pathURI .getFragment (), null , "Fragment mismatch" );
24+ }
25+
1326 @ Test
1427 public void testUriForPath () throws MalformedURLException {
1528 URL context = URI .create ("http://user:pswd@host.com:80/context/path?id=123#frag" ).toURL ();
@@ -23,8 +36,33 @@ public void testUriForPath() throws MalformedURLException {
2336 assertEquals (pathURI .getFragment (), null , "Fragment mismatch" );
2437 }
2538
39+ @ Test
40+ public void testUriForPathAndParams () throws MalformedURLException {
41+ URL context = URI .create ("http://user:pswd@host.com:80/context/path?id=123#frag" ).toURL ();
42+ URI pathURI = UriUtils .uriForPath (context , "/target" , "id=321" , "q=fresh & clean" );
43+ assertEquals (pathURI .getScheme (), "http" , "Scheme mismatch" );
44+ assertEquals (pathURI .getUserInfo (), null , "User info mismatch" );
45+ assertEquals (pathURI .getHost (), "host.com" , "Host mismatch" );
46+ assertEquals (pathURI .getPort (), 80 , "Post mismatch" );
47+ assertEquals (pathURI .getPath (), "/target" , "Path mismatch" );
48+ assertEquals (pathURI .getQuery (), "id=321&q=fresh+%26+clean" , "Query mismatch" );
49+ assertEquals (pathURI .getFragment (), null , "Fragment mismatch" );
50+ }
51+
2652 @ Test
2753 public void testMakeBasicURI () {
54+ URI basicURI = UriUtils .makeBasicURI ("http" , "host.com" , 80 );
55+ assertEquals (basicURI .getScheme (), "http" , "Scheme mismatch" );
56+ assertEquals (basicURI .getUserInfo (), null , "User info mismatch" );
57+ assertEquals (basicURI .getHost (), "host.com" , "Host mismatch" );
58+ assertEquals (basicURI .getPort (), 80 , "Post mismatch" );
59+ assertEquals (basicURI .getPath (), "" , "Path mismatch" );
60+ assertEquals (basicURI .getQuery (), null , "Query mismatch" );
61+ assertEquals (basicURI .getFragment (), null , "Fragment mismatch" );
62+ }
63+
64+ @ Test
65+ public void testMakeBasicURIWithPath () {
2866 URI basicURI = UriUtils .makeBasicURI ("http" , "host.com" , 80 , "/target" );
2967 assertEquals (basicURI .getScheme (), "http" , "Scheme mismatch" );
3068 assertEquals (basicURI .getUserInfo (), null , "User info mismatch" );
@@ -34,4 +72,16 @@ public void testMakeBasicURI() {
3472 assertEquals (basicURI .getQuery (), null , "Query mismatch" );
3573 assertEquals (basicURI .getFragment (), null , "Fragment mismatch" );
3674 }
75+
76+ @ Test
77+ public void testMakeBasicURIWithPathAndParams () {
78+ URI basicURI = UriUtils .makeBasicURI ("http" , "host.com" , 80 , "/target" , "id=123" , "q=fresh & clean" );
79+ assertEquals (basicURI .getScheme (), "http" , "Scheme mismatch" );
80+ assertEquals (basicURI .getUserInfo (), null , "User info mismatch" );
81+ assertEquals (basicURI .getHost (), "host.com" , "Host mismatch" );
82+ assertEquals (basicURI .getPort (), 80 , "Post mismatch" );
83+ assertEquals (basicURI .getPath (), "/target" , "Path mismatch" );
84+ assertEquals (basicURI .getQuery (), "id=123&q=fresh+%26+clean" , "Query mismatch" );
85+ assertEquals (basicURI .getFragment (), null , "Fragment mismatch" );
86+ }
3787}
0 commit comments