001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import java.util.*;
024: import java.sql.*;
025: import junit.framework.*;
026: import org.apache.log4j.*;
027: import com.methodhead.persistable.*;
028: import com.methodhead.test.*;
029:
030: public class FoldingNavRendererTest extends TestCase {
031:
032: TestSite site = null;
033: String html = null;
034: StringBuffer buf = null;
035:
036: FoldingNavRenderer renderer1_ = null;
037:
038: static {
039: TestUtils.initLogger();
040: }
041:
042: public FoldingNavRendererTest(String name) {
043: super (name);
044: }
045:
046: protected void setUp() {
047: try {
048: renderer1_ = new FoldingNavRenderer();
049: renderer1_.setStart(1);
050: renderer1_.setContext(1);
051: renderer1_.setDepth(1);
052: renderer1_.setTop(1);
053: renderer1_.setHeader("<ul>\n");
054: renderer1_
055: .setLink("<li class=\"lev{level}\"><a href=\"{url}\">{title}</a></li>\n");
056: renderer1_
057: .setCurLink("<li class=\"lev{level}cur\"><a href=\"{url}\">{title}</a></li>\n");
058: renderer1_.setFooter("</ul>\n");
059: } catch (Exception e) {
060: fail(e.getMessage());
061: }
062: }
063:
064: protected void tearDown() {
065: }
066:
067: public void testProperties() {
068: try {
069: site = new TestSite();
070: site.createLinks();
071:
072: FoldingNavRenderer renderer = new FoldingNavRenderer();
073: renderer.setRoot(site.link1_);
074: assertTrue(site.link1_ == renderer.getRoot());
075:
076: renderer.setCur(site.link1_);
077: assertTrue(site.link1_ == renderer.getCur());
078:
079: renderer.setStart(666);
080: assertEquals(666, renderer.getStart());
081:
082: renderer.setContext(777);
083: assertEquals(777, renderer.getContext());
084:
085: renderer.setDepth(888);
086: assertEquals(888, renderer.getDepth());
087:
088: renderer.setHeader("header");
089: assertEquals("header", renderer.getHeader());
090:
091: renderer.setLink("link");
092: assertEquals("link", renderer.getLink());
093:
094: renderer.setCurLink("curlink");
095: assertEquals("curlink", renderer.getCurLink());
096:
097: renderer.setFooter("footer");
098: assertEquals("footer", renderer.getFooter());
099:
100: renderer.setIsEditMode(true);
101: assertEquals(true, renderer.getIsEditMode());
102: } catch (Exception e) {
103: e.printStackTrace();
104: fail();
105: }
106: }
107:
108: public void testRenderLink() {
109: try {
110: site = new TestSite();
111: site.createLinks();
112:
113: //
114: // render non-current link
115: //
116: renderer1_.setRoot(site.link1_);
117: renderer1_.setCur(site.link1_);
118:
119: buf = new StringBuffer();
120: renderer1_.renderLink(buf, site.link1_, 1);
121: assertEquals(
122: "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n",
123: buf.toString());
124:
125: buf = new StringBuffer();
126: renderer1_.renderLink(buf, site.link2_, 2);
127: assertEquals(
128: "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n",
129: buf.toString());
130:
131: buf = new StringBuffer();
132: renderer1_.renderLink(buf, site.link4_, 2);
133: assertEquals(
134: "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n",
135: buf.toString());
136: } catch (Exception e) {
137: e.printStackTrace();
138: fail();
139: }
140: }
141:
142: public void testRenderLinkEditMode() {
143: try {
144: site = new TestSite();
145: site.createLinks();
146:
147: //
148: // render non-current link
149: //
150: renderer1_.setRoot(site.link1_);
151: renderer1_.setCur(site.link1_);
152: renderer1_.setIsEditMode(true);
153:
154: buf = new StringBuffer();
155: renderer1_.renderLink(buf, site.link1_, 1);
156: assertEquals(
157: "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n",
158: buf.toString());
159:
160: buf = new StringBuffer();
161: renderer1_.renderLink(buf, site.link2_, 2);
162: assertEquals(
163: "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n",
164: buf.toString());
165:
166: buf = new StringBuffer();
167: renderer1_.renderLink(buf, site.link4_, 2);
168: assertEquals(
169: "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n",
170: buf.toString());
171: } catch (Exception e) {
172: e.printStackTrace();
173: fail();
174: }
175: }
176:
177: public void testRenderHeader() {
178: try {
179: site = new TestSite();
180: site.createLinks();
181:
182: renderer1_.setRoot(site.link1_);
183: renderer1_.setCur(site.link1_);
184:
185: StringBuffer buf = new StringBuffer();
186: renderer1_.renderHeader(buf);
187: assertEquals("<ul>\n", buf.toString());
188: } catch (Exception e) {
189: e.printStackTrace();
190: fail();
191: }
192: }
193:
194: public void testRenderFooter() {
195: try {
196: site = new TestSite();
197: site.createLinks();
198:
199: renderer1_.setRoot(site.link1_);
200: renderer1_.setCur(site.link1_);
201:
202: StringBuffer buf = new StringBuffer();
203: renderer1_.renderFooter(buf);
204: assertEquals("</ul>\n", buf.toString());
205: } catch (Exception e) {
206: e.printStackTrace();
207: fail();
208: }
209: }
210:
211: public void testRenderNav_Cur1() {
212: try {
213: site = new TestSite();
214: site.createLinks();
215:
216: renderer1_.setRoot(site.link1_);
217: renderer1_.setCur(site.link1_);
218:
219: html = "<ul>\n"
220: + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
221: + "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n"
222: + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
223: + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
224: + "</ul>\n";
225:
226: buf = new StringBuffer();
227: renderer1_.renderNav(buf);
228: assertEquals(html, buf.toString());
229: } catch (Exception e) {
230: e.printStackTrace();
231: fail();
232: }
233: }
234:
235: public void testRenderNav_Cur1Depth2() {
236: try {
237: site = new TestSite();
238: site.createLinks();
239:
240: renderer1_.setRoot(site.link1_);
241: renderer1_.setCur(site.link1_);
242: renderer1_.setDepth(2);
243:
244: html = "<ul>\n"
245: + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
246: + "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n"
247: + "<li class=\"lev3\"><a href=\"page3.shtml\">Page3</a></li>\n"
248: + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
249: + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
250: + "<li class=\"lev3\"><a href=\"page6.shtml\">Page6</a></li>\n"
251: + "</ul>\n";
252:
253: buf = new StringBuffer();
254: renderer1_.renderNav(buf);
255: assertEquals(html, buf.toString());
256: } catch (Exception e) {
257: e.printStackTrace();
258: fail();
259: }
260: }
261:
262: public void testRenderNav_Cur2() {
263: try {
264: site = new TestSite();
265: site.createLinks();
266:
267: renderer1_.setRoot(site.link1_);
268: renderer1_.setCur(site.link2_);
269:
270: html = "<ul>\n"
271: + "<li class=\"lev1\"><a href=\"page1.shtml\">Page1</a></li>\n"
272: + "<li class=\"lev2cur\"><a href=\"page2.shtml\">Page2</a></li>\n"
273: + "<li class=\"lev3\"><a href=\"page3.shtml\">Page3</a></li>\n"
274: + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
275: + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
276: + "</ul>\n";
277:
278: buf = new StringBuffer();
279: renderer1_.renderNav(buf);
280: assertEquals(html, buf.toString());
281: } catch (Exception e) {
282: e.printStackTrace();
283: fail();
284: }
285: }
286:
287: public void testRenderNav_Cur2Start2() {
288: try {
289: site = new TestSite();
290: site.createLinks();
291:
292: renderer1_.setRoot(site.link1_);
293: renderer1_.setCur(site.link2_);
294: renderer1_.setStart(2);
295:
296: html = "<ul>\n"
297: + "<li class=\"lev1cur\"><a href=\"page2.shtml\">Page2</a></li>\n"
298: + "<li class=\"lev2\"><a href=\"page3.shtml\">Page3</a></li>\n"
299: + "<li class=\"lev1\"><a href=\"page4.shtml\">Page4</a></li>\n"
300: + "<li class=\"lev1\"><a href=\"page5.shtml\">Page5</a></li>\n"
301: + "</ul>\n";
302:
303: buf = new StringBuffer();
304: renderer1_.renderNav(buf);
305: assertEquals(html, buf.toString());
306: } catch (Exception e) {
307: e.printStackTrace();
308: fail();
309: }
310:
311: }
312:
313: public void testRenderNav_Cur3Start2Top0() {
314: try {
315: site = new TestSite();
316: site.createLinks();
317:
318: renderer1_.setRoot(site.link1_);
319: renderer1_.setCur(site.link3_);
320: renderer1_.setStart(2);
321: renderer1_.setTop(0);
322:
323: html = "<ul>\n"
324: + "<li class=\"lev1\"><a href=\"page2.shtml\">Page2</a></li>\n"
325: + "<li class=\"lev2cur\"><a href=\"page3.shtml\">Page3</a></li>\n"
326: + "</ul>\n";
327:
328: buf = new StringBuffer();
329: renderer1_.renderNav(buf);
330: assertEquals(html, buf.toString());
331: } catch (Exception e) {
332: e.printStackTrace();
333: fail();
334: }
335: }
336:
337: public void testRenderNav_Cur3Top2() {
338: try {
339: site = new TestSite();
340: site.createLinks();
341:
342: renderer1_.setRoot(site.link1_);
343: renderer1_.setCur(site.link3_);
344: renderer1_.setTop(2);
345:
346: html = "<ul>\n"
347: + "<li class=\"lev1\"><a href=\"page1.shtml\">Page1</a></li>\n"
348: + "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n"
349: + "<li class=\"lev3cur\"><a href=\"page3.shtml\">Page3</a></li>\n"
350: + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
351: + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
352: + "</ul>\n";
353:
354: buf = new StringBuffer();
355: renderer1_.renderNav(buf);
356: assertEquals(html, buf.toString());
357: } catch (Exception e) {
358: e.printStackTrace();
359: fail();
360: }
361: }
362:
363: public void testRenderNav_Cur1Hide2() {
364: try {
365: site = new TestSite();
366: site.createLinks();
367:
368: renderer1_.setRoot(site.link1_);
369: renderer1_.setCur(site.link1_);
370: site.link2_.setHidden(true);
371:
372: html = "<ul>\n"
373: + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
374: + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
375: + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
376: + "</ul>\n";
377:
378: buf = new StringBuffer();
379: renderer1_.renderNav(buf);
380: assertEquals(html, buf.toString());
381: } catch (Exception e) {
382: e.printStackTrace();
383: fail();
384: }
385: }
386:
387: public void testGetNavHtml() {
388: try {
389: site = new TestSite();
390: site.createLinks();
391:
392: renderer1_.setRoot(site.link1_);
393: renderer1_.setCur(site.link1_);
394: site.link2_.setHidden(true);
395:
396: html = "<ul>\n"
397: + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
398: + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
399: + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
400: + "</ul>\n";
401:
402: assertEquals(html, renderer1_.getNavHtml());
403: } catch (Exception e) {
404: e.printStackTrace();
405: fail();
406: }
407: }
408: }
|