rwaldhoff 01/04/06 11:30:46
Added: xmlunit/src/org/apache/commons/xmlunit XMLTestCase.java
TestXMLTestCase.java
Removed: xmlunit/src/org/apache/commons/xmlunit XMLAssert.java
TestXMLAssert.java
Log:
Moved XMLAssert to XMLTestCase.
Revision Changes Path
1.1
jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/XMLTestCase.java
Index: XMLTestCase.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/XMLTestCase.java,v
1.1 2001/04/06 18:30:45 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2001/04/06 18:30:45 $
*
* ====================================================================
*
* 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;
import org.apache.commons.xmlunit.xpath.AbstractXPathAPI;
import org.apache.commons.xmlunit.xpath.XalanXPathAPI;
/**
* A set of XML-related assert methods.
* @see junit.framework.Assert
* @author Rod Waldhoff
*/
public class XMLTestCase extends TestCase {
public XMLTestCase(String name) {
super(name);
_xpath = new XalanXPathAPI();
}
public XMLTestCase(String name, AbstractXPathAPI xpath) {
super(name);
_xpath = xpath;
}
public void xmlAssertValid(Document doc) throws AssertionFailedError {
xmlAssertValid(null,doc);
}
public void xmlAssertValid(String message, Document doc) throws
AssertionFailedError {
//
}
public void xmlAssertExists(Node root, String xpathexpr) throws
AssertionFailedError {
xmlAssertExists(null,root,xpathexpr);
}
public void xmlAssertExists(String message, Node root, String xpathexpr) throws
AssertionFailedError {
try {
if(null == _xpath.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());
}
}
private AbstractXPathAPI _xpath = null;
}
1.1
jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/TestXMLTestCase.java
Index: TestXMLTestCase.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/xmlunit/src/org/apache/commons/xmlunit/TestXMLTestCase.java,v
1.1 2001/04/06 18:30:46 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2001/04/06 18:30:46 $
*
* ====================================================================
*
* 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: TestXMLTestCase.java,v 1.1 2001/04/06 18:30:46 rwaldhoff Exp $
*/
public class TestXMLTestCase extends TestCase {
public TestXMLTestCase(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestXMLTestCase.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestXMLTestCase.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
private XMLTestCase _case = null;
public void setUp() {
_case = new XMLTestCase("XMLTestCase");
}
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"));
_case.xmlAssertExists(root,".");
_case.xmlAssertExists(root,"self::node()[@attrname]");
_case.xmlAssertExists(root,"self::node()[@attrname='attrvalue']");
_case.xmlAssertExists(root,"self::node()/@attrname");
try {
_case.xmlAssertExists(root,"self::node()[@notanattribute]");
fail("Shouldn't get here");
} catch(AssertionFailedError e) {
// expected
}
_case.xmlAssertExists(root,"./a");
_case.xmlAssertExists(root,"./b");
_case.xmlAssertExists(root,"./c");
_case.xmlAssertExists(root,"./a[position()=2]");
_case.xmlAssertExists(root,"a");
_case.xmlAssertExists(root,"a[position()=2]");
_case.xmlAssertExists(root,"a[text()]");
_case.xmlAssertExists(root,"a[text()='This is the second child of type
a.']");
try {
_case.xmlAssertExists(root,"a[text()='This is the second child of type
a.' and position()=1]");
fail("Shouldn't get here");
} catch(AssertionFailedError e) {
// expected
}
}
}