KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestBasicComponentsRender.java,v 1.12 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 import org.apache.log4j.*;
28 import org.apache.log4j.xml.*;
29
30 //import org.enhydra.barracuda.plankton.*;
31
//import org.enhydra.barracuda.plankton.data.*;
32
import org.enhydra.barracuda.core.util.dom.*;
33 import org.enhydra.barracuda.core.view.*;
34 import org.enhydra.barracuda.examples.xmlc.*;
35 import org.enhydra.barracuda.testbed.*;
36 import org.enhydra.barracuda.testbed.servlet.*;
37
38
39 /**
40  * This test verifies the basic component renderings
41  */

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

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

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

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

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

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

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

107         //assert that there are no 'link failed' messages in the doc
108
int fpos = html.indexOf("render failed");
109         assertTrue("BLink render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0);
110
111     }
112 }
113
Popular Tags