vladimir    2003/06/27 21:26:14

  Modified:    java/tests/src/org/apache/xindice/core/query
                        XPathQueryResolverTest.java
  Log:
  general good practice to now catch the exception and fail the test (the 
entire stacktrace is lost)
  
  Revision  Changes    Path
  1.2       +80 -109   
xml-xindice/java/tests/src/org/apache/xindice/core/query/XPathQueryResolverTest.java
  
  Index: XPathQueryResolverTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/core/query/XPathQueryResolverTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XPathQueryResolverTest.java       27 Jun 2003 13:25:08 -0000      1.1
  +++ XPathQueryResolverTest.java       28 Jun 2003 04:26:13 -0000      1.2
  @@ -61,7 +61,6 @@
   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;
  @@ -75,123 +74,95 @@
    *   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());
  +    public void setUp() throws Exception {
  +        /* this will create a new database for each test method.  Is this the
  +         * desired behaviour? (vladimir) */
  +        
  +        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>";
  +
  +        doc = DOMParser.toDocument(xml);
  +
  +        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>";
  +
  +        doc = DOMParser.toDocument(xml);
  +
  +        conf = new Configuration(doc);
  +        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);
  +    }
  +
  +    public void testSimpleXPathQuery() throws Exception {
  +        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);
  +    }
  +
  +     public void testComplexXPathQuery() throws Exception {
  +             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();
                }
  -             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());
  -             }
  -
  +             assertNotNull("Complex query didn't return a node", node);
        }
   
  -     public void testSimpleXPathQuery() {
  +    public void tearDown() throws Exception {
  +        db.dropCollection(col);
  +    }
   
  -             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());
  -             }
  -     }
   }
  
  
  

Reply via email to