KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > metadata > BasicTests


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

23
24 package org.enhydra.xml.xmlc.metadata;
25
26 import java.io.File JavaDoc;
27 import java.io.FileWriter JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31
32 import junit.framework.Test;
33
34 import org.enhydra.xml.dom.DOMInfo;
35 import org.enhydra.xml.driver.TestCaseBase;
36 import org.enhydra.xml.driver.TestException;
37 import org.enhydra.xml.io.ErrorReporter;
38 import org.enhydra.xml.xmlc.XMLCException;
39 import org.xml.sax.InputSource JavaDoc;
40 import org.xml.sax.SAXException JavaDoc;
41
42 /**
43  * Tests of metadata file parsing.
44  */

45 public class BasicTests extends TestCaseBase {
46     /** XMLC schema */
47     private static final String JavaDoc XMLC_XSD
48         = "../../../../../../org/enhydra/xml/xmlc/metadata/xmlc-1.0.2.xsd";
49
50     /** Factory method to create suite of these tests */
51     public static Test suite() {
52         return createSuite(BasicTests.class, null);
53     }
54     
55     /** Constructor */
56     public BasicTests(Method JavaDoc method) {
57         super(method);
58     }
59
60     /**
61      * Parse file, dump and validate.
62      */

63     private MetaDataDocument parseDump(File JavaDoc xmlcFile,
64                                        String JavaDoc outExt)
65         throws IOException JavaDoc,
66                SAXException JavaDoc,
67                XMLCException {
68         File JavaDoc outFile = getResultFile(outExt);
69         File JavaDoc expectFile = getExpectedFile(outExt);
70
71         outFile.getParentFile().mkdirs();
72         PrintWriter JavaDoc out = new PrintWriter JavaDoc(new FileWriter JavaDoc(outFile));
73         MetaDataDocument metaDataDoc;
74         try {
75             metaDataDoc
76                 = MetaDataDocument.parseMetaData(new InputSource JavaDoc(xmlcFile.getPath()),
77                                                  new ErrorReporter(out),
78                                                  null);
79             DOMInfo.printTree(xmlcFile.getPath(), metaDataDoc, out);
80         } finally {
81             out.close();
82         }
83         getDiffer().diff(expectFile, outFile);
84         return metaDataDoc;
85     }
86
87         
88     /**
89      * Common routine used to implement the tests
90      */

91     private void testParseMetaData(File JavaDoc xmlcFile) {
92         try {
93             MetaDataDocument doc = parseDump(xmlcFile, "1.dump");
94             File JavaDoc docOut = getResultFile("xmlc");
95             doc.serialize(docOut);
96             parseDump(docOut, "2.dump");
97         } catch (IOException JavaDoc except) {
98             throw new TestException(except);
99         } catch (SAXException JavaDoc except) {
100             throw new TestException(except);
101         } catch (XMLCException except) {
102             throw new TestException(except);
103         }
104     }
105
106     /**
107      * Test 1: Parse file with most tags
108      */

109     public void test1() {
110         testParseMetaData(getInputFile("most-xml-1.1.xmlc"));
111     }
112
113     /**
114      * Test 2: Document with empty sections
115      */

116     public void test2() {
117         testParseMetaData(getInputFile("empty-sections.xmlc"));
118     }
119
120     /**
121      * Test 3: Creating new metadata document
122      */

123     public void test3() throws XMLCException {
124         // setup a new document with some stuff...
125
MetaDataDocument doc = MetaDataDocument.newInstance();
126         MetaData metaData = doc.getMetaData();
127         InputDocument inputDoc = metaData.getInputDocument();
128         inputDoc.setProcessSSI(true);
129         inputDoc.setDocumentFormat(DocumentFormat.XML);
130
131         // Output and reparse
132
File JavaDoc createdFile = getResultFile("new.xmlc");
133         doc.serialize(createdFile);
134         testParseMetaData(createdFile);
135     }
136
137     /**
138      * Test 3: Backwards compaibility with xmlc-1.0.xsd
139      */

140     public void disable_test3() {
141         // Disabled due to Xerces not being backwards compatible
142
testParseMetaData(getInputFile("most-xml-1.0.xmlc"));
143     }
144
145     /**
146      * Test 4: Backwards compaibility with xmlc-1.0.1.xsd
147      */

148     private void disable_test4() {
149         // Disabled due to Xerces not being backwards compatible
150
testParseMetaData(getInputFile("most-xml-1.0.1.xmlc"));
151     }
152 }
153
Popular Tags