/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: JellyTest.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.1 2004/08/18 15:18:47 drmlipp
* Update to 1.2
*
* Revision 1.2 2004/06/28 14:58:33 lipp
* Got test running.
*
* Revision 1.1 2004/06/23 15:07:35 lipp
* Jelly evaluation.
*
*/
package util;
import java.io.File;
import java.io.FileReader;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.parser.XMLParser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import de.danet.an.util.sax.NamespaceAttributesFilter;
import de.danet.an.util.sax.SAXEventLogger;
import de.danet.an.util.sax.XmlnsUrisPatcher;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* This class provides ...
*
* @author <a href="mailto:lipp@danet.de"></a>
* @version $Revision: 1607 $
*/
/**
* Test class for sax utility classes
*/
public class JellyTest extends TestCase {
/**
* Konstruktor zum Erzeugen eines TestCase
*/
public JellyTest (String name) {
super (name);
}
/**
* Assembling the test suite
*/
public static Test suite() throws Exception {
TestSuite suite = new TestSuite();
// suite.addTest(new JellyTest("runScript"));
suite.addTest(new JellyTest("runEvents"));
return suite;
}
/**
* Simple parsing test
*/
public void runScript() throws Exception {
JellyContext context = new JellyContext();
XMLOutput xmlOutput = XMLOutput.createXMLOutput(System.out);
context.runScript(new File ("util/test.jelly"), xmlOutput);
xmlOutput.flush();
}
private class ExtXMLParser extends XMLParser {
public void configure () {
super.configure ();
}
}
/**
* Simple parsing test
*/
public void runEvents() throws Exception {
SAXParserFactory pf = SAXParserFactory.newInstance();
pf.setValidating (false);
pf.setNamespaceAware (true);
pf.setFeature ("http://xml.org/sax/features/namespace-prefixes", true);
XMLReader reader = null;
try {
pf.setFeature
("http://xml.org/sax/features/xmlns-uris", true);
SAXParser parser = pf.newSAXParser();
reader = parser.getXMLReader();
} catch (SAXException e) {
SAXParser parser = pf.newSAXParser();
reader = new XmlnsUrisPatcher (parser.getXMLReader());
}
InputSource inSrc = new InputSource
(new FileReader(new File ("util/test.jelly")));
JellyContext context = new JellyContext();
ExtXMLParser jellyParser = new ExtXMLParser ();
jellyParser.setContext(context);
jellyParser.configure ();
reader.setContentHandler(new NamespaceAttributesFilter(jellyParser));
reader.parse (inSrc);
Script script = jellyParser.getScript ();
script.compile ();
script.run (context, XMLOutput.createXMLOutput(System.out));
}
}