001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: JellyTest.java,v 1.2 2006/09/29 12:32:09 drmlipp Exp $
021: *
022: * $Log: JellyTest.java,v $
023: * Revision 1.2 2006/09/29 12:32:09 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.1 2004/08/18 15:18:47 drmlipp
027: * Update to 1.2
028: *
029: * Revision 1.2 2004/06/28 14:58:33 lipp
030: * Got test running.
031: *
032: * Revision 1.1 2004/06/23 15:07:35 lipp
033: * Jelly evaluation.
034: *
035: */
036: package util;
037:
038: import java.io.File;
039: import java.io.FileReader;
040:
041: import javax.xml.parsers.SAXParser;
042: import javax.xml.parsers.SAXParserFactory;
043:
044: import org.apache.commons.jelly.JellyContext;
045: import org.apache.commons.jelly.Script;
046: import org.apache.commons.jelly.XMLOutput;
047: import org.apache.commons.jelly.parser.XMLParser;
048:
049: import org.xml.sax.InputSource;
050: import org.xml.sax.SAXException;
051: import org.xml.sax.XMLReader;
052:
053: import de.danet.an.util.sax.NamespaceAttributesFilter;
054: import de.danet.an.util.sax.SAXEventLogger;
055: import de.danet.an.util.sax.XmlnsUrisPatcher;
056:
057: import junit.framework.Test;
058: import junit.framework.TestCase;
059: import junit.framework.TestSuite;
060:
061: /**
062: * This class provides ...
063: *
064: * @author <a href="mailto:lipp@danet.de"></a>
065: * @version $Revision: 1.2 $
066: */
067: /**
068: * Test class for sax utility classes
069: */
070: public class JellyTest extends TestCase {
071:
072: /**
073: * Konstruktor zum Erzeugen eines TestCase
074: */
075: public JellyTest(String name) {
076: super (name);
077: }
078:
079: /**
080: * Assembling the test suite
081: */
082: public static Test suite() throws Exception {
083: TestSuite suite = new TestSuite();
084: // suite.addTest(new JellyTest("runScript"));
085: suite.addTest(new JellyTest("runEvents"));
086: return suite;
087: }
088:
089: /**
090: * Simple parsing test
091: */
092: public void runScript() throws Exception {
093: JellyContext context = new JellyContext();
094: XMLOutput xmlOutput = XMLOutput.createXMLOutput(System.out);
095: context.runScript(new File("util/test.jelly"), xmlOutput);
096: xmlOutput.flush();
097: }
098:
099: private class ExtXMLParser extends XMLParser {
100: public void configure() {
101: super .configure();
102: }
103: }
104:
105: /**
106: * Simple parsing test
107: */
108: public void runEvents() throws Exception {
109: SAXParserFactory pf = SAXParserFactory.newInstance();
110: pf.setValidating(false);
111: pf.setNamespaceAware(true);
112: pf.setFeature("http://xml.org/sax/features/namespace-prefixes",
113: true);
114: XMLReader reader = null;
115: try {
116: pf.setFeature("http://xml.org/sax/features/xmlns-uris",
117: true);
118: SAXParser parser = pf.newSAXParser();
119: reader = parser.getXMLReader();
120: } catch (SAXException e) {
121: SAXParser parser = pf.newSAXParser();
122: reader = new XmlnsUrisPatcher(parser.getXMLReader());
123: }
124: InputSource inSrc = new InputSource(new FileReader(new File(
125: "util/test.jelly")));
126:
127: JellyContext context = new JellyContext();
128: ExtXMLParser jellyParser = new ExtXMLParser();
129: jellyParser.setContext(context);
130: jellyParser.configure();
131: reader.setContentHandler(new NamespaceAttributesFilter(
132: jellyParser));
133: reader.parse(inSrc);
134: Script script = jellyParser.getScript();
135: script.compile();
136: script.run(context, XMLOutput.createXMLOutput(System.out));
137: }
138: }
|