KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > TestBTemplateRender


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: TestBTemplateRender.java,v 1.13 2004/02/01 05:16:32 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp;
21
22 import java.io.*;
23 import java.util.*;
24
25 import org.w3c.dom.*;
26 import junit.framework.*;
27
28 //import org.enhydra.barracuda.plankton.*;
29
//import org.enhydra.barracuda.plankton.data.*;
30
import org.enhydra.barracuda.core.util.dom.*;
31 import org.apache.log4j.*;
32 import org.enhydra.barracuda.core.view.*;
33 import org.enhydra.barracuda.examples.xmlc.*;
34 import org.enhydra.barracuda.testbed.*;
35 import org.enhydra.barracuda.testbed.servlet.*;
36
37
38 /**
39  * This test verifies that BLink works correctly.
40  */

41 public class TestBTemplateRender extends DefaultTestCase {
42     //common vars (customize for every test class)
43
private static String JavaDoc testClass = TestBTemplateRender.class.getName();
44     private static Logger logger = Logger.getLogger("test."+testClass);
45
46     //variables
47

48     //-------------------- Basics --------------------------------
49
/**
50      * Public Constructor
51      */

52     public TestBTemplateRender(String JavaDoc name) {
53         super(name);
54     }
55
56     /**
57      * Every test class should have a main method so it can be run
58      * directly (when debugging tests you often will not want to run
59      * the whole suite)
60      *
61      * @param args defined in test.util.TestUtil
62      */

63     public static void main(String JavaDoc args[]) {
64         //check for standard runtime parameters
65
TestUtil.parseParams(args);
66
67         //launch the test
68
if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String JavaDoc[] {testClass});
69         else junit.swingui.TestRunner.main(new String JavaDoc[] {testClass});
70     }
71
72     
73     //-------------------- Actual Tests --------------------------
74
//Note: all the methods herein should follow the testXXXX naming convention
75
//Also keep in mind that local vars set in one test method are NOT retained
76
//when the next method is invoked because JUnit makes a separate instance of
77
//the test class for each testXXXX method!!!
78

79     /**
80      * Simple test to verify that the component renders as expected
81      */

82     public void testBTemplateRender() throws IOException, RenderException {
83         //render the doc
84
if (logger.isInfoEnabled()) logger.info("testing BTemplate render");
85         CompEx6 cg = new CompEx6();
86         BComponent root = new BComponent();
87         root.initCycle();
88
89         //build a sample view capabilities object
90
MockHttpServletRequest req = new MockHttpServletRequest();
91         req.setHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
92         ViewCapabilities vcap = new ViewCapabilities(req, null);
93 //System.out.println(vcap.toString());
94

95         //create the component amd render
96
ViewContext vc = new DefaultViewContext(vcap, req, null);
97         Document doc = cg.handleDefault(root, vc, req, null);
98         root.render(vc);
99         root.destroyCycle();
100         DefaultDOMWriter ddw = new DefaultDOMWriter(false);
101         StringWriter sw = new StringWriter(2000);
102         ddw.write(doc, sw);
103         String JavaDoc html = sw.toString();
104
105 //DOMUtil.printMarkup(doc);
106

107         //assert that there are no 'dir::' messages in the doc (which would
108
//mean there were directives which didn't get parsed)
109
int fpos = html.indexOf("Dir::");
110         assertTrue("BTemplate render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0);
111         fpos = html.indexOf("Iterative Item99"); //this will catch nested iterative directives not getting processed depth-first;
112
assertTrue("BTemplate render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0);
113     }
114 }
115
Popular Tags