10
10
11
11
public class UriUtilsTest {
12
12
13
+ @ Test
14
+ public void testUriWithoutPath () throws MalformedURLException {
15
+ URL context =
URI .
create (
"http://user:[email protected] :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
+
13
26
@ Test
14
27
public void testUriForPath () throws MalformedURLException {
15
28
URL context =
URI .
create (
"http://user:[email protected] :80/context/path?id=123#frag" ).
toURL ();
@@ -23,8 +36,33 @@ public void testUriForPath() throws MalformedURLException {
23
36
assertEquals (pathURI .getFragment (), null , "Fragment mismatch" );
24
37
}
25
38
39
+ @ Test
40
+ public void testUriForPathAndParams () throws MalformedURLException {
41
+ URL context =
URI .
create (
"http://user:[email protected] :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
+
26
52
@ Test
27
53
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 () {
28
66
URI basicURI = UriUtils .makeBasicURI ("http" , "host.com" , 80 , "/target" );
29
67
assertEquals (basicURI .getScheme (), "http" , "Scheme mismatch" );
30
68
assertEquals (basicURI .getUserInfo (), null , "User info mismatch" );
@@ -34,4 +72,16 @@ public void testMakeBasicURI() {
34
72
assertEquals (basicURI .getQuery (), null , "Query mismatch" );
35
73
assertEquals (basicURI .getFragment (), null , "Fragment mismatch" );
36
74
}
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
+ }
37
87
}
0 commit comments