1 package org.apache.maven;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import junit.framework.TestCase;
21
22 import org.dom4j.Document;
23 import org.dom4j.Node;
24
25 import org.dom4j.io.SAXReader;
26
27 import java.io.File;
28 import java.io.FileInputStream;
29
30
31 /**
32 * NavBean Tests class.
33 *
34 * @author <a href="mailto:bwalding@jakarta.org">Ben Walding</a>
35 * @version $Id: NavBeanTest.java 532339 2007-04-25 12:28:56Z ltheussl $
36 */
37 public class NavBeanTest extends TestCase
38 {
39
40
41 /** Test resources file. */
42 private File testResources;
43
44 /** NavBean instance to test */
45 private NavBean nb;
46
47
48
49 /**
50 * Tests settings.
51 *
52 * @throws Exception If a problem occurs
53 */
54 public void setUp()
55 throws Exception
56 {
57 testResources =
58 new File(System.getProperty("basedir") + "/src/test-resources");
59 nb = new NavBean();
60 nb.setDocument(getTestDocument());
61 }
62
63 /**
64 * Test.
65 *
66 * @param href href
67 * @param location location
68 * @param expected Result expected
69 */
70 public void testCollapsed(
71 String href,
72 String location,
73 boolean expected)
74 {
75 nb.setLocation(location);
76
77 Node node = nb.getFirstNodeByHREF(href);
78 assertNotNull(node);
79
80 String s =
81 "At location " + location + ", looking to generate link to " + href
82 + ", expecting collapse = " + expected;
83 assertEquals(
84 s,
85 expected,
86 nb.isCollapsed(node));
87 }
88
89 /**
90 * tests suite.
91 *
92 * @throws Exception DOCUMENT ME!
93 */
94 public void testCollapsed()
95 throws Exception
96 {
97 testCollapsed(
98 "/alpha/index.html",
99 "/alpha/index.html",
100 false);
101 testCollapsed(
102 "/alpha/one/index.html",
103 "/alpha/index.html",
104 false);
105 testCollapsed(
106 "/alpha/two/index.html",
107 "/alpha/index.html",
108 false);
109 testCollapsed(
110 "/beta/index.html",
111 "/alpha/index.html",
112 true);
113
114 testCollapsed(
115 "/alpha/index.html",
116 "/beta/index.html",
117 false);
118 testCollapsed(
119 "/alpha/one/index.html",
120 "/beta/index.html",
121 false);
122 testCollapsed(
123 "/alpha/two/index.html",
124 "/beta/index.html",
125 false);
126 testCollapsed(
127 "/beta/index.html",
128 "/beta/index.html",
129 false);
130 testCollapsed(
131 "/beta/one/index.html",
132 "/beta/index.html",
133 true);
134 testCollapsed(
135 "/beta/two/index.html",
136 "/beta/index.html",
137 true);
138
139 testCollapsed(
140 "/alpha/index.html",
141 "beta/index.html",
142 false);
143 testCollapsed(
144 "/alpha/one/index.html",
145 "beta/index.html",
146 false);
147 testCollapsed(
148 "/alpha/two/index.html",
149 "beta/index.html",
150 false);
151 testCollapsed(
152 "/beta/index.html",
153 "beta/index.html",
154 false);
155 testCollapsed(
156 "/beta/one/index.html",
157 "beta/index.html",
158 true);
159 testCollapsed(
160 "/beta/two/index.html",
161 "beta/index.html",
162 true);
163 }
164
165 /**
166 * Get the navigation.xml to test.
167 *
168 * @return XML Document
169 *
170 * @throws Exception If a problem occurs.
171 */
172 protected Document getTestDocument()
173 throws Exception
174 {
175 SAXReader reader = new SAXReader();
176
177 return reader.read(
178 new FileInputStream(new File(
179 testResources,
180 "navigation.xml")));
181 }
182
183
184
185 /**
186 * Test
187 */
188 class Test
189 {
190
191
192 /** Href. */
193 private String href;
194
195 /** Collapsed. */
196 private boolean collapsed;
197
198
199
200 /**
201 * Creates a new Test object.
202 *
203 * @param newHref HREF.
204 * @param newCollapsed Status.
205 */
206 public Test(
207 String newHref,
208 boolean newCollapsed)
209 {
210 this.href = newHref;
211 this.collapsed = newCollapsed;
212 }
213 }
214 }