kevinross 2003/06/27 06:25:08
Modified: java/tests/src/org/apache/xindice UnitTests.java Added: java/tests/src/org/apache/xindice/core/query XPathQueryResolverTest.java Log: Added xpath query resolver test Revision Changes Path 1.13 +4 -2 xml-xindice/java/tests/src/org/apache/xindice/UnitTests.java Index: UnitTests.java =================================================================== RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/UnitTests.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- UnitTests.java 13 Jun 2003 14:12:03 -0000 1.12 +++ UnitTests.java 27 Jun 2003 13:25:06 -0000 1.13 @@ -78,6 +78,7 @@ import org.apache.xindice.core.filer.MemFiler; import org.apache.xindice.core.meta.inline.InlineMetaTests; import org.apache.xindice.core.meta.MetaTest; +import org.apache.xindice.core.query.XPathQueryResolverTest; import org.apache.xindice.tools.XMLToolsTest; import org.apache.xindice.util.ConfigurationTest; @@ -94,6 +95,7 @@ suite.addTest(new TestSuite(KeyTest.class)); suite.addTest(new TestSuite(ValueTest.class)); + suite.addTest(new TestSuite(XPathQueryResolverTest.class)); suite.addTest(InlineMetaTests.suite()); suite.addTest(new FilerTestSetup(new TestSuite(FilerTestCase.class), new BTreeFiler())); 1.1 xml-xindice/java/tests/src/org/apache/xindice/core/query/XPathQueryResolverTest.java Index: XPathQueryResolverTest.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999 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 acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xindice" 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 name, without prior written * permission of the Apache Software Foundation. * * 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 and was * originally based on software copyright (c) 1999-2001, The dbXML * Group, L.L.C., http://www.dbxmlgroup.com. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * */ package org.apache.xindice.core.query; import junit.framework.TestCase; import org.apache.xindice.core.Collection; import org.apache.xindice.core.DBException; import org.apache.xindice.core.Database; import org.apache.xindice.core.data.NodeSet; import org.apache.xindice.util.Configuration; import org.apache.xindice.xml.dom.DOMParser; import org.w3c.dom.Document; import org.w3c.dom.Node; /** This TestCase should test the correct Work of the XPathQueryResolver. * During setUp it generates a database and adds one Collection. * The two Tests Simple and Complex query will be raun against this Collection. * The complex query string is taken from the Bug 14878 in Bugzilla * * @author Alexander Sterff <[EMAIL PROTECTED]> * * */ public class XPathQueryResolverTest extends TestCase { protected Database db; protected Configuration conf; Collection col; public void setUp() { db = new Database(); Document doc = null; String xml = "<root-collection dbroot=\"db/\" name=\"db\">" + "<queryengine>" + "<resolver autoindex=\"false\" class=\"org.apache.xindice.core.query.XPathQueryResolver\" />" + "<resolver class=\"org.apache.xindice.core.xupdate.XUpdateQueryResolver\" />" + "</queryengine>" + "</root-collection>"; try { doc = DOMParser.toDocument(xml); } catch (Exception e) { fail("Can't parse xml document! " + e.getMessage()); } conf = new Configuration(doc); db.setConfig(conf); //File root = new File("C:\\"); //db.getFiler().setLocation(root, "test"); xml = "<collection compressed=\"true\" name=\"testcol\">" + "<filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" + "<indexes />" + "</collection>"; try { doc = DOMParser.toDocument(xml); } catch (Exception e) { fail("Can't parse xml document! " + e.getMessage()); } conf = new Configuration(doc); try { col = db.createCollection("testcol", conf); Document sampleXML = null; String sampleXMLString = "<terrainmap>" + "<coordinates>" + "<top-left>" + "<latlong>" + "<latitude>80</latitude>" + "<longitude>-100</longitude>" + "</latlong>" + "</top-left>" + "<bottom-right>" + "<latlong>" + "<latitude>-200</latitude>" + "<longitude>90</longitude>" + "</latlong>" + "</bottom-right>" + "</coordinates>" + "</terrainmap>"; sampleXML = DOMParser.toDocument(sampleXMLString); col.insertDocument(sampleXML); } catch (DBException dbEx) { fail("Can't create Collection! " + dbEx.getMessage()); } catch (Exception e) { fail("Can't parse xml document! " + e.getMessage()); } } public void testSimpleXPathQuery() { try { Node node = null; XPathQueryResolver queryResolv = new XPathQueryResolver(); NodeSet nodeSet = queryResolv.query(col, "/terrainmap", null, null); if (nodeSet.hasMoreNodes()) { node = nodeSet.getNextNode(); } assertNotNull("Simple query didn't return a node", node); db.dropCollection(col); } catch (DBException dbEx) { fail("Can't create Collection! " + dbEx.getMessage()); } } public void testComplexXPathQuery() { try { Node node = null; XPathQueryResolver queryResolv = new XPathQueryResolver(); NodeSet nodeSet = queryResolv.query( col, "/terrainmap[coordinates/top-left/latlong/latitude[(number(text()) + 180) >= 0] and coordinates/top-left/latlong/longitude[(number(text()) + 90) <= 0] and coordinates/bottom-right/latlong/latitude[(number(text()) + 180) <= 0] and coordinates/bottom-right/latlong/longitude[(number(text()) + 90) >= 0]]", null, null); if (nodeSet.hasMoreNodes()) { node = nodeSet.getNextNode(); } assertNotNull("Complex query didn't return a node", node); } catch (DBException dbEx) { fail("Can't create Collection! " + dbEx.getMessage()); } } public void tearDown() { try { db.dropCollection(col); } catch (DBException dbEx) { fail("Can't delete Collection! " + dbEx.getMessage()); } } }