1   package org.apache.maven.doxia.util;
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 org.codehaus.plexus.PlexusTestCase;
23  
24  /**
25   * Test case for <code>DoxiaUtils</code>.
26   *
27   * @author ltheussl
28   * @version $Id: DoxiaUtilsTest.java 652905 2008-05-02 20:56:52Z ltheussl $
29   */
30  public class DoxiaUtilsTest
31      extends PlexusTestCase
32  {
33      /**
34       * Verify the expected results.
35       */
36      public void testIsInternalLink()
37      {
38          String link = "#anchor";
39          assertTrue( "Should be an internal link: " + link,
40              DoxiaUtils.isInternalLink( link ) );
41  
42          link = "http://maven.apache.org/index.html#anchor";
43          assertFalse( "Should NOT be an internal link: " + link,
44              DoxiaUtils.isInternalLink( link ) );
45  
46          link = "./index.html";
47          assertFalse( "Should NOT be an internal link: " + link,
48              DoxiaUtils.isInternalLink( link ) );
49      }
50  
51      /**
52       * Verify the expected results.
53       */
54      public void testIsExternalLink()
55      {
56          String link = "http://maven.apache.org/";
57          assertTrue( "Should be an external link: " + link,
58              DoxiaUtils.isExternalLink( link ) );
59  
60          link = "https://maven.apache.org/";
61          assertTrue( "Should be an external link: " + link,
62              DoxiaUtils.isExternalLink( link ) );
63  
64          link = "HTTPS://MAVEN.APACHE.ORG/";
65          assertTrue( "Should be an external link: " + link,
66              DoxiaUtils.isExternalLink( link ) );
67  
68          link = "ftp:/maven.apache.org/";
69          assertTrue( "Should be an external link: " + link,
70              DoxiaUtils.isExternalLink( link ) );
71  
72          link = "mailto:maven@apache.org";
73          assertTrue( "Should be an external link: " + link,
74              DoxiaUtils.isExternalLink( link ) );
75  
76          link = "file:/index.html";
77          assertTrue( "Should be an external link: " + link,
78              DoxiaUtils.isExternalLink( link ) );
79  
80          link = "index.html";
81          assertFalse( "Should NOT be an external link: " + link,
82              DoxiaUtils.isExternalLink( link ) );
83  
84          link = "example.pdf";
85          assertFalse( "Should NOT be an external link: " + link,
86              DoxiaUtils.isExternalLink( link ) );
87  
88          link = "./index.html";
89          assertFalse( "Should NOT be an external link: " + link,
90              DoxiaUtils.isExternalLink( link ) );
91  
92          link = "../index.html";
93          assertFalse( "Should NOT be an external link: " + link,
94              DoxiaUtils.isExternalLink( link ) );
95  
96          // Windows style separators "\" are not allowed
97  
98          link = "file:\\index.html";
99          assertFalse( "Should NOT be an external link: " + link,
100             DoxiaUtils.isExternalLink( link ) );
101 
102         link = ".\\index.html";
103         assertFalse( "Should NOT be an external link: " + link,
104             DoxiaUtils.isExternalLink( link ) );
105 
106         link = "..\\index.html";
107         assertFalse( "Should NOT be an external link: " + link,
108             DoxiaUtils.isExternalLink( link ) );
109     }
110 
111     /**
112      * Verify the expected results.
113      */
114     public void testIsLocalLink()
115     {
116         String link = "index.html";
117         assertTrue( "Should be a local link: " + link,
118             DoxiaUtils.isLocalLink( link ) );
119 
120         link = "./index.html";
121         assertTrue( "Should be a local link: " + link,
122             DoxiaUtils.isLocalLink( link ) );
123 
124         link = "../index.html";
125         assertTrue( "Should be a local link: " + link,
126             DoxiaUtils.isLocalLink( link ) );
127 
128         link = "#anchor";
129         assertFalse( "Should NOT be a local link: " + link,
130             DoxiaUtils.isLocalLink( link ) );
131 
132     }
133 
134 }