Permalink
Browse files

Attempt to get some useful JUnit tests. Several are broken, but in pa…

…rticular, the test suite can now be run using JUnit
  • Loading branch information...
ndw committed Aug 19, 2014
1 parent 3e0a8da commit 7b30f0a42e65b20a98f48a54df07b70232128883
View
@@ -25,6 +25,7 @@
<property name="dist.dir" value="dist"/>
<property name="build.dir" value="out/production/Calabash"/>
+ <property name="test.dir" value="out/test/Calabash"/>
<property name="docs.repo.dir" value="../docs-calabash"/>
<!-- where my Saxon EE license lives -->
@@ -93,6 +94,14 @@
</fileset>
</path>
+ <path id="test.classpath">
+ <pathelement location="${license.dir}"/>
+ <fileset dir="${lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <pathelement path="${test.dir}/com/xmlcalabash/testsuite"/>
+ </path>
+
<available property="saxon94"
classname="net.sf.saxon.expr.flwor.ForClause">
<classpath refid="build.classpath"/>
@@ -502,17 +511,16 @@ java -Xmx1024m -jar %INSTALL_PATH/calabash.jar "$@"
<target name="test" depends="jar">
<echo>Running test...</echo>
- <java fork="true" classname="com.xmlcalabash.drivers.RunTestReport">
- <classpath>
- <pathelement location="calabash.jar"/>
- <path refid="full.classpath"/>
- </classpath>
+ <junit printsummary="yes" haltonfailure="no">
+ <classpath refid="test.classpath"/>
<jvmarg value="-Xmx1024m"/>
- <jvmarg value="-Djava.util.logging.config.file=/home/ndw/java/logging.properties"/>
- <arg value="-D"/>
- <arg value="-a"/>
- <arg value="http://tests.xproc.org/tests/serialization/version-001.xml"/>
- </java>
+ <formatter type="plain" usefile="false"/>
+ <test name="com.xmlcalabash.testsuite.TestRequired"/>
+ <test name="com.xmlcalabash.testsuite.TestOptional"/>
+ <test name="com.xmlcalabash.testsuite.TestSerialization"/>
+ <test name="com.xmlcalabash.testsuite.TestExtension"/>
+ <test name="com.xmlcalabash.testsuite.TestXMLCalabash"/>
+ </junit>
</target>
<target name="test-suite" depends="jar">
@@ -0,0 +1,105 @@
+package com.xmlcalabash.drivers;
+
+import net.sf.saxon.s9api.SaxonApiException;
+import net.sf.saxon.s9api.XsltCompiler;
+import net.sf.saxon.s9api.XsltExecutable;
+import net.sf.saxon.s9api.XsltTransformer;
+import net.sf.saxon.s9api.QName;
+import net.sf.saxon.s9api.XdmAtomicValue;
+import net.sf.saxon.s9api.XdmDestination;
+import net.sf.saxon.s9api.XdmNode;
+import net.sf.saxon.s9api.Processor;
+import net.sf.saxon.s9api.DocumentBuilder;
+import net.sf.saxon.s9api.Axis;
+import net.sf.saxon.s9api.XdmSequenceIterator;
+import net.sf.saxon.Configuration;
+import net.sf.saxon.lib.OutputURIResolver;
+import net.sf.saxon.lib.CollectionURIResolver;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URISyntaxException;
+
+import com.xmlcalabash.util.CollectionResolver;
+import com.xmlcalabash.model.RuntimeValue;
+import org.xml.sax.InputSource;
+
+import javax.xml.transform.sax.SAXSource;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ndw
+ * Date: Nov 27, 2008
+ * Time: 11:45:52 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class BaseURITest {
+ public static void main(String[] args) throws SaxonApiException, IOException, URISyntaxException {
+ BaseURITest test = new BaseURITest();
+ test.run();
+ }
+
+ public void run() throws SaxonApiException {
+ Processor processor = new Processor(false);
+ Configuration config = processor.getUnderlyingConfiguration();
+
+ String textStyle = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\n"
+ + " version='2.0'>\n"
+ + "\n"
+ + "<xsl:output method='xml' encoding='utf-8' indent='no'\n"
+ + " omit-xml-declaration='yes'/>\n"
+ + "\n"
+ + "<xsl:preserve-space elements='*'/>\n"
+ + "\n"
+ + "<xsl:template match='/'>\n"
+ + " <xsl:apply-templates/>\n"
+ + "</xsl:template>\n"
+ + "\n"
+ + "<xsl:template match='*'>\n"
+ + " <xsl:copy>\n"
+ + " <xsl:copy-of select='@*'/>\n"
+ + " <xsl:apply-templates/>\n"
+ + " </xsl:copy>\n"
+ + "</xsl:template>\n"
+ + "\n"
+ + "<xsl:template match='comment()|processing-instruction()|text()'>\n"
+ + " <xsl:copy/>\n"
+ + "</xsl:template>\n"
+ + "\n"
+ + "</xsl:stylesheet>\n";
+
+
+ String textXML = "<doc xml:base='foo/'><para xml:base='bar/'/></doc>";
+
+ SAXSource stylesheet = new SAXSource(new InputSource(new StringReader(textStyle)));
+
+ XsltCompiler compiler = processor.newXsltCompiler();
+ XsltExecutable exec = compiler.compile(stylesheet);
+ XsltTransformer transformer = exec.load();
+
+ //transformer.getUnderlyingController().setBaseOutputURI("http://example.com/");
+
+ // No resolver, there isn't one here.
+ DocumentBuilder builder = processor.newDocumentBuilder();
+ SAXSource document = new SAXSource(new InputSource(new StringReader(textXML)));
+ XdmNode context = builder.build(document);
+ transformer.setInitialContextNode(context);
+ XdmDestination result = new XdmDestination();
+ transformer.setDestination(result);
+ transformer.transform();
+
+ XdmNode xformed = result.getXdmNode();
+ System.err.println("Document base: " + xformed.getBaseURI());
+
+ XdmSequenceIterator nodes = xformed.axisIterator(Axis.CHILD);
+ XdmNode docNode = (XdmNode) nodes.next();
+
+ nodes = docNode.axisIterator(Axis.CHILD);
+ XdmNode paraNode = (XdmNode) nodes.next();
+
+ System.err.println("doc base: " + docNode.getBaseURI());
+ System.err.println("para base: " + paraNode.getBaseURI());
+
+ }
+
+}
@@ -0,0 +1,96 @@
+package com.xmlcalabash.drivers;
+
+import net.sf.saxon.s9api.SaxonApiException;
+import net.sf.saxon.s9api.XdmDestination;
+import net.sf.saxon.s9api.XdmNode;
+import net.sf.saxon.s9api.Processor;
+import net.sf.saxon.s9api.DocumentBuilder;
+import net.sf.saxon.s9api.Axis;
+import net.sf.saxon.s9api.XdmSequenceIterator;
+import net.sf.saxon.s9api.SchemaManager;
+import net.sf.saxon.s9api.SchemaValidator;
+import net.sf.saxon.s9api.XdmNodeKind;
+import net.sf.saxon.Controller;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.event.Receiver;
+import net.sf.saxon.event.PipelineConfiguration;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.xml.sax.InputSource;
+
+import javax.xml.transform.sax.SAXSource;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ndw
+ * Date: Nov 27, 2008
+ * Time: 11:45:52 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ValidBaseURITest {
+ public static void main(String[] args) throws SaxonApiException, IOException, URISyntaxException {
+ ValidBaseURITest test = new ValidBaseURITest();
+ test.run();
+ }
+
+ public void run() throws SaxonApiException {
+ Processor processor = new Processor(true);
+ SchemaManager manager = processor.getSchemaManager();
+
+ // No resolver here, there isn't one.
+ DocumentBuilder builder = processor.newDocumentBuilder();
+ SAXSource source = new SAXSource(new InputSource("http://tests.xproc.org/tests/doc/compoundEntity.xml"));
+ XdmNode document = builder.build(source);
+
+ source = new SAXSource(new InputSource("http://tests.xproc.org/tests/doc/document.xsd"));
+ XdmNode schema = builder.build(source);
+ manager.load(schema.asSource());
+
+ XdmDestination destination = new XdmDestination();
+ Controller controller = new Controller(processor.getUnderlyingConfiguration());
+ Receiver receiver = destination.getReceiver(controller.getConfiguration());
+ PipelineConfiguration pipe = controller.makePipelineConfiguration();
+ pipe.setRecoverFromValidationErrors(false);
+ receiver.setPipelineConfiguration(pipe);
+
+ SchemaValidator validator = manager.newSchemaValidator();
+ validator.setDestination(destination);
+
+ dumpTree(document, "Input");
+
+ validator.validate(document.asSource());
+
+ XdmNode valid = destination.getXdmNode();
+
+ dumpTree(valid, "Output");
+ }
+
+ public void dumpTree(XdmNode tree, String message) {
+ NodeInfo treeNode = tree.getUnderlyingNode();
+ System.err.println(message);
+
+ if (treeNode.getSystemId().equals(tree.getBaseURI().toASCIIString())) {
+ System.err.println("Dumping tree: " + treeNode.getSystemId());
+ } else {
+ System.err.println("Dumping tree:: " + treeNode.getSystemId() + ", " + tree.getBaseURI());
+ }
+ XdmSequenceIterator iter = tree.axisIterator(Axis.CHILD);
+ while (iter.hasNext()) {
+ XdmNode child = (XdmNode) iter.next();
+ dumpTreeNode(child, " ");
+ }
+ }
+
+ private void dumpTreeNode(XdmNode node, String indent) {
+ if (node.getNodeKind() == XdmNodeKind.ELEMENT) {
+ System.err.println(indent + node.getNodeName() + ": " + node.getBaseURI());
+ XdmSequenceIterator iter = node.axisIterator(Axis.CHILD);
+ while (iter.hasNext()) {
+ XdmNode child = (XdmNode) iter.next();
+ dumpTreeNode(child, indent + " ");
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7b30f0a

Please sign in to comment.