KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > xml > MiscTests


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: MiscTests.java,v 1.2 2005/01/26 08:29:25 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.xml;
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.driver.TestException;
31 import org.enhydra.xml.xmlc.XMLObject;
32 import org.enhydra.xml.xmlc.driver.ExecXmlc;
33 import org.w3c.dom.DocumentType JavaDoc;
34
35 /**
36  * Various tests that we did put anywhere else.
37  */

38 public class MiscTests extends XmlTestCaseBase {
39
40     /** Factory method to create suite of these tests */
41     public static Test suite() {
42         return createSuite(MiscTests.class, null);
43     }
44     
45     /** Constructor */
46     public MiscTests(Method JavaDoc method) {
47         super(method);
48     }
49
50     /**
51      * Test 1: Try compile document that needs a xcatalog, but
52      * not specifying it.
53      */

54     public void test1() {
55         XmlBasicTest test
56             = new XmlBasicTest(this, getInputFile("xcatalog/index.wml"), null);
57         test.setCompileShouldFail();
58         test.basicTest();
59     }
60
61     /**
62      * Test 2: Compile with xcatalog
63      */

64     public void test2() {
65         XmlBasicTest test
66             = new XmlBasicTest(this, getInputFile("xcatalog/index.wml"), null);
67         test.addBoth(ExecXmlc.OPT_XCATALOG,
68                      getInputFile("xcatalog/wml.xcat"));
69         test.basicTest();
70     }
71
72     /**
73      * Test 3: access via URIs: explicit file
74      */

75     private void disable_test3() {
76         //FIXME: disabled, need to figure out how to do this with input mapping
77
XmlBasicTest test
78             = new XmlBasicTest(this, getInputFile("file:input/xml-examples/6-1.xml"),
79                                getInputFile("xml-examples/document.dtd"));
80         test.basicTest();
81     }
82
83     /**
84      * Test 4: access via URIs: ../xxx relative file
85      */

86     private void disable_test4() {
87         //FIXME: disabled, need to figure out how to do this with input mapping
88
XmlBasicTest test
89             = new XmlBasicTest(this, getInputFile("file:../xml/input/xml-examples/6-1.xml"),
90                                getInputFile("xml-examples/document.dtd"));
91         test.basicTest();
92     }
93
94     /**
95      * Test 5: access via URIs: ../../xxx relative file
96      */

97     private void disable_test5() {
98         //FIXME: disabled, need to figure out how to do this with input mapping
99
XmlBasicTest test
100             = new XmlBasicTest(this,
101                                getInputFile("file:../../xmlc/xml/input/xml-examples/6-1.xml"),
102                                getInputFile("../xml/input/xml-examples/document.dtd"));
103         test.basicTest();
104     }
105
106     /**
107      * Test 6: Compiling SSI file without enabling SSI processing.
108      */

109     public void test6() {
110         XmlBasicTest test
111             = new XmlBasicTest(this, getInputFile("bioml/small-ssi.bioml"),
112                                getInputFile("bioml/bioml.dtd"));
113         test.basicTest();
114     }
115
116     /**
117      * Test 7: Compiling with SSI processing.
118      */

119     public void test7() {
120         XmlBasicTest test
121             = new XmlBasicTest(this, getInputFile("bioml/small-ssi.bioml"),
122                                getInputFile("bioml/bioml.dtd"));
123         test.addBoth(ExecXmlc.OPT_SSI);
124         test.basicTest();
125     }
126
127     /**
128      * Test 8:
129      */

130     public void test8() {
131         XmlBasicTest test
132             = new XmlBasicTest(this, getInputFile("bioml/error-ssi.bioml"),
133                                getInputFile("bioml/bioml.dtd"));
134         test.setCompileShouldFail();
135         test.addBoth(ExecXmlc.OPT_SSI);
136         test.basicTest();
137     }
138
139     /**
140      * Test 9: Whitespace handling
141      */

142     public void test9() {
143         XmlBasicTest test
144             = new XmlBasicTest(this, getInputFile("bioml/space-preserve.bioml"),
145                                getInputFile("bioml/bioml.dtd"));
146         test.basicTest();
147     }
148
149     /**
150      * Test 10: Bug regression. This was a bug were the DocumentType was not
151      * being generated for LazyDOM, this combined with incorrect resetting of
152      * the node ids, results in the compiled-in node ids being out-of-sync
153      * with the DOM, and a class-cast exception when an Element was access via
154      * it's node id.
155      */

156     public void test10() throws TestException {
157         // compile
158
ExecXmlc execXmlc = new ExecXmlc(this);
159         execXmlc.addOpt(ExecXmlc.OPT_CLASS, getTestClass());
160         execXmlc.addOpt(ExecXmlc.OPT_DEST_DIR, getClassRoot());
161         execXmlc.addClassPath(getClassRoot());
162         execXmlc.setSrcFile(getInputFile("regression/Error.xml"));
163         if (getParams().getReloading()) {
164             execXmlc.addOpt(ExecXmlc.OPT_FOR_RECOMP);
165         }
166         if (true) {
167             // only needed when debugging.
168
execXmlc.addOpt(ExecXmlc.OPT_SOURCE_OUT,
169                              getGenSourceDir().getPath());
170             execXmlc.addOpt(ExecXmlc.OPT_KEEP);
171             execXmlc.addOpt(ExecXmlc.OPT_DUMP);
172         }
173
174         File JavaDoc outFile = getResultFile("compile.out");
175         File JavaDoc expectFile = getExpectedFile("compile.out");
176         execXmlc.compile(outFile);
177         getDiffer().diff(expectFile, outFile);
178
179         // Check the document..
180
XMLObject doc = loadTestDocument(getTestClass());
181
182         // make sure we have the correct document type.
183
String JavaDoc docTypeSystemId = "AirSent.dtd";
184         DocumentType JavaDoc docType = doc.getDoctype();
185         if (docType == null) {
186             throw new TestException("no document type node");
187         } else if (!docType.getSystemId().equals(docTypeSystemId)) {
188             throw new TestException("Incorrect document type system id: expected \""
189                                     + docTypeSystemId + "\", got \""
190                                     + docType.getSystemId() + "\"");
191         }
192
193         // test generated setTextError(String);
194
try {
195             Method JavaDoc setText = doc.getClass().getMethod("setTextErrorMessage",
196                                                       new Class JavaDoc[]{String JavaDoc.class});
197             setText.invoke(doc, new Object JavaDoc[]{"game over, man"});
198         } catch (Exception JavaDoc except) {
199             throw new TestException(except);
200         }
201     }
202 }
203
Popular Tags