1 package org.apache.maven.wagon.shared.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import java.net.MalformedURLException;
25 import java.net.URISyntaxException;
26
27 public class EncodingUtilTest
28 extends TestCase
29 {
30 public void testEncodeURLWithTrailingSlash()
31 {
32 String encodedURL = EncodingUtil.encodeURLToString( "https://host:1234/test", "demo/" );
33
34 assertEquals( "https://host:1234/test/demo/", encodedURL );
35 }
36
37 public void testEncodeURLWithSpaces()
38 throws URISyntaxException, MalformedURLException
39 {
40 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/path with spaces" );
41
42 assertEquals( "file://host:1/path%20with%20spaces", encodedURL );
43 }
44
45 public void testEncodeURLWithSpacesInPath()
46 throws URISyntaxException, MalformedURLException
47 {
48 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", "path with spaces" );
49
50 assertEquals( "file://host:1/path%20with%20spaces", encodedURL );
51 }
52
53 public void testEncodeURLWithSpacesInBothBaseAndPath()
54 throws URISyntaxException, MalformedURLException
55 {
56 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/with%20a", "path with spaces" );
57
58 assertEquals( "file://host:1/with%20a/path%20with%20spaces", encodedURL );
59 }
60
61 public void testEncodeURLWithSlashes1()
62 throws URISyntaxException, MalformedURLException
63 {
64 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath", "a", "b", "c" );
65
66 assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
67
68 encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath", "a/b/c" );
69
70 assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
71 }
72
73 public void testEncodeURLWithSlashes2()
74 throws URISyntaxException, MalformedURLException
75 {
76 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath/", "a", "b", "c" );
77
78 assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
79
80 encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath/", "a/b/c" );
81
82 assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
83 }
84
85 public void testEncodeURLWithSlashes3()
86 throws URISyntaxException, MalformedURLException
87 {
88 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath/", new String[0] );
89
90 assertEquals( "file://host:1/basePath/", encodedURL );
91 }
92
93 public void testEncodeURLWithSlashes4()
94 throws URISyntaxException, MalformedURLException
95 {
96 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath", new String[0] );
97
98 assertEquals( "file://host:1/basePath", encodedURL );
99 }
100
101 public void testEncodeURLWithSlashes5()
102 throws URISyntaxException, MalformedURLException
103 {
104 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath",
105 "a/1", "b/1", "c/1" );
106
107 assertEquals( "file://host:1/basePath/a%2F1/b%2F1/c%2F1", encodedURL );
108 }
109
110 public void testEncodeURLWithSlashes6()
111 throws URISyntaxException, MalformedURLException
112 {
113 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/", new String[0] );
114
115 assertEquals( "file://host:1/", encodedURL );
116 }
117
118 public void testEncodeURLWithSlashes7()
119 throws URISyntaxException, MalformedURLException
120 {
121 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", new String[0] );
122
123 assertEquals( "file://host:1", encodedURL );
124 }
125
126 public void testEncodeURLWithNonLatin()
127 throws URISyntaxException, MalformedURLException
128 {
129 String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", "пипец/" );
130
131 assertEquals( "file://host:1/%D0%BF%D0%B8%D0%BF%D0%B5%D1%86/", encodedURL );
132 }
133 }