KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > view > TestFormatType


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: TestFormatType.java,v 1.8 2004/02/01 05:16:33 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.view;
21
22 import java.io.*;
23 import java.util.*;
24 import java.security.*;
25 import javax.servlet.*;
26 import javax.servlet.http.*;
27
28 import org.w3c.dom.*;
29 import junit.framework.*;
30
31 import org.enhydra.barracuda.plankton.*;
32 import org.enhydra.barracuda.plankton.data.*;
33 import org.enhydra.barracuda.core.util.dom.*;
34 import org.apache.log4j.*;
35 import org.enhydra.barracuda.core.view.*;
36 import org.enhydra.barracuda.examples.xmlc.*;
37 import org.enhydra.barracuda.testbed.*;
38 import org.enhydra.barracuda.testbed.servlet.*;
39
40
41 /**
42  * This test verifies that the hierachical organization of
43  * FormatType classes. We do this by testing for what it should be
44  * an instanceof and what it shouldn't. The idea is that the FormatType
45  * extension hierarchy is very important and we don't want it getting
46  * changed accidentally. This test should preclude that.
47  */

48 public class TestFormatType extends DefaultTestCase {
49     //common vars (customize for every test class)
50
private static String JavaDoc testClass = TestFormatType.class.getName();
51     private static Logger logger = Logger.getLogger("test."+testClass);
52
53     //variables
54
FormatType ft = null;
55     Class JavaDoc targetCl = null;
56     
57     //-------------------- Basics --------------------------------
58
/**
59      * Public Constructor
60      */

61     public TestFormatType(String JavaDoc name) {
62         super(name);
63     }
64
65     public TestFormatType(String JavaDoc name, FormatType ift, Class JavaDoc itargetCl) {
66         super(name);
67         ft = ift;
68         targetCl = itargetCl;
69     }
70     
71     /**
72      * Every test class should have a main method so it can be run
73      * directly (when debugging tests you often will not want to run
74      * the whole suite)
75      *
76      * @param args defined in test.util.TestUtil
77      */

78     public static void main(String JavaDoc args[]) {
79         //check for standard runtime parameters
80
TestUtil.parseParams(args);
81
82         //launch the test
83
if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String JavaDoc[] {testClass});
84         else junit.swingui.TestRunner.main(new String JavaDoc[] {testClass});
85     }
86
87     /**
88      * Return a suite of tests...
89      */

90     public static Test suite() {
91         //create the test suite
92
TestSuite suite = new TestSuite();
93         
94         //add the tests
95
//...HTML_3_0
96
suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_0, FormatType.Html3x.class));
97         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_0, FormatType.Html.class));
98         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_0, FormatType.HtmlBasic.class));
99         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_0, FormatType.AsciiData.class));
100         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_0, FormatType.GenericData.class));
101         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_0, FormatType.Html4x.class));
102         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_0, FormatType.Chtml.class));
103         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_0, FormatType.Xml.class));
104         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_0, FormatType.BinaryData.class));
105         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_0, FormatType.UnknownFormat.class));
106         //...HTML_3_1
107
suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_1, FormatType.Html3x.class));
108         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_1, FormatType.Html.class));
109         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_1, FormatType.HtmlBasic.class));
110         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_1, FormatType.AsciiData.class));
111         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_1, FormatType.GenericData.class));
112         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_1, FormatType.Html4x.class));
113         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_1, FormatType.Chtml.class));
114         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_1, FormatType.Xml.class));
115         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_1, FormatType.BinaryData.class));
116         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_1, FormatType.UnknownFormat.class));
117         //...HTML_3_2
118
suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_2, FormatType.Html3x.class));
119         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_2, FormatType.Html.class));
120         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_2, FormatType.HtmlBasic.class));
121         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_2, FormatType.AsciiData.class));
122         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_3_2, FormatType.GenericData.class));
123         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_2, FormatType.Html4x.class));
124         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_2, FormatType.Chtml.class));
125         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_2, FormatType.Xml.class));
126         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_2, FormatType.BinaryData.class));
127         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_3_2, FormatType.UnknownFormat.class));
128         //...HTML_4_0
129
suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_0, FormatType.Html4x.class));
130         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_0, FormatType.Html3x.class));
131         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_0, FormatType.Html.class));
132         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_0, FormatType.HtmlBasic.class));
133         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_0, FormatType.AsciiData.class));
134         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_0, FormatType.GenericData.class));
135         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_0, FormatType.Chtml.class));
136         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_0, FormatType.Xml.class));
137         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_0, FormatType.BinaryData.class));
138         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_0, FormatType.UnknownFormat.class));
139         //...HTML_4_1
140
suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_1, FormatType.Html4x.class));
141         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_1, FormatType.Html3x.class));
142         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_1, FormatType.Html.class));
143         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_1, FormatType.HtmlBasic.class));
144         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_1, FormatType.AsciiData.class));
145         suite.addTest(new TestFormatType("testInstance", FormatType.HTML_4_1, FormatType.GenericData.class));
146         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_1, FormatType.Chtml.class));
147         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_1, FormatType.Xml.class));
148         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_1, FormatType.BinaryData.class));
149         suite.addTest(new TestFormatType("testNotInstance", FormatType.HTML_4_1, FormatType.UnknownFormat.class));
150         //...CHTML_1_0
151
suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_1_0, FormatType.Chtml1x.class));
152         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_1_0, FormatType.Chtml.class));
153         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_1_0, FormatType.HtmlBasic.class));
154         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_1_0, FormatType.AsciiData.class));
155         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_1_0, FormatType.GenericData.class));
156         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_1_0, FormatType.Chtml2x.class));
157         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_1_0, FormatType.Html.class));
158         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_1_0, FormatType.Xml.class));
159         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_1_0, FormatType.BinaryData.class));
160         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_1_0, FormatType.UnknownFormat.class));
161         //...CHTML_2_0
162
suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_2_0, FormatType.Chtml2x.class));
163         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_2_0, FormatType.Chtml1x.class));
164         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_2_0, FormatType.Chtml.class));
165         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_2_0, FormatType.HtmlBasic.class));
166         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_2_0, FormatType.AsciiData.class));
167         suite.addTest(new TestFormatType("testInstance", FormatType.CHTML_2_0, FormatType.GenericData.class));
168         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_2_0, FormatType.Html.class));
169         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_2_0, FormatType.Xml.class));
170         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_2_0, FormatType.BinaryData.class));
171         suite.addTest(new TestFormatType("testNotInstance", FormatType.CHTML_2_0, FormatType.UnknownFormat.class));
172         //...XML_1_0
173
suite.addTest(new TestFormatType("testInstance", FormatType.XML_1_0, FormatType.Xml1x.class));
174         suite.addTest(new TestFormatType("testInstance", FormatType.XML_1_0, FormatType.Xml.class));
175         suite.addTest(new TestFormatType("testInstance", FormatType.XML_1_0, FormatType.AsciiData.class));
176         suite.addTest(new TestFormatType("testInstance", FormatType.XML_1_0, FormatType.GenericData.class));
177         suite.addTest(new TestFormatType("testNotInstance", FormatType.XML_1_0, FormatType.Vxml.class));
178         suite.addTest(new TestFormatType("testNotInstance", FormatType.XML_1_0, FormatType.Wml.class));
179         suite.addTest(new TestFormatType("testNotInstance", FormatType.XML_1_0, FormatType.Xhtml.class));
180         suite.addTest(new TestFormatType("testNotInstance", FormatType.XML_1_0, FormatType.HtmlBasic.class));
181         suite.addTest(new TestFormatType("testNotInstance", FormatType.XML_1_0, FormatType.BinaryData.class));
182         suite.addTest(new TestFormatType("testNotInstance", FormatType.XML_1_0, FormatType.UnknownFormat.class));
183         //...VXML_1_0
184
suite.addTest(new TestFormatType("testInstance", FormatType.VXML_1_0, FormatType.Vxml1x.class));
185         suite.addTest(new TestFormatType("testInstance", FormatType.VXML_1_0, FormatType.Vxml.class));
186         suite.addTest(new TestFormatType("testInstance", FormatType.VXML_1_0, FormatType.Xml.class));
187         suite.addTest(new TestFormatType("testInstance", FormatType.VXML_1_0, FormatType.AsciiData.class));
188         suite.addTest(new TestFormatType("testInstance", FormatType.VXML_1_0, FormatType.GenericData.class));
189         suite.addTest(new TestFormatType("testNotInstance", FormatType.VXML_1_0, FormatType.Xml1x.class));
190         suite.addTest(new TestFormatType("testNotInstance", FormatType.VXML_1_0, FormatType.Wml.class));
191         suite.addTest(new TestFormatType("testNotInstance", FormatType.VXML_1_0, FormatType.Xhtml.class));
192         suite.addTest(new TestFormatType("testNotInstance", FormatType.VXML_1_0, FormatType.HtmlBasic.class));
193         suite.addTest(new TestFormatType("testNotInstance", FormatType.VXML_1_0, FormatType.BinaryData.class));
194         suite.addTest(new TestFormatType("testNotInstance", FormatType.VXML_1_0, FormatType.UnknownFormat.class));
195         //...WML_1_0
196
suite.addTest(new TestFormatType("testInstance", FormatType.WML_1_0, FormatType.Wml1x.class));
197         suite.addTest(new TestFormatType("testInstance", FormatType.WML_1_0, FormatType.Wml.class));
198         suite.addTest(new TestFormatType("testInstance", FormatType.WML_1_0, FormatType.Xml.class));
199         suite.addTest(new TestFormatType("testInstance", FormatType.WML_1_0, FormatType.AsciiData.class));
200         suite.addTest(new TestFormatType("testInstance", FormatType.WML_1_0, FormatType.GenericData.class));
201         suite.addTest(new TestFormatType("testNotInstance", FormatType.WML_1_0, FormatType.Xml1x.class));
202         suite.addTest(new TestFormatType("testNotInstance", FormatType.WML_1_0, FormatType.Vxml.class));
203         suite.addTest(new TestFormatType("testNotInstance", FormatType.WML_1_0, FormatType.Xhtml.class));
204         suite.addTest(new TestFormatType("testNotInstance", FormatType.WML_1_0, FormatType.HtmlBasic.class));
205         suite.addTest(new TestFormatType("testNotInstance", FormatType.WML_1_0, FormatType.BinaryData.class));
206         suite.addTest(new TestFormatType("testNotInstance", FormatType.WML_1_0, FormatType.UnknownFormat.class));
207         //...XHTML_BASIC_1_0
208
suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_BASIC_1_0, FormatType.XhtmlBasic1x.class));
209         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_BASIC_1_0, FormatType.XhtmlBasic.class));
210         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_BASIC_1_0, FormatType.Xhtml.class));
211         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_BASIC_1_0, FormatType.Xml.class));
212         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_BASIC_1_0, FormatType.AsciiData.class));
213         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_BASIC_1_0, FormatType.GenericData.class));
214         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.XhtmlBasic2x.class));
215         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.XhtmlStandard.class));
216         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.Xml1x.class));
217         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.Vxml.class));
218         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.Wml.class));
219         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.HtmlBasic.class));
220         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.BinaryData.class));
221         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_BASIC_1_0, FormatType.UnknownFormat.class));
222         //...XHTML_STANDARD_1_0
223
suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.XhtmlStandard1x.class));
224         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.XhtmlStandard.class));
225         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.XhtmlBasic1x.class));
226         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.XhtmlBasic.class));
227         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.Xhtml.class));
228         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.Xml.class));
229         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.AsciiData.class));
230         suite.addTest(new TestFormatType("testInstance", FormatType.XHTML_STANDARD_1_0, FormatType.GenericData.class));
231         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.XhtmlStandard2x.class));
232         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.XhtmlBasic2x.class));
233         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.Xml1x.class));
234         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.Vxml.class));
235         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.Wml.class));
236         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.HtmlBasic.class));
237         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.BinaryData.class));
238         suite.addTest(new TestFormatType("testNotInstance", FormatType.XHTML_STANDARD_1_0, FormatType.UnknownFormat.class));
239         //...UNKNOWN_FORMAT
240
suite.addTest(new TestFormatType("testInstance", FormatType.UNKNOWN_FORMAT, FormatType.UnknownFormat.class));
241         suite.addTest(new TestFormatType("testInstance", FormatType.UNKNOWN_FORMAT, FormatType.GenericData.class));
242         suite.addTest(new TestFormatType("testNotInstance", FormatType.UNKNOWN_FORMAT, FormatType.AsciiData.class));
243         suite.addTest(new TestFormatType("testNotInstance", FormatType.UNKNOWN_FORMAT, FormatType.BinaryData.class));
244
245         //finally return the suite
246
return suite;
247     }
248
249
250     //-------------------- Actual Tests --------------------------
251
//Note: all the methods herein should follow the testXXXX naming convention
252
//Also keep in mind that local vars set in one test method are NOT retained
253
//when the next method is invoked because JUnit makes a separate instance of
254
//the test class for each testXXXX method!!!
255

256     /**
257      * Make sure that the class being tested IS an instance of the
258      * target class
259      */

260     public void testInstance() {
261         if (logger.isInfoEnabled()) logger.info("testing instanceof");
262         assertTrue(ft+" not an instanceof "+targetCl, targetCl.isAssignableFrom(ft.getClass()));
263     }
264
265     /**
266      * Make sure that the class being tested is NOT an instance of the
267      * target class
268      */

269     public void testNotInstance() {
270         if (logger.isInfoEnabled()) logger.info("testing !instanceof");
271         assertTrue(ft+" is an instanceof "+targetCl+" (and it shouldn't be!)", !targetCl.isAssignableFrom(ft.getClass()));
272     }
273 }
274
Popular Tags