Debian Codegraph @

doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java

raw
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 package org.apache.maven.doxia.tools;
20
21 import java.io.File;
22
23 import org.junit.jupiter.api.Test;
24
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertNull;
27 import static org.junit.jupiter.api.Assertions.assertTrue;
28
29 /**
30 * @author <a href="mailto:[email protected]">Vincent Siveton</a>
31 */
32 public class DefaultSiteToolTest {
33
34 private DefaultSiteTool tool = new DefaultSiteTool();
35
36 /**
37 * test getNormalizedPath().
38 */
39 @Test
40 public void testGetNormalizedPath() {
41 assertNull(DefaultSiteTool.getNormalizedPath(null));
42 assertEquals("", DefaultSiteTool.getNormalizedPath(""));
43 assertEquals("", DefaultSiteTool.getNormalizedPath("."));
44 assertEquals("", DefaultSiteTool.getNormalizedPath("./"));
45 assertEquals("foo", DefaultSiteTool.getNormalizedPath("foo"));
46 assertEquals("foo/bar", DefaultSiteTool.getNormalizedPath("foo/bar"));
47 assertEquals("foo/bar", DefaultSiteTool.getNormalizedPath("foo\\bar"));
48 assertEquals("foo/bar", DefaultSiteTool.getNormalizedPath("foo/./bar"));
49 assertEquals("foo/bar", DefaultSiteTool.getNormalizedPath("foo//bar"));
50 assertEquals("", DefaultSiteTool.getNormalizedPath("foo/../"));
51 assertEquals("", DefaultSiteTool.getNormalizedPath("foo/.."));
52 assertEquals("bar", DefaultSiteTool.getNormalizedPath("foo/../bar"));
53 assertEquals("foo", DefaultSiteTool.getNormalizedPath("./foo"));
54 assertEquals("../foo", DefaultSiteTool.getNormalizedPath("../foo"));
55 assertEquals("../../foo", DefaultSiteTool.getNormalizedPath("../../foo"));
56 assertEquals("index.html", DefaultSiteTool.getNormalizedPath("./foo/../index.html"));
57
58 // note: space is preserved and double slash is removed!
59 assertEquals(
60 "file:/Documents and Settings/", DefaultSiteTool.getNormalizedPath("file://Documents and Settings/"));
61 }
62
63 @SuppressWarnings("deprecation")
64 @Test
65 public void testGetRelativePath() {
66 assertEquals(
67 ".." + File.separator + "bar.html",
68 tool.getRelativePath("http://example.com/foo/bar.html", "http://example.com/foo/baz.html"));
69 }
70
71 @SuppressWarnings("deprecation")
72 @Test
73 public void testGetRelativePath_same() {
74 assertTrue(tool.getRelativePath("http://example.com/foo/bar.html", "http://example.com/foo/bar.html")
75 .isEmpty());
76 }
77
78 @SuppressWarnings("deprecation")
79 @Test
80 public void testGetRelativePath_differentSchemes() {
81 assertEquals(
82 "scp://example.com/foo/bar.html",
83 tool.getRelativePath("scp://example.com/foo/bar.html", "http://example.com/foo/bar.html"));
84 assertEquals("file:///tmp/bloop", tool.getRelativePath("file:///tmp/bloop", "scp://localhost:/tmp/blop"));
85 }
86
87 @SuppressWarnings("deprecation")
88 @Test
89 public void testGetRelativePath_differentDomains() {
90 assertEquals(
91 "https://example.org/bar.html",
92 tool.getRelativePath("https://example.org/bar.html", "https://example.com/bar.html"));
93 assertEquals(
94 "dav:https://nexus2.mysite.net:123/nexus/content/sites/site/mysite-child/2.0.0/",
95 tool.getRelativePath(
96 "dav:https://nexus2.mysite.net:123/nexus/content/sites/site/mysite-child/2.0.0/",
97 "dav:https://nexus1.mysite.net:123/nexus/content/sites/site/mysite-parent/1.0.0/"));
98 }
99 }