Return-Path: Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 6078 invoked by uid 500); 1 Aug 2003 01:04:34 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 6065 invoked by uid 500); 1 Aug 2003 01:04:34 -0000 Received: (qmail 6062 invoked from network); 1 Aug 2003 01:04:34 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 1 Aug 2003 01:04:34 -0000 Received: (qmail 6121 invoked by uid 1342); 1 Aug 2003 01:04:50 -0000 Date: 1 Aug 2003 01:04:50 -0000 Message-ID: <20030801010450.6120.qmail@minotaur.apache.org> From: vgritsenko@apache.org To: avalon-excalibur-cvs@apache.org Subject: cvs commit: avalon-excalibur/xmlutil/src/test/org/apache/excalibur/xml/xpath/test XPathTestCase.java XPathTestCase.xtest X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N vgritsenko 2003/07/31 18:04:50 Modified: xmlutil/src/test/org/apache/excalibur/xml/xpath/test XPathTestCase.java XPathTestCase.xtest Log: * Add more xpath tests * Package access to test documents * zap tabs Revision Changes Path 1.2 +52 -10 avalon-excalibur/xmlutil/src/test/org/apache/excalibur/xml/xpath/test/XPathTestCase.java Index: XPathTestCase.java =================================================================== RCS file: /home/cvs/avalon-excalibur/xmlutil/src/test/org/apache/excalibur/xml/xpath/test/XPathTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XPathTestCase.java 20 May 2003 10:43:00 -0000 1.1 +++ XPathTestCase.java 1 Aug 2003 01:04:50 -0000 1.2 @@ -61,21 +61,23 @@ import org.apache.excalibur.xml.xpath.PrefixResolver; import org.xml.sax.InputSource; import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import java.io.StringReader; public class XPathTestCase extends ExcaliburTestCase { /** A small test document. */ - private static final String CONTENT1 = + static final String CONTENT1 = "" + "" + "" + "" + ""; - /** Second testdocument, has a different namespace than {@link #CONTENT1}. */ - private static final String CONTENT2 = + /** Second test document, has a different namespace than {@link #CONTENT1}. */ + static final String CONTENT2 = "" + "" + "" + @@ -96,14 +98,34 @@ Document document1 = parser.parseDocument(new InputSource(new StringReader(CONTENT1))); Document document2 = parser.parseDocument(new InputSource(new StringReader(CONTENT2))); - // test with a namespace prefix configured in the component configuration - String testExpr = "count(/test:root/*)"; - Number number = processor.evaluateAsNumber(document1, testExpr); + // 1. Test single node expression + String expr = "/test:root/test:element1"; + Node node = processor.selectSingleNode(document1, expr); + assertNotNull("Must select node, but got null", node); + assertEquals("Must select node", Node.ELEMENT_NODE, node.getNodeType()); + assertEquals("Must select node", "element1", node.getLocalName()); + + // 2. Test single node expression with no expected result + expr = "/test:root/test:element3"; + node = processor.selectSingleNode(document1, expr); + assertNull("Must be null", node); + + // 3. Test multiple node expression + expr = "/test:root/test:*"; + NodeList list = processor.selectNodeList(document1, expr); + assertNotNull("Must select two nodes, but got null", list); + assertEquals("Must select two nodes", 2, list.getLength()); + assertEquals("Must select node", "element1", list.item(0).getLocalName()); + assertEquals("Must select node", "element2", list.item(1).getLocalName()); + + // 4. Test with a namespace prefix configured in the component configuration + expr = "count(/test:root/*)"; + Number number = processor.evaluateAsNumber(document1, expr); assertEquals(2, number.intValue()); - // test with a custom prefix resolver using a different document in a different namespace, + // 5. Test with a custom prefix resolver using a different document in a different namespace, // to be sure the custom prefix resolver is used - number = processor.evaluateAsNumber(document2, testExpr, new PrefixResolver() { + number = processor.evaluateAsNumber(document2, expr, new PrefixResolver() { public String prefixToNamespace(String prefix) { if (prefix.equals("test")) @@ -113,11 +135,31 @@ }); assertEquals(2, number.intValue()); + // 6. Test boolean + expr = "count(/test:root/*) = 2"; + boolean bool = processor.evaluateAsBoolean(document1, expr); + assertEquals(true, bool); + + // 7. Test expression in the root element context + expr = "/test:root/test:element1"; + node = processor.selectSingleNode(document1.getDocumentElement(), expr); + assertNotNull("Must select node, but got null", node); + assertEquals("Must select node", Node.ELEMENT_NODE, node.getNodeType()); + assertEquals("Must select node", "element1", node.getLocalName()); + + // 8. Test expression in the child node context + node = processor.selectSingleNode(document1.getDocumentElement().getFirstChild(), expr); + assertNotNull("Must select node, but got null", node); + assertEquals("Must select node", Node.ELEMENT_NODE, node.getNodeType()); + assertEquals("Must select node", "element1", node.getLocalName()); + } finally { - if (parser != null) + if (parser != null) { manager.release((Component)parser); - if (processor != null) + } + if (processor != null) { manager.release((Component)processor); + } } } } 1.2 +9 -8 avalon-excalibur/xmlutil/src/test/org/apache/excalibur/xml/xpath/test/XPathTestCase.xtest Index: XPathTestCase.xtest =================================================================== RCS file: /home/cvs/avalon-excalibur/xmlutil/src/test/org/apache/excalibur/xml/xpath/test/XPathTestCase.xtest,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XPathTestCase.xtest 20 May 2003 10:43:00 -0000 1.1 +++ XPathTestCase.xtest 1 Aug 2003 01:04:50 -0000 1.2 @@ -1,15 +1,16 @@ + - XPathProcessor test case - - - - - + XPathProcessor test case + + + + + - - \ No newline at end of file + + --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org