KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestBLinkRender.java,v 1.18 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 TestBLinkRender extends DefaultTestCase {
42     //common vars (customize for every test class)
43
private static String JavaDoc testClass = TestBLinkRender.class.getName();
44     private static Logger logger = Logger.getLogger("test."+testClass);
45
46     //variables
47

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

52     public TestBLinkRender(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 testBLinkRender() throws IOException, RenderException {
83
84         //render the doc
85
if (logger.isInfoEnabled()) logger.info("testing BLink render");
86         CompEx5 cg = new CompEx5();
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 'visibility failed' messages in the doc
108
int fpos = html.indexOf("basic component visibility failed");
109         assertTrue("BComponent render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0);
110
111         //assert that there are no 'link failed' messages in the doc
112
fpos = html.indexOf("link failed");
113         assertTrue("BLink render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0);
114
115     }
116 }
117
Popular Tags