This project has retired. For details please refer to its
Attic page.
MiscTest xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 *19 * Contributors:20 * Florian Mueller21 * Florent Guillaume, Nuxeo22 */23package org.apache.chemistry.opencmis.commons.impl.misc;
2425import junit.framework.TestCase;
2627import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
2829/**30 * Tests miscellaneous details.31 */32publicclassMiscTestextends TestCase {
3334publicvoid 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 }
3940publicvoid testUrlBuilderAddParameter() {
41 UrlBuilder urlBuilder;
4243 urlBuilder = new UrlBuilder("http://host/test");
44 urlBuilder.addParameter("query", "value");
45 assertEquals("http://host/test?query=value", urlBuilder.toString());
4647 urlBuilder = new UrlBuilder("http://host/test?foo=bar");
48 urlBuilder.addParameter("query", "value");
49 assertEquals("http://host/test?foo=bar&query=value", urlBuilder.toString());
5051// special chars, space turns into plus52 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 }
5657publicvoid testUrlBuilderAddPath() {
58 UrlBuilder urlBuilder;
5960 urlBuilder = new UrlBuilder("http://host/test");
61 urlBuilder.addParameter("query", "value");
62 assertEquals("http://host/test?query=value", urlBuilder.toString());
6364 urlBuilder = new UrlBuilder("http://host/test");
65 urlBuilder.addPath("path");
66 assertEquals("http://host/test/path", urlBuilder.toString());
6768 urlBuilder = new UrlBuilder("http://host/test/");
69 urlBuilder.addPath("path");
70 assertEquals("http://host/test/path", urlBuilder.toString());
7172 urlBuilder = new UrlBuilder("http://host/test");
73 urlBuilder.addPath("/path");
74 assertEquals("http://host/test/path", urlBuilder.toString());
7576 urlBuilder = new UrlBuilder("http://host/test/");
77 urlBuilder.addPath("/path");
78 assertEquals("http://host/test/path", urlBuilder.toString());
7980// multi-segment path with special chars, space turns into %2081 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 }
8586publicvoid testUrlBuilderAddPathSegment() {
87 UrlBuilder urlBuilder;
8889 urlBuilder = new UrlBuilder("http://host/test");
90 urlBuilder.addParameter("query", "value");
91 assertEquals("http://host/test?query=value", urlBuilder.toString());
9293 urlBuilder = new UrlBuilder("http://host/test");
94 urlBuilder.addPathSegment("path");
95 assertEquals("http://host/test/path", urlBuilder.toString());
9697 urlBuilder = new UrlBuilder("http://host/test/");
98 urlBuilder.addPathSegment("path");
99 assertEquals("http://host/test/path", urlBuilder.toString());
100101 urlBuilder = new UrlBuilder("http://host/test");
102 urlBuilder.addPathSegment("/path");
103 assertEquals("http://host/test/path", urlBuilder.toString());
104105 urlBuilder = new UrlBuilder("http://host/test/");
106 urlBuilder.addPathSegment("/path");
107 assertEquals("http://host/test/path", urlBuilder.toString());
108109// with special chars and slash, space turns into %20110 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 }
114115 }