This project has retired. For details please refer to its Attic page.
MiscTest xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   *
19   * Contributors:
20   *     Florian Mueller
21   *     Florent Guillaume, Nuxeo
22   */
23  package org.apache.chemistry.opencmis.commons.impl.misc;
24  
25  import junit.framework.TestCase;
26  
27  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
28  
29  /**
30   * Tests miscellaneous details.
31   */
32  public class MiscTest extends TestCase {
33  
34      public void testUrlBuilder() {
35          assertEquals("http://host/test", (new UrlBuilder("http://host/test")).toString());
36          assertEquals("http://host/test?query=value", (new UrlBuilder("http://host/test?query=value")).toString());
37          assertEquals("http://host/test", (new UrlBuilder("http://host/test?")).toString());
38      }
39  
40      public void testUrlBuilderAddParameter() {
41          UrlBuilder urlBuilder;
42  
43          urlBuilder = new UrlBuilder("http://host/test");
44          urlBuilder.addParameter("query", "value");
45          assertEquals("http://host/test?query=value", urlBuilder.toString());
46  
47          urlBuilder = new UrlBuilder("http://host/test?foo=bar");
48          urlBuilder.addParameter("query", "value");
49          assertEquals("http://host/test?foo=bar&query=value", urlBuilder.toString());
50  
51          // special chars, space turns into plus
52          urlBuilder = new UrlBuilder("http://host/test");
53          urlBuilder.addParameter("query", "caf\u00e9 cr\u00e8me");
54          assertEquals("http://host/test?query=caf%C3%A9+cr%C3%A8me", urlBuilder.toString());
55      }
56  
57      public void testUrlBuilderAddPath() {
58          UrlBuilder urlBuilder;
59  
60          urlBuilder = new UrlBuilder("http://host/test");
61          urlBuilder.addParameter("query", "value");
62          assertEquals("http://host/test?query=value", urlBuilder.toString());
63  
64          urlBuilder = new UrlBuilder("http://host/test");
65          urlBuilder.addPath("path");
66          assertEquals("http://host/test/path", urlBuilder.toString());
67  
68          urlBuilder = new UrlBuilder("http://host/test/");
69          urlBuilder.addPath("path");
70          assertEquals("http://host/test/path", urlBuilder.toString());
71  
72          urlBuilder = new UrlBuilder("http://host/test");
73          urlBuilder.addPath("/path");
74          assertEquals("http://host/test/path", urlBuilder.toString());
75  
76          urlBuilder = new UrlBuilder("http://host/test/");
77          urlBuilder.addPath("/path");
78          assertEquals("http://host/test/path", urlBuilder.toString());
79  
80          // multi-segment path with special chars, space turns into %20
81          urlBuilder = new UrlBuilder("http://host/test/");
82          urlBuilder.addPath("path/caf\u00e9 d@d");
83          assertEquals("http://host/test/path/caf%C3%A9%20d%40d", urlBuilder.toString());
84      }
85  
86      public void testUrlBuilderAddPathSegment() {
87          UrlBuilder urlBuilder;
88  
89          urlBuilder = new UrlBuilder("http://host/test");
90          urlBuilder.addParameter("query", "value");
91          assertEquals("http://host/test?query=value", urlBuilder.toString());
92  
93          urlBuilder = new UrlBuilder("http://host/test");
94          urlBuilder.addPathSegment("path");
95          assertEquals("http://host/test/path", urlBuilder.toString());
96  
97          urlBuilder = new UrlBuilder("http://host/test/");
98          urlBuilder.addPathSegment("path");
99          assertEquals("http://host/test/path", urlBuilder.toString());
100 
101         urlBuilder = new UrlBuilder("http://host/test");
102         urlBuilder.addPathSegment("/path");
103         assertEquals("http://host/test/path", urlBuilder.toString());
104 
105         urlBuilder = new UrlBuilder("http://host/test/");
106         urlBuilder.addPathSegment("/path");
107         assertEquals("http://host/test/path", urlBuilder.toString());
108 
109         // with special chars and slash, space turns into %20
110         urlBuilder = new UrlBuilder("http://host/test/");
111         urlBuilder.addPathSegment("path/caf\u00e9 d@d");
112         assertEquals("http://host/test/path%2Fcaf%C3%A9%20d%40d", urlBuilder.toString());
113     }
114 
115 }