View Javadoc
1   package org.apache.maven.wagon.shared.http;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }