rwaldhoff 01/04/06 10:37:40
Added: xmlunit build.properties.sample build.xml
xmlunit/src/org/apache/commons/xmlunit TestAll.java
TestXMLAssert.java XMLAssert.java
Log:
Adding build scripts, beginning JUnit support
Revision Changes Path
1.1 jakarta-commons-sandbox/xmlunit/build.properties.sample
Index: build.properties.sample
===================================================================
# junit.jar - JUnit 3.5 Classpath
junit.jar=/java/junit/junit.jar
# jaxp.jar - JAXP Classpath
jaxp.jar=/cvs/bcom/bcom/stable/ext/lib/jaxp.jar
# w3cdom2.jar - W3C DOM Level 2 Classpath
w3cdom2.jar=/cvs/bcom/bcom/stable/ext/lib/w3cdom2.jar
# xalan.jar - Xalan 2 Classpath
xalan.jar=/java/xalan-j_2_0_1/bin/xalan.jar
# xerces.jar - Xerces Classpath
xerces.jar==/cvs/bcom/bcom/stable/ext/lib/xerces.jar
1.1 jakarta-commons-sandbox/xmlunit/build.xml
Index: build.xml
===================================================================
<!-- $Id: build.xml,v 1.1 2001/04/06 17:37:39 rwaldhoff Exp $ -->
<project name="jakarta-commons-xmlunit" default="test" basedir=".">
<!-- patternset describing files to be copied from the doc directory -->
<patternset id="patternset-doc"/>
<!-- patternset describing test classes -->
<patternset id="patternset-test-classes">
<include name="**/Test*.class"/>
</patternset>
<!-- patternset describing non test classes -->
<patternset id="patternset-non-test-classes">
<include name="**/*.class"/>
<exclude name="**/Test*.class"/>
</patternset>
<!-- patternset describing non test source files (*.java, *html, etc.) -->
<patternset id="patternset-javadocable-sources">
<include name="**/*"/>
<exclude name="**/Test*.java"/>
</patternset>
<!-- ######################################################### -->
<target name="init">
<tstamp/>
<!-- read properties from the ${user.home}/propfile, if any -->
<property name="user-propfile" value="${user.home}/build.properties"/>
<property file="${user-propfile}"/>
<property name="user-classpath" value=""/>
<!-- read properties from the build.properties, if any -->
<property file="${basedir}/build.properties"/>
<!-- command line classpath, if any -->
<property name="cp" value=""/>
<!-- now combine the classpaths -->
<property name="classpath"
value="${cp}:${user-classpath}:${junit.jar}:${w3cdom.jar}:${xalan.jar}:${jaxp.jar}"/>
<property name="name" value="commons-xmlunit"/>
<property name="Name" value="Commons-XMLUnit"/>
<property name="Name-Long" value="Jakarta Commons XMLUnit"/>
<property name="test.entry" value="org.apache.commons.xmlunit.TestAll"/>
<property name="test.failonerror" value="true" />
<property name="test.runner" value="junit.textui.TestRunner" />
<property name="workdir"
value="${java.io.tmpdir}/buildtemp_${DSTAMP}${TSTAMP}"/>
<property name="source" value="${basedir}"/>
<property name="source.src" value="${basedir}/src"/>
<property name="source.doc" value="${basedir}/doc"/>
<property name="dest" value="${basedir}/build"/>
<property name="dest.classes" value="${dest}/classes"/>
<property name="dest.doc" value="${dest}/doc"/>
<property name="dest.doc.api" value="${dest.doc}/api"/>
<property name="dest.jardir" value="${dest}"/>
<property name="dest.jardir.jar" value="${dest.jardir}/${name}.jar"/>
<available property="available-doc" file="${source.doc}"/> <!-- does this
module have docs? -->
<available property="available-src" file="${source.src}"/> <!-- does this
module have src? -->
</target>
<!-- ######################################################### -->
<target name="copy-javadoc-source" depends="init" if="available-src">
<mkdir dir="${javadoc-source-dir}"/>
<copy todir="${javadoc-source-dir}" filtering="no">
<fileset dir="${source.src}">
<patternset refid="patternset-javadocable-sources"/>
</fileset>
</copy>
</target>
<target name="copy-doc" depends="init" if="available-doc">
<mkdir dir="${doc-source-dir}/${name}"/>
<copy todir="${doc-source-dir}/${name}" filtering="no">
<fileset dir="${source.doc}">
<patternset refid="patternset-doc"/>
</fileset>
</copy>
</target>
<!-- ######################################################### -->
<target name="clean" depends="init,clean-doc,clean-build,clean-dist"
description="removes generated files">
<delete dir="${dest}"/>
</target>
<target name="clean-doc" depends="init,clean-javadoc">
<delete dir="${dest.doc}"/>
</target>
<target name="clean-javadoc" depends="init">
<delete dir="${dest.doc.api}"/>
</target>
<target name="clean-build" depends="init">
<delete dir="${dest.classes}"/>
</target>
<target name="clean-dist" depends="init">
<delete file="${dest.jardir.jar}"/>
</target>
<!-- ######################################################### -->
<target name="doc" depends="init,doc-copy,doc-javadoc" description="generates
documentation">
</target>
<target name="doc-copy" depends="init" if="available-doc">
<mkdir dir="${dest.doc}"/>
<copy todir="${dest.doc}">
<fileset dir="${source.doc}">
<patternset refid="patternset-doc"/>
</fileset>
</copy>
</target>
<target name="doc-javadoc" depends="init" if="available-src">
<!-- copy all the non-test sources out to the work directory and javadoc that
-->
<mkdir dir="${workdir}"/>
<copy todir="${workdir}">
<fileset dir="${source.src}">
<patternset refid="patternset-javadocable-sources"/>
</fileset>
</copy>
<mkdir dir="${dest.doc.api}"/>
<javadoc packagenames="org.*"
sourcepath="${workdir}"
classpath="${classpath}"
destdir="${dest.doc.api}"
windowtitle="${Name-Long}"
doctitle="${Name-Long}"
bottom="<small>Copyright &copy; 2001 Apache Software
Foundation. Documenation generated ${TODAY}</small>."
public="true"
version="true"
author="false"
splitindex="false"
nodeprecated="true"
nodeprecatedlist="true"
notree="true"
noindex="false"
nohelp="true"
nonavbar="false"
serialwarn="false">
</javadoc>
<delete dir="${workdir}"/>
</target>
<!-- ######################################################### -->
<target name="build" depends="init,build-javac" description="compiles source"/>
<target name="build-javac" depends="init" if="available-src">
<mkdir dir="${dest.classes}"/>
<javac destdir="${dest.classes}"
srcdir="${source.src}"
classpath="${classpath}"
debug="false"
deprecation="true"
optimize="true"/>
</target>
<!-- ######################################################### -->
<target name="test" depends="build" if="test.entry" description="runs (junit)
unit tests">
<!--
<junit printsummary="yes" fork="on" haltonfailure="yes">
<formatter type="plain" usefile="false"/>
<test name="${test.entry}"/>
<classpath>
<pathelement location="${dest.classes}" />
<pathelement path="${classpath}" />
<pathelement path="${java.class.path}" />
</classpath>
</junit>
-->
<java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
<arg value="${test.entry}"/>
<classpath>
<pathelement location="${dest.classes}" />
<pathelement path="${classpath}" />
<pathelement path="${java.class.path}" />
</classpath>
</java>
</target>
<!-- ######################################################### -->
<target name="dist" depends="dist-jar" description="builds production jar"/>
<target name="dist-jar" depends="build">
<mkdir dir="${dest.jardir}"/>
<mkdir dir="${workdir}"/>
<copy todir="${workdir}">
<fileset dir="${dest.classes}">
<patternset refid="patternset-non-test-classes"/>
</fileset>
</copy>
<jar jarfile="${dest.jardir.jar}">
<fileset dir="${workdir}"/>
</jar>
<delete dir="${workdir}"/>
</target>
<!-- ######################################################### -->
</project>
1.1
jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/TestAll.java
Index: TestAll.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/TestAll.java,v
1.1 2001/04/06 17:37:40 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2001/04/06 17:37:40 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.xmlunit;
import junit.framework.*;
/**
* @author Rodney Waldhoff
* @version $Id: TestAll.java,v 1.1 2001/04/06 17:37:40 rwaldhoff Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestXMLAssert.suite());
return suite;
}
public static void main(String args[]) {
String[] testCaseName = { TestAll.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
}
1.1
jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/TestXMLAssert.java
Index: TestXMLAssert.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/TestXMLAssert.java,v
1.1 2001/04/06 17:37:40 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2001/04/06 17:37:40 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.xmlunit;
import junit.framework.*;
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
/**
* @author Rodney Waldhoff
* @version $Id: TestXMLAssert.java,v 1.1 2001/04/06 17:37:40 rwaldhoff Exp $
*/
public class TestXMLAssert extends TestCase {
public TestXMLAssert(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestXMLAssert.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestXMLAssert.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public void testXmlAssertExists() {
DocumentImpl doc = new DocumentImpl();
Element root = doc.createElement("root");
root.setAttribute("attrname","attrvalue");
root.appendChild(new ElementImpl(doc,"a"));
root.appendChild(new ElementImpl(doc,"b"));
ElementImpl a2 = new ElementImpl(doc,"a");
a2.appendChild(new TextImpl(doc,"This is the second child of type a."));
root.appendChild(a2);
root.appendChild(new ElementImpl(doc,"c"));
XMLAssert.xmlAssertExists(root,".");
XMLAssert.xmlAssertExists(root,"self::node()[@attrname]");
XMLAssert.xmlAssertExists(root,"self::node()[@attrname='attrvalue']");
XMLAssert.xmlAssertExists(root,"self::node()/@attrname");
try {
XMLAssert.xmlAssertExists(root,"self::node()[@notanattribute]");
fail("Shouldn't get here");
} catch(AssertionFailedError e) {
// expected
}
XMLAssert.xmlAssertExists(root,"./a");
XMLAssert.xmlAssertExists(root,"./b");
XMLAssert.xmlAssertExists(root,"./c");
XMLAssert.xmlAssertExists(root,"./a[position()=2]");
XMLAssert.xmlAssertExists(root,"a");
XMLAssert.xmlAssertExists(root,"a[position()=2]");
XMLAssert.xmlAssertExists(root,"a[text()]");
XMLAssert.xmlAssertExists(root,"a[text()='This is the second child of type
a.']");
try {
XMLAssert.xmlAssertExists(root,"a[text()='This is the second child of
type a.' and position()=1]");
fail("Shouldn't get here");
} catch(AssertionFailedError e) {
// expected
}
}
}
1.1
jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/XMLAssert.java
Index: XMLAssert.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/XMLAssert.java,v
1.1 2001/04/06 17:37:40 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2001/04/06 17:37:40 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.xmlunit;
import junit.framework.*;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import javax.xml.transform.TransformerException;
/**
* A set of XML-related assert methods.
* @see junit.framework.Assert
* @author Rod Waldhoff
*/
public class XMLAssert extends Assert {
public static void xmlAssertValid(Document doc) throws AssertionFailedError {
xmlAssertValid(null,doc);
}
public static void xmlAssertValid(String message, Document doc) throws
AssertionFailedError {
//
}
public static void xmlAssertExists(Node root, String xpathexpr) throws
AssertionFailedError {
xmlAssertExists(null,root,xpathexpr);
}
public static void xmlAssertExists(String message, Node root, String xpathexpr)
throws AssertionFailedError {
try {
if(null == XPathAPI.selectSingleNode(root,xpathexpr)) {
fail((null == message ? "" : message + " ") + "No node matching <" +
xpathexpr + "> found under <" + root + ">");
}
} catch(TransformerException ex) {
fail((null == message ? "" : message + " ") + "TransformerException for
expression <" + xpathexpr + "> under <" + root + ">: " + ex.toString());
}
}
}