View Javadoc
1   package org.apache.maven.doxia.module.apt;
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  /**
25   * Test AptUtils.
26   *
27   * @author ltheussl
28   * @version $Id$
29   */
30  public class AptUtilsTest
31          extends TestCase
32  {
33      /**
34       * Test of isExternalLink method, of class AptUtils.
35       */
36      public void testIsExternalLink()
37      {
38          String link = "http://maven.apache.org/";
39          assertTrue( "Should be an external link: " + link,
40              AptUtils.isExternalLink( link ) );
41  
42          link = "https://maven.apache.org/";
43          assertTrue( "Should be an external link: " + link,
44              AptUtils.isExternalLink( link ) );
45  
46          link = "HTTPS://MAVEN.APACHE.ORG/";
47          assertTrue( "Should be an external link: " + link,
48              AptUtils.isExternalLink( link ) );
49  
50          link = "ftp:/maven.apache.org/";
51          assertTrue( "Should be an external link: " + link,
52              AptUtils.isExternalLink( link ) );
53  
54          link = "mailto:maven@apache.org";
55          assertTrue( "Should be an external link: " + link,
56              AptUtils.isExternalLink( link ) );
57  
58          link = "file:/index.html";
59          assertTrue( "Should be an external link: " + link,
60              AptUtils.isExternalLink( link ) );
61  
62          link = "resource_type://domain:port/filepathname?query_string#anchor";
63          assertTrue( "Should be an external link: " + link,
64              AptUtils.isExternalLink( link ) );
65  
66          link = "index.html";
67          assertFalse( "Should NOT be an external link: " + link,
68              AptUtils.isExternalLink( link ) );
69  
70          link = "example.pdf";
71          assertFalse( "Should NOT be an external link: " + link,
72              AptUtils.isExternalLink( link ) );
73  
74          link = "./index.html";
75          assertFalse( "Should NOT be an external link: " + link,
76              AptUtils.isExternalLink( link ) );
77  
78          link = "../index.html";
79          assertFalse( "Should NOT be an external link: " + link,
80              AptUtils.isExternalLink( link ) );
81  
82          // Windows style separators "\" are not allowed
83  
84          link = "file:\\index.html";
85          assertFalse( "Should NOT be an external link: " + link,
86              AptUtils.isExternalLink( link ) );
87  
88          link = ".\\index.html";
89          assertFalse( "Should NOT be an external link: " + link,
90              AptUtils.isExternalLink( link ) );
91  
92          link = "..\\index.html";
93          assertFalse( "Should NOT be an external link: " + link,
94              AptUtils.isExternalLink( link ) );
95      }
96  
97      /**
98       * Test of isInternalLink method, of class AptUtils.
99       */
100     public void testIsInternalLink()
101     {
102         String link = "index.html";
103         assertTrue( "Should be an internal link: " + link, AptUtils.isInternalLink( link ) );
104         link = "file:/index.html";
105         assertFalse( "Should NOT be an internal link: " + link, AptUtils.isInternalLink( link ) );
106         link = "./index.html";
107         assertFalse( "Should NOT be an internal link: " + link, AptUtils.isInternalLink( link ) );
108     }
109 
110     /**
111      * Test of isLocalLink method, of class AptUtils.
112      */
113     public void testIsLocalLink()
114     {
115         String link = "/index.html";
116         assertTrue( "Should be a local link: " + link, AptUtils.isLocalLink( link ) );
117 
118         link = "./index.html";
119         assertTrue( "Should be a local link: " + link, AptUtils.isLocalLink( link ) );
120 
121         link = "../index.html";
122         assertTrue( "Should be a local link: " + link, AptUtils.isLocalLink( link ) );
123 
124         link = "index.html";
125         assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) );
126 
127         link = ".\\index.html";
128         assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) );
129 
130         link = "\\index.html";
131         assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) );
132 
133         link = "..\\index.html";
134         assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) );
135     }
136 
137     /**
138      * Test of encodeAnchor method, of class AptUtils.
139      */
140     public void testEncodeAnchor()
141     {
142         assertNull( AptUtils.encodeAnchor( null ) );
143         assertEquals( "a123_:_.-aBc", AptUtils.encodeAnchor( " 12!3 :_.&-a)Bc " ) );
144     }
145 
146     /**
147      * Test of encodeFragment method, of class AptUtils.
148      */
149     public void testEncodeFragment()
150     {
151         assertNull( AptUtils.encodeFragment( null ) );
152         assertEquals( "abc0d", AptUtils.encodeFragment( "a B&c0)D" ) );
153     }
154 
155     /**
156      * Test of linkToKey method, of class AptUtils.
157      */
158     public void testLinkToKey()
159     {
160         assertEquals( "abc56au", AptUtils.linkToKey( "aB$%C56 a&\\/'U" ) );
161     }
162 }