1 package org.apache.maven.doxia.module.apt;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24
25
26
27
28
29
30 public class AptUtilsTest
31 extends TestCase
32 {
33
34
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
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
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
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
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
148
149 public void testEncodeFragment()
150 {
151 assertNull( AptUtils.encodeFragment( null ) );
152 assertEquals( "abc0d", AptUtils.encodeFragment( "a B&c0)D" ) );
153 }
154
155
156
157
158 public void testLinkToKey()
159 {
160 assertEquals( "abc56au", AptUtils.linkToKey( "aB$%C56 a&\\/'U" ) );
161 }
162 }