KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > html > ExtendsTests


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: ExtendsTests.java,v 1.2 2005/01/26 08:29:25 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.html;
25 import java.io.File JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27
28 import junit.framework.Test;
29
30 import org.enhydra.xml.xmlc.XMLObject;
31 import org.enhydra.xml.xmlc.driver.ExecXmlc;
32
33 /**
34  * Tests of generating classes where super class or interfaces are specified.
35  */

36 public class ExtendsTests extends HtmlTestCaseBase {
37     /** Interfaces a generated interface must be an instanceof */
38     private final String JavaDoc[] INTERFACE_INSTANCEOF = {
39     "org.enhydra.xml.xmlc.XMLObject",
40     "org.enhydra.xml.xmlc.html.HTMLObject",
41     "org.w3c.dom.html.HTMLDocument"
42     };
43
44     /** Interfaces a generated interface must not be an instanceof */
45     private final String JavaDoc[] INTERFACE_NOT_INSTANCEOF = {
46     "org.enhydra.xml.xmlc.XMLObjectImpl",
47     "org.enhydra.xml.xmlc.html.HTMLObjectImpl"
48     };
49
50     /** Interfaces/classes a generated class must be an instanceof */
51     private final String JavaDoc[] IMPLEMENTATION_INSTANCEOF = {
52     "org.enhydra.xml.xmlc.XMLObject",
53     "org.enhydra.xml.xmlc.XMLObjectImpl",
54     "org.enhydra.xml.xmlc.html.HTMLObject",
55     "org.enhydra.xml.xmlc.html.HTMLObjectImpl",
56     "org.w3c.dom.html.HTMLDocument"
57     };
58
59     /** Factory method to create suite of these tests */
60     public static Test suite() {
61         return createSuite(ExtendsTests.class, null);
62     }
63     
64     /** Constructor */
65     public ExtendsTests(Method JavaDoc method) {
66         super(method);
67     }
68
69     /**
70      * Do standard verification for an generate class.
71      */

72     private void verifyClass(XMLObject doc,
73                              Class JavaDoc xtraImpl) {
74         verifyIsClass(doc.getClass());
75         verifyInstanceOf(doc.getClass(),
76                          IMPLEMENTATION_INSTANCEOF);
77         if (xtraImpl != null) {
78             verifyInstanceOf(doc.getClass(), xtraImpl);
79         }
80     }
81
82     /**
83      * Do standard verification for an generate interface.
84      */

85     private void verifyInterface(Class JavaDoc docClass,
86                                  Class JavaDoc xtraImpl) {
87         verifyIsInterface(docClass);
88         verifyInstanceOf(docClass,
89                          INTERFACE_INSTANCEOF);
90         verifyNotInstanceOf(docClass,
91                             INTERFACE_NOT_INSTANCEOF);
92         if (xtraImpl != null) {
93             verifyInstanceOf(docClass, xtraImpl);
94         }
95     }
96
97     /*
98      * Test 1: -implements
99      */

100     public void test1() {
101         HtmlBasicTest test = createTest("testPage1.html");
102         test.addFirst(ExecXmlc.OPT_IMPLEMENTS,
103                       TestPage1Interface.class.getName());
104         test.basicTest();
105         verifyClass(loadTestDocument(), TestPage1Interface.class);
106     }
107
108     /*
109      * Test 2: -extends
110      */

111     public void test2() {
112         HtmlBasicTest test = createTest("testPage2.html");
113         test.addFirst(ExecXmlc.OPT_EXTENDS,
114                       HTMLObjectBase.class.getName());
115         test.basicTest();
116         if (fParams.getReloading()) {
117             verifyInterface(loadDocClassInterface(), null);
118         }
119         verifyClass(loadTestDocument(), HTMLObjectBase.class);
120     }
121
122     /*
123      * Test 3: generating an interfaces and an implementation, and
124      * implementing an interface.
125      */

126     public void test3() {
127         HtmlBasicTest test = createTest("testPage1.html");
128         setUsingImplInterface();
129         test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_BOTH);
130         test.addFirst(ExecXmlc.OPT_IMPLEMENTS,
131                       TestPage1Interface.class.getName());
132         test.addOptionFile(getInputFile("testPage1.xmlc"));
133         test.basicTest();
134         
135         verifyInterface(loadDocClassInterface(),
136                         TestPage1Interface.class);
137         verifyClass(loadTestDocument(), TestPage1Interface.class);
138     }
139
140     /*
141      * Test 4: generating an interfaces and an implementation, extending
142      * a base class
143      */

144     public void test4() {
145         HtmlBasicTest test = createTest("testPage2.html");
146         setUsingImplInterface();
147         test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_BOTH);
148         test.addFirst(ExecXmlc.OPT_EXTENDS,
149                       HTMLObjectBase.class.getName());
150         test.basicTest();
151         
152         verifyInterface(loadDocClassInterface(), null);
153         verifyClass(loadTestDocument(), HTMLObjectBase.class);
154     }
155
156     /*
157      * Test 5: - not sure what was special about this test
158      */

159     public void test5() {
160         HtmlBasicTest test = createTest("testPage3.html");
161         setUsingImplInterface();
162         test.addFirst(ExecXmlc.OPT_EXTENDS,
163                       HTMLObjectBase.class.getName());
164         test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_BOTH);
165         test.basicTest();
166         verifyInterface(loadDocClassInterface(), null);
167         verifyClass(loadTestDocument(), HTMLObjectBase.class);
168     }
169
170     /*
171      * Test 6: generate an interface and an implementation seperately
172      */

173     public void test6() {
174         HtmlBasicTest test = createTest("testPage3.html");
175         setUsingImplInterface();
176         
177         // Compile the interface
178
test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_INTERFACE);
179         test.compileOriginalStep();
180
181         // now, compile the implementation
182
ExecXmlc execXmlc = new ExecXmlc(this);
183         execXmlc.addOpt(ExecXmlc.OPT_GENERATE,
184                         ExecXmlc.GENERATE_IMPLEMENTATION);
185         execXmlc.addOpt(ExecXmlc.OPT_CLASS, getTestClass());
186         execXmlc.addOpt(ExecXmlc.OPT_DEST_DIR, getClassRoot());
187         execXmlc.addClassPath(getClassRoot());
188         execXmlc.setSrcFile(getInputFile("testPage3.html"));
189
190         File JavaDoc outFile2 = getResultFile("compile2.out");
191         File JavaDoc expectFile2 = getExpectedFile("compile2.out");
192         execXmlc.compile(outFile2);
193         getDiffer().diff(expectFile2, outFile2);
194         
195         // Verify interface and implementation. The test object used to
196
// compile the interface is used to load both so that we get the
197
// same classloader.
198
Class JavaDoc faceClass = loadDocClassInterface();
199         verifyInterface(faceClass, null);
200         verifyClass(loadTestDocument(faceClass), faceClass);
201
202         // finish test now that interface is compiled
203
test.reparseStep();
204     }
205 }
206
Popular Tags