vgritsenko    2003/12/21 18:14:08

  Modified:    java/tests/src/org/apache/xindice UnitTests.java
               java/tests/src/org/apache/xindice/client/xmldb
                        DatabaseImplTest.java
               java/tests/src/org/apache/xindice/core/meta/inline
                        InlineHeaderBuilderTest.java
                        ResourceTypeReaderTest.java
               java/tests/src/org/apache/xindice/core/query
                        XPathQueryResolverTest.java
               java/tests/src/org/apache/xindice/xml/sax
                        SAXEventGeneratorTest.java
  Added:       java/tests/src/org/apache/xindice/core DatabaseTest.java
               java/tests/src/org/apache/xindice/core/filer
                        BTreeFilerTest.java FSFilerTest.java
                        FilerTestBase.java HashFilerTest.java
                        MemFilerTest.java
  Removed:     java/tests/src/org/apache/xindice/core/filer
                        FilerTestCase.java FilerTestSetup.java
               java/tests/src/org/apache/xindice/core/meta/inline
                        InlineMetaTests.java
  Log:
  Unit test modifications:
   * (Almost) remove programmatic test suite composition. Let Ant do it. Result 
is
     that it is easier to add new tests, and report looks more readable.
   * Add DatabaseTest
   * Add more tests to the XPathQuery test.
   * Fix (newly discovered) SAXEventGen test.
  
  Revision  Changes    Path
  1.18      +8 -36     
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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- UnitTests.java    18 Dec 2003 14:47:22 -0000      1.17
  +++ UnitTests.java    22 Dec 2003 02:14:07 -0000      1.18
  @@ -59,30 +59,18 @@
   
   package org.apache.xindice;
   
  -import java.io.File;
  -
  -import junit.framework.Test;
  -import junit.framework.TestSuite;
  -import junit.textui.TestRunner;
  -import junitx.extensions.TestSetup;
  -
   import org.apache.xindice.client.xmldb.DatabaseImplTest;
   import org.apache.xindice.client.xmldb.ResourceIteratorImplTest;
  -import org.apache.xindice.core.data.KeyTest;
  -import org.apache.xindice.core.data.ValueTest;
  -import org.apache.xindice.core.filer.BTreeFiler;
  -import org.apache.xindice.core.filer.FSFiler;
   import org.apache.xindice.core.filer.Filer;
  -import org.apache.xindice.core.filer.FilerTestCase;
  -import org.apache.xindice.core.filer.FilerTestSetup;
  -import org.apache.xindice.core.filer.HashFiler;
  -import org.apache.xindice.core.filer.MemFiler;
  -import org.apache.xindice.core.meta.inline.InlineMetaTests;
  +import org.apache.xindice.core.filer.FilerTestBase;
   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;
   
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import junit.textui.TestRunner;
  +
   /**
    * @version CVS $Revision$, $Date$
    * @author Vladimir R. Bossicard <[EMAIL PROTECTED]>
  @@ -97,31 +85,15 @@
       public static Test suite() {
           TestSuite suite = new TestSuite("Xindice unit tests");
   
  -        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()));
  -        suite.addTest(new FilerTestSetup(new TestSuite(FilerTestCase.class), 
new FSFiler()));
  -        // TODO: see what to do with the HashFiler
  -        suite.addTest(new FilerTestSetup(new TestSuite(FilerTestCase.class), 
new HashFiler()));
  -        suite.addTest(new FilerTestSetup(new TestSuite(FilerTestCase.class), 
new MemFiler()));
  -
           // If the Berkeley filer was built in then test it too.
           try {
               Class filerClass = 
Class.forName("org.apache.xindice.core.filer.BerkeleyBTreeFiler");
               Filer filer = (Filer) filerClass.newInstance();
  -            suite.addTest(new FilerTestSetup(new 
TestSuite(FilerTestCase.class), filer));
  +            suite.addTest(new FilerTestBase("BerkeleyFilerTestCase", filer));
           } catch (Exception e) {
               // If the class wasn't built just ignore it.
           }
   
  -        suite.addTest(new TestSuite(DatabaseImplTest.class));
  -        suite.addTest(new TestSuite(ResourceIteratorImplTest.class));
  -        suite.addTest(new TestSuite(XMLToolsTest.class));
  -        suite.addTest(new TestSuite(ConfigurationTest.class));
  -        suite.addTest(new TestSuite(MetaTest.class));
           return suite;
       }
   }
  
  
  
  1.5       +10 -19    
xml-xindice/java/tests/src/org/apache/xindice/client/xmldb/DatabaseImplTest.java
  
  Index: DatabaseImplTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/client/xmldb/DatabaseImplTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DatabaseImplTest.java     7 Aug 2003 20:13:26 -0000       1.4
  +++ DatabaseImplTest.java     22 Dec 2003 02:14:07 -0000      1.5
  @@ -65,23 +65,19 @@
    * @version CVS $Revision$, $Date$
    * @author Vladimir R. Bossicard <[EMAIL PROTECTED]>
    */
  -public class DatabaseImplTest
  -      extends TestCase {
  +public class DatabaseImplTest extends TestCase {
   
      private DatabaseImpl db;
   
  -   public void setUp()
  -         throws Exception {
  +   public void setUp() throws Exception {
         db = new DatabaseImpl();
      }
   
  -   public void testGetName()
  -         throws Exception {
  +   public void testGetName() throws Exception {
         assertEquals("xindice, xindice-embed, xindice-managed", db.getName());
      }
   
  -   public void testAcceptXmlRpcURI()
  -         throws Exception {
  +   public void testAcceptXmlRpcURI() throws Exception {
         assertTrue(db.acceptsURI("xindice://"));
   
         assertTrue(db.acceptsURI("xindice://"));
  @@ -91,8 +87,7 @@
         assertFalse(db.acceptsURI(null));
      }
   
  -   public void testAcceptEmbedURI()
  -         throws Exception {
  +   public void testAcceptEmbedURI() throws Exception {
         assertTrue(db.acceptsURI("xindice-embed://"));
   
         assertFalse(db.acceptsURI("xindice://"));
  @@ -102,8 +97,7 @@
         assertFalse(db.acceptsURI(null));
      }
   
  -   public void testFailAcceptCorbaURI()
  -         throws Exception {
  +   public void testFailAcceptCorbaURI() throws Exception {
         assertFalse(db.acceptsURI("xindice-corba://"));
   
         assertFalse(db.acceptsURI("xindice-corba://"));
  @@ -111,8 +105,7 @@
         assertFalse(db.acceptsURI(null));
      }
   
  -   public void testFailAcceptNullURI()
  -         throws Exception {
  +   public void testFailAcceptNullURI() throws Exception {
         assertFalse(db.acceptsURI(null));
   
         assertFalse(db.acceptsURI("xindice-corba://"));
  @@ -120,13 +113,11 @@
         assertFalse(db.acceptsURI(null));
      }
   
  -   public void testFailAcceptEmptyURI()
  -         throws Exception {
  +   public void testFailAcceptEmptyURI() throws Exception {
         assertFalse(db.acceptsURI(""));
   
         assertFalse(db.acceptsURI("xindice-corba://"));
         assertFalse(db.acceptsURI(""));
         assertFalse(db.acceptsURI(null));
      }
  -
   }
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/DatabaseTest.java
  
  Index: DatabaseTest.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/>.
   *
   * CVS $Id: DatabaseTest.java,v 1.1 2003/12/22 02:14:07 vgritsenko Exp $
   */
  
  package org.apache.xindice.core;
  
  import org.apache.xindice.util.Configuration;
  import org.apache.xindice.xml.dom.DOMParser;
  
  import junit.framework.TestCase;
  
  /**
   * @version CVS $Revision: 1.1 $, $Date: 2003/12/22 02:14:07 $
   * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
   */
  public class DatabaseTest extends TestCase {
  
      final String DATABASE =
          "<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>";
  
      final String COLLECTIONA =
          "<collection compressed=\"true\" name=\"CollectionA\">" +
              "<filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" +
              "<indexes />" +
          "</collection>";
  
      final String COLLECTIONB =
          "<collection compressed=\"true\" name=\"CollectionB\">" +
              "<filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" +
              "<indexes />" +
          "</collection>";
  
      final String COLLECTIONC =
          "<collection compressed=\"true\" name=\"CollectionC\">" +
              "<filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" +
              "<indexes />" +
          "</collection>";
  
  
        private static Database db;
      private Configuration configurationA;
      private Configuration configurationB;
      private Configuration configurationC;
  
      public DatabaseTest(String name) {
          super(name);
      }
  
      public void setUp() throws Exception {
          db = new Database();
          db.setConfig(new Configuration(DOMParser.toDocument(DATABASE)));
          configurationA = new Configuration(DOMParser.toDocument(COLLECTIONA));
          configurationB = new Configuration(DOMParser.toDocument(COLLECTIONB));
          configurationC = new Configuration(DOMParser.toDocument(COLLECTIONC));
      }
  
      public void testCreateCollection() throws Exception {
          Collection collection = db.createCollection("CollectionA", 
configurationA);
          assertNotNull("Collection expected", collection);
          assertEquals("Collection name", "CollectionA", collection.getName());
      }
  
      public void testFailCreateCollection() throws Exception {
          Collection collection = null;
          try {
              collection = db.createCollection("somepath", configurationA);
              fail("Exception expected");
          } catch (DBException e) {
              // Expected
          }
      }
  
      public void testMTGetCollection() throws Exception {
          Collection a = db.createCollection("CollectionA", configurationA);
          Collection b = db.createCollection("CollectionB", configurationB);
          Collection c = db.createCollection("CollectionC", configurationC);
  
          final int THREADS = 20;
          final int ITERATIONS = 50;
  
          final boolean[] result = new boolean[]{ true };
          Thread[] threads = new Thread[THREADS];
          for (int i = 0; i < THREADS; i++) {
              threads[i] = new Thread() {
                  public void run() {
                      for (int ii = 0; ii < ITERATIONS && result[0]; ii++) {
                          Collection c;
                          try {
                              c = db.getCollection("CollectionA");
                              if (!c.getName().equals("CollectionA")) {
                                  System.out.println("Expected CollectionA, got 
" + c.getName());
                                  result[0] = false;
                              }
                              c = db.getCollection("CollectionB");
                              if (!c.getName().equals("CollectionB")) {
                                  System.out.println("Expected CollectionB, got 
" + c.getName());
                                  result[0] = false;
                              }
                              c = db.getCollection("CollectionC");
                              if (!c.getName().equals("CollectionC")) {
                                  System.out.println("Expected CollectionC, got 
" + c.getName());
                                  result[0] = false;
                              }
                          } catch (Exception e) {
                              e.printStackTrace();
                              result[0] = false;
                              fail();
                          }
                      }
                  }
              };
              threads[i].setName("DatabaseTest" + i);
          }
  
          // Start all the threads at once
          for (int i = 0; i < THREADS; i++) {
              threads[i].start();
          }
          Thread.sleep(1000);
          for (int i = 0; i < THREADS; i++) {
              threads[i].join();
          }
  
          db.dropCollection(a);
          db.dropCollection(b);
          db.dropCollection(c);
  
          assertTrue("Test Failed", result[0]);
      }
  
      public void tearDown() throws Exception {
          try {
              db.dropCollection(db.getCollection("CollectionA"));
          } catch (Exception e) {
          }
          try {
              db.dropCollection(db.getCollection("CollectionB"));
          } catch (Exception e) {
          }
          try {
              db.dropCollection(db.getCollection("CollectionC"));
          } catch (Exception e) {
          }
      }
  }
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/filer/BTreeFilerTest.java
  
  Index: BTreeFilerTest.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/>.
   *
   * CVS $Id: BTreeFilerTest.java,v 1.1 2003/12/22 02:14:07 vgritsenko Exp $
   */
  package org.apache.xindice.core.filer;
  
  /**
   * @version CVS $Revision: 1.1 $, $Date: 2003/12/22 02:14:07 $
   * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
   */
  public class BTreeFilerTest extends FilerTestBase {
  
      public BTreeFilerTest(String name) {
          super(name, new BTreeFiler());
      }
  }
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/filer/FSFilerTest.java
  
  Index: FSFilerTest.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/>.
   *
   * CVS $Id: FSFilerTest.java,v 1.1 2003/12/22 02:14:07 vgritsenko Exp $
   */
  package org.apache.xindice.core.filer;
  
  /**
   * @version CVS $Revision: 1.1 $, $Date: 2003/12/22 02:14:07 $
   * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
   */
  public class FSFilerTest extends FilerTestBase {
  
      public FSFilerTest(String name) {
          super(name, new FSFiler());
      }
  
      public void testLargeKey() throws Exception {
          // Kay size is limited by the file system used
          LARGE_KEY_SIZE = 128;
          super.testLargeKey();
      }
  }
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java
  
  Index: FilerTestBase.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/>.
   *
   * CVS $Id: FilerTestBase.java,v 1.1 2003/12/22 02:14:07 vgritsenko Exp $
   */
  package org.apache.xindice.core.filer;
  
  import org.apache.xindice.core.data.Key;
  import org.apache.xindice.core.data.Record;
  import org.apache.xindice.core.data.RecordSet;
  import org.apache.xindice.core.data.Value;
  import org.apache.xindice.util.Configuration;
  import org.apache.xindice.xml.dom.DOMParser;
  
  import junit.framework.TestCase;
  
  import java.util.List;
  import java.util.Vector;
  import java.io.File;
  
  /**
   * Base class for filer test cases
   *
   * @version CVS $Revision: 1.1 $, $Date: 2003/12/22 02:14:07 $
   * @author <a href="mailto:[EMAIL PROTECTED]">Kimbro Staken</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Vladimir R. Bossicard</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
   */
  public class FilerTestBase extends TestCase {
  
      static public final String TEST_COLLECTION_NAME = "tests";
      static public final Key TEST_KEY = new Key("test.xml");
      static public final Value TEST_VALUE = new 
Value("<test><test></test><test>Just a test</test></test>");
      static public final Value TEST_VALUE_2 = new 
Value("<test><test></test><test>Just a test 2</test></test>");
      static public final Value TEST_VALUE_3 = new 
Value("<test><test></test><test>Just a test 3</test></test>");
  
      /**
       * Key size for the testLargeKey. FSFiler will set smaller value for its 
test.
       */
      protected int LARGE_KEY_SIZE = 8192 + 32;
  
  
      private static final File root = new File(TEST_COLLECTION_NAME);
      private Filer filer;
  
      public FilerTestBase(String name, Filer filer) {
          super(name);
          this.filer = filer;
      }
  
      public void setUp() throws Exception {
          root.mkdir();
          filer.setLocation(root, TEST_COLLECTION_NAME);
          filer.setConfig(new Configuration(DOMParser.toDocument("<filer 
location=\"" + TEST_COLLECTION_NAME + "\"/>")));
          if (!filer.exists()) {
              filer.create();
          }
          filer.open();
  
          RecordSet set = filer.getRecordSet();
          while (set.hasMoreRecords()) {
              Key key = set.getNextKey();
              filer.deleteRecord(key);
          }
          assertEquals(0, filer.getRecordCount());
      }
  
      protected void tearDown() throws Exception {
          if (filer != null) {
              filer.close();
          }
  
          String[] files = root.list();
          for (int i = 0; i < files.length; i++) {
              new File(root, files[i]).delete();
          }
          root.delete();
          super.tearDown();
      }
  
      public String getName() {
          return this.filer.getName() + " " + super.getName();
      }
  
      public void testSuccessWriteRecord() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          Record result = filer.readRecord(TEST_KEY);
          assertEquals(TEST_VALUE, result.getValue());
  
          RecordSet set = filer.getRecordSet();
          assertEquals(result.getValue(), set.getNextRecord().getValue());
          assertTrue(set.hasMoreRecords() == false);
  
          filer.deleteRecord(TEST_KEY);
          assertEquals(0, filer.getRecordCount());
      }
  
      public void testFailReadDeletedRecord() throws Exception {
          Record result = filer.readRecord(TEST_KEY);
          assertNull(result);
      }
  
      public void testFailWriteRecordNullKey() throws Exception {
          try {
              filer.writeRecord(null, TEST_VALUE);
              fail("Expecting FilerException");
          } catch (FilerException e) {
              // Ok
          }
      }
  
      public void testFailWriteRecordNullValue() throws Exception {
          try {
              filer.writeRecord(TEST_KEY, null);
              fail("Expecting FilerException");
          } catch (FilerException e) {
              // Ok
          }
      }
  
      public void testFailWriteRecordNullValueKey() throws Exception {
          try {
              filer.writeRecord(null, null);
              fail("Expecting FilerException");
          } catch (FilerException e) {
              // Ok
          }
      }
  
      public void testReadRecord() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // Valid key
          Record result = filer.readRecord(TEST_KEY);
          assertEquals(TEST_VALUE, result.getValue());
      }
  
      public void testFailReadRecordNullKey() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // Null key
          Record result = filer.readRecord(null);
          assertNull(result);
      }
  
      public void testFailReadRecordEmptyKey() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // Empty key
          Record result = filer.readRecord(new Key(""));
          assertNull(result);
      }
  
      public void testFailReadRecordUnknownKey() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // Non-existant key
          Record result = filer.readRecord(new Key("non-existant-key"));
          assertNull(result);
      }
  
      public void testDeleteRecord() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // Valid key
          filer.deleteRecord(TEST_KEY);
          assertEquals(0, filer.getRecordCount());
          Record result = filer.readRecord(TEST_KEY);
          assertNull(result);
      }
  
      public void testDeleteRecordNullKey() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // These should all just fail silently.
          assertTrue(false == filer.deleteRecord(null));
          assertEquals(1, filer.getRecordCount());
      }
  
      public void testDeleteRecordEmptyKey() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // These should all just fail silently.
          assertTrue(false == filer.deleteRecord(new Key("")));
          assertEquals(1, filer.getRecordCount());
      }
  
      public void testDeleteRecordWrongKey() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertEquals(1, filer.getRecordCount());
  
          // These should all just fail silently.
          assertTrue(false == filer.deleteRecord(new Key("non-existant-key")));
          assertEquals(1, filer.getRecordCount());
      }
  
      public void testGetRecordCount() throws Exception {
          assertEquals(0, filer.getRecordCount());
  
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertTrue(filer.writeRecord(new Key("test1"), TEST_VALUE));
          assertTrue(filer.writeRecord(new Key("test2"), TEST_VALUE));
          assertEquals(3, filer.getRecordCount());
  
          assertTrue(filer.writeRecord(new Key("test3"), TEST_VALUE));
          assertEquals(4, filer.getRecordCount());
  
          assertTrue(filer.deleteRecord(new Key("test3")));
          assertEquals(3, filer.getRecordCount());
  
          assertTrue(filer.deleteRecord(TEST_KEY));
          assertTrue(filer.deleteRecord(new Key("test1")));
          assertTrue(filer.deleteRecord(new Key("test2")));
  
          assertEquals(0, filer.getRecordCount());
      }
  
      public void testGetRecordSet() throws Exception {
          assertTrue(filer.writeRecord(TEST_KEY, TEST_VALUE));
          assertTrue(filer.writeRecord(new Key("test2"), TEST_VALUE_2));
          assertTrue(filer.writeRecord(new Key("test3"), TEST_VALUE_3));
  
          RecordSet result = filer.getRecordSet();
          assertNotNull(result);
  
          List results = new Vector();
          while (result.hasMoreRecords()) {
              results.add(result.getNextRecord().getValue());
          }
          assertEquals(3, results.size());
          assertTrue(results.contains(TEST_VALUE));
          assertTrue(results.contains(TEST_VALUE_2));
          assertTrue(results.contains(TEST_VALUE_3));
  
          assertTrue(filer.deleteRecord(TEST_KEY));
          assertTrue(filer.deleteRecord(new Key("test2")));
          assertTrue(filer.deleteRecord(new Key("test3")));
  
          result = filer.getRecordSet();
          assertTrue(!result.hasMoreRecords());
      }
  
      public void testInsertManyDocuments() throws Exception {
          int iterations = 1000;
          for (int i = 0; i < iterations; i++) {
              assertTrue(filer.writeRecord(new Key("key" + i), TEST_VALUE));
          }
  
          assertTrue(filer.getRecordCount() == iterations);
  
          for (int i = 0; i < iterations; i++) {
              assertTrue(filer.deleteRecord(new Key("key" + i)));
          }
  
          assertTrue(filer.getRecordCount() == 0);
      }
  
      public void testConcurrentInsert() throws Exception {
          assertTrue(filer.getRecordCount() == 0);
  
          final int THREADS = 30;
          final int ITERATIONS = 65;
  
          Thread[] threads = new Thread[THREADS];
          for (int i = 0; i < THREADS; i++) {
              final int threadID = i;
              threads[i] = new Thread() {
                  public void run() {
                      for (int ii = 0; ii < ITERATIONS; ii++) {
                          Key key = new Key("T" + threadID + "I" + ii);
                          Value value = new Value("<test thread=\"" + threadID 
+ "\" iteration=\"" + ii + "\"/>");
                          try {
                              filer.writeRecord(key, value);
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                      // System.out.println(getName() + " done.");
                  }
              };
              threads[i].setName("FilerTest" + i);
          }
  
          // Start all the threads at once
          for (int i = 0; i < THREADS; i++) {
              threads[i].start();
          }
          Thread.sleep(1000);
  
          for (int i = 0; i < THREADS; i++) {
              threads[i].join();
          }
  
          filer.flush();
  
          // Check results
          assertEquals(filer.getRecordCount(), THREADS * ITERATIONS);
          for (int i = 0; i < THREADS; i++) {
              for (int ii = 0; ii < ITERATIONS; ii++) {
                  Key key = new Key("T" + i + "I" + ii);
                  Value value = new Value("<test thread=\"" + i + "\" 
iteration=\"" + ii + "\"/>");
                  Record record = filer.readRecord(key);
                  assertNotNull("Record with key '" + key + "' was not found",
                                record);
                  assertEquals("Expected record with key '" + key + "', found 
record with key '" + record.getKey() + "'",
                               key, record.getKey());
                  assertEquals("Expected record with value '" + value + "', 
found record with value '" + record.getValue() + "'",
                               value, record.getValue());
              }
          }
      }
  
      public void testLargeKey() throws Exception {
          assertTrue(filer.getRecordCount() == 0);
  
          StringBuffer sb = new StringBuffer(LARGE_KEY_SIZE);
          sb.append("KEY");
          for (int k = 0; k < LARGE_KEY_SIZE - 3; k++) {
              sb.append('0');
          }
          final Key key = new Key(sb.toString());
          final Value value = new Value("<test/>");
  
          assertTrue(filer.writeRecord(key, value));
  
          assertEquals(filer.getRecordCount(), 1);
          Record record = filer.readRecord(key);
          assertNotNull("Record with key '" + key + "' was not found",
                        record);
          assertEquals("Expected record with key '" + key + "', found record 
with key '" + record.getKey() + "'",
                       key, record.getKey());
          assertEquals("Expected record with value '" + value + "', found 
record with value '" + record.getValue() + "'",
                       value, record.getValue());
      }
  }
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/filer/HashFilerTest.java
  
  Index: HashFilerTest.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/>.
   *
   * CVS $Id: HashFilerTest.java,v 1.1 2003/12/22 02:14:07 vgritsenko Exp $
   */
  package org.apache.xindice.core.filer;
  
  /**
   * @version CVS $Revision: 1.1 $, $Date: 2003/12/22 02:14:07 $
   * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
   */
  public class HashFilerTest extends FilerTestBase {
  
      public HashFilerTest(String name) {
          super(name, new HashFiler());
      }
  
      public void testLargeKey() throws Exception {
          // HashFiler large key can not be large than page size (less page 
header)
          LARGE_KEY_SIZE = 4030;
          super.testLargeKey();
      }
  }
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/filer/MemFilerTest.java
  
  Index: MemFilerTest.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/>.
   *
   * CVS $Id: MemFilerTest.java,v 1.1 2003/12/22 02:14:07 vgritsenko Exp $
   */
  package org.apache.xindice.core.filer;
  
  /**
   * @version CVS $Revision: 1.1 $, $Date: 2003/12/22 02:14:07 $
   * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
   */
  public class MemFilerTest extends FilerTestBase {
  
      public MemFilerTest(String name) {
          super(name, new MemFiler());
      }
  }
  
  
  
  1.3       +4 -5      
xml-xindice/java/tests/src/org/apache/xindice/core/meta/inline/InlineHeaderBuilderTest.java
  
  Index: InlineHeaderBuilderTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/core/meta/inline/InlineHeaderBuilderTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InlineHeaderBuilderTest.java      7 Aug 2003 20:13:26 -0000       1.2
  +++ InlineHeaderBuilderTest.java      22 Dec 2003 02:14:07 -0000      1.3
  @@ -68,8 +68,7 @@
    * @version CVS $Revision$, $Date$
    * @author Gary Shea <[EMAIL PROTECTED]>
    */
  -public class InlineHeaderBuilderTest
  -        extends TestCase {
  +public class InlineHeaderBuilderTest extends TestCase {
   
       public void testInlineHeaderBuilderCreateValue() {
           byte[] metadata = new byte[] {
  @@ -104,4 +103,4 @@
               assertEquals("i=" + i, data[i + 2], valueBytes[i + 5]);
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.3       +4 -6      
xml-xindice/java/tests/src/org/apache/xindice/core/meta/inline/ResourceTypeReaderTest.java
  
  Index: ResourceTypeReaderTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/core/meta/inline/ResourceTypeReaderTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResourceTypeReaderTest.java       7 Aug 2003 20:13:26 -0000       1.2
  +++ ResourceTypeReaderTest.java       22 Dec 2003 02:14:07 -0000      1.3
  @@ -59,7 +59,6 @@
    * CVS $Id$
    */
   
  -
   import org.apache.xindice.core.meta.inline.InlineMetaException;
   import org.apache.xindice.core.meta.inline.InlineMetaMap;
   import org.apache.xindice.core.meta.inline.ResourceTypeReader;
  @@ -70,8 +69,7 @@
    * @version CVS $Revision$, $Date$
    * @author Gary Shea <[EMAIL PROTECTED]>
    */
  -public class ResourceTypeReaderTest
  -        extends TestCase {
  +public class ResourceTypeReaderTest extends TestCase {
   
       public void testResourceTypeReaderRead() throws Exception {
   
  @@ -99,4 +97,4 @@
               // expected exception
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.6       +193 -69   
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XPathQueryResolverTest.java       15 Dec 2003 14:21:48 -0000      1.5
  +++ XPathQueryResolverTest.java       22 Dec 2003 02:14:07 -0000      1.6
  @@ -54,92 +54,214 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * 
  + * CVS $Id$
    */
  -package org.apache.xindice.core.query;
   
  -import junit.framework.TestCase;
  +package org.apache.xindice.core.query;
   
   import org.apache.xindice.core.Collection;
   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
  - * 
  +import junit.framework.TestCase;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Text;
  +
  +/**
  + * 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
  + *
  + * @version CVS $Revision$, $Date$
    * @author Alexander Sterff <[EMAIL PROTECTED]>
    */
   public class XPathQueryResolverTest extends TestCase {
   
  -     protected Database db;
  -     protected Configuration conf;
  -     Collection col;
  +    final String DATABASE =
  +        "<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>";
  +
  +    final String COLLECTION =
  +        "<collection compressed=\"true\" name=\"testcol\">" +
  +            "<filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" +
  +            "<indexes />" +
  +        "</collection>";
  +
  +    final String DOCUMENT =
  +        "<terrainmap>" +
  +            "<coordinates>" +
  +                "some text" +
  +                "<top-left>" +
  +                    "<latlong>" +
  +                        "some more text" +
  +                        "<latitude>80</latitude>" +
  +                        "<longitude>-100</longitude>" +
  +                    "</latlong>" +
  +                "</top-left>" +
  +                "<bottom-right>" +
  +                    "<latlong>" +
  +                        "a" +
  +                        "<latitude>-200</latitude>" +
  +                        "b" +
  +                        "<longitude>90</longitude>" +
  +                        "c" +
  +                    "</latlong>" +
  +                "</bottom-right>" +
  +            "</coordinates>" +
  +        "</terrainmap>";
  +
  +    final String[] ELEMENT_QUERY = {
  +        "/terrainmap",
  +        "/terrainxmap",
  +        "/terrainmap/coordinates",
  +        "/terrainmap/coordinates/top-left",
  +        "/terrainmap/coordinates/*",
  +        "/terrainmap/coordinates/bottom-right/latlong",
  +        "/terrainmap/coordinates/bottom-right/latlong/*",
  +        "/terrainmap/coordinates/bottom-right/latlong/..",
  +    };
  +
  +    final int[] ELEMENT_COUNT = {
  +        1,
  +        0,
  +        1,
  +        1,
  +        2,
  +        1,
  +        2,
  +        1,
  +    };
  +
  +    final String[] ELEMENT_NAMES = {
  +        "terrainmap",
  +        null,
  +        "coordinates",
  +        "top-left",
  +        "bottom-right",
  +        "latlong",
  +        "longitude",
  +        "bottom-right",
  +    };
  +
  +    final String[] NUMBER_QUERY = {
  +        "2 + 2",
  +        "count(/terrainmap)",
  +        "count(/terrainmap/coordinates) + count(//latlong)",
  +        "number(//latitude[1]/text())",
  +        "number(//longitude[ancestor::bottom-right]/text())",
  +    };
  +
  +    final int[] NUMBER_VALUE = {
  +        4,
  +        1,
  +        3,
  +        80,
  +        90,
  +    };
  +
  +    final String[] TEXT_QUERY = {
  +        "/terrainmap/coordinates/text()",
  +        "/terrainmap/coordinates//text()[contains(., 'more')]",
  +        "//text()",
  +        "//latlong/text()",
  +        "//latlong/text()[2]",
  +    };
  +
  +    final int[] TEXT_COUNT = {
  +        1,
  +        1,
  +        9,
  +        4,
  +        1,
  +    };
  +
  +    final String[] TEXT_VALUE = {
  +        "some text",
  +        "some more text",
  +        "c",
  +        "c",
  +        "b",
  +    };
  +
  +
  +    private static int tests;
  +     private static Database db;
  +     private static Collection col;
  +
  +    private XPathQueryResolver resolver;
  +
  +
  +    public XPathQueryResolverTest(String name) {
  +        super(name);
  +        tests++;
  +    }
   
       public void setUp() throws Exception {
  -        // FIXME: This will create a new database for each test method. It's 
overkill; one DB is enough
  -        
  -        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);
  -
  -        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);
  +        if (db == null) {
  +            Database db = new Database();
  +            db.setConfig(new Configuration(DOMParser.toDocument(DATABASE)));
  +            col = db.createCollection("testcol", new 
Configuration(DOMParser.toDocument(COLLECTION)));
  +            col.insertDocument(DOMParser.toDocument(DOCUMENT));
  +
  +            XPathQueryResolverTest.db = db;
  +        }
  +
  +        resolver = new XPathQueryResolver();
  +    }
  +
  +    public void testElementXPathQuery() throws Exception {
  +        for (int i = 0; i < ELEMENT_QUERY.length; i++) {
  +            NodeSet nodeSet = resolver.query(col, ELEMENT_QUERY[i], null, 
null);
  +            int results = 0;
  +            Element element = null;
  +            while(nodeSet.hasMoreNodes()) {
  +                element = (Element)nodeSet.getNextNode();
  +                assertNotNull("NodeSet.getNextNode must be not null", 
element);
  +                results++;
  +            }
  +
  +            assertEquals("Results count", ELEMENT_COUNT[i], results);
  +            if (results > 0) {
  +                assertEquals("Result element name", ELEMENT_NAMES[i], 
element.getNodeName());
  +            }
  +        }
       }
   
  -    public void testSimpleXPathQuery() throws Exception {
  -        Object node = null;
  -        XPathQueryResolver queryResolv = new XPathQueryResolver();
  -        NodeSet nodeSet = queryResolv.query(col, "/terrainmap", null, null);
  -        if (nodeSet.hasMoreNodes()) {
  -            node = nodeSet.getNextNode();
  +    public void testNumberXPathQuery() throws Exception {
  +        for (int i = 0; i < NUMBER_QUERY.length; i++) {
  +            NodeSet nodeSet = resolver.query(col, NUMBER_QUERY[i], null, 
null);
  +            Double element = null;
  +            assertTrue("Expected one result", nodeSet.hasMoreNodes());
  +            element = (Double)nodeSet.getNextNode();
  +            assertNotNull("NodeSet.getNextNode must be not null", element);
  +            assertEquals("Result value", new Double(NUMBER_VALUE[i]), 
element);
  +        }
  +    }
  +
  +    public void testTextXPathQuery() throws Exception {
  +        for (int i = 0; i < TEXT_QUERY.length; i++) {
  +            NodeSet nodeSet = resolver.query(col, TEXT_QUERY[i], null, null);
  +            int results = 0;
  +            Text element = null;
  +            while(nodeSet.hasMoreNodes()) {
  +                element = (Text)nodeSet.getNextNode();
  +                assertNotNull("NodeSet.getNextNode must be not null", 
element);
  +                results++;
  +            }
  +
  +            assertEquals("Results count for " + TEXT_QUERY[i], 
TEXT_COUNT[i], results);
  +            if (results > 0) {
  +                assertEquals("Result value for " + TEXT_QUERY[i], 
TEXT_VALUE[i], element.getNodeValue());
  +            }
           }
  -        assertNotNull("Simple query didn't return a node", node);
       }
   
        public void testComplexXPathQuery() throws Exception {
  @@ -158,6 +280,8 @@
        }
   
       public void tearDown() throws Exception {
  -        db.dropCollection(col);
  +        if (--tests == 0) {
  +            db.dropCollection(col);
  +        }
       }
   }
  
  
  
  1.2       +60 -110   
xml-xindice/java/tests/src/org/apache/xindice/xml/sax/SAXEventGeneratorTest.java
  
  Index: SAXEventGeneratorTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/xml/sax/SAXEventGeneratorTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SAXEventGeneratorTest.java        25 Dec 2002 20:53:30 -0000      1.1
  +++ SAXEventGeneratorTest.java        22 Dec 2003 02:14:08 -0000      1.2
  @@ -26,32 +26,31 @@
   public class SAXEventGeneratorTest extends TestCase {
       
       private static final String XML = 
  -     "<?xml version=\"1.0\"?>"
  +       "<?xml version=\"1.0\"?>"
        + "<n1:n1 "
  -     + "xmlns:n1=\"http://apache.org/xindice/mockns/n1\"; "
  -     + "xmlns:n2=\"http://apache.org/xindice/mockns/n1/n2\"; "
  -     + "xmlns:n3=\"http://apache.org/xindice/mockns/n1/n3\"; "
  -     + "xmlns:n4=\"http://apache.org/xindice/mockns/n1/n4\"; "
  -     + "xmlns:n5=\"http://apache.org/xindice/mockns/n1/n5\"; "
  -     + "xmlns:n6=\"http://apache.org/xindice/mockns/n1/n6\"; "
  -     + "xmlns:n7=\"http://apache.org/xindice/mockns/n7\"; "
  -     + "n7:aaa=\"n1\" "
  -     + "n7:bbb=\"something\">"
  -     + ""
  -     + ""
  -     + "<n2:aaa />"
  -     + "<n2:bbb />"
  -     + "<n2:ccc with=\"an attribute\">Whatever</n2:ccc>"
  -     + "<n2:ddd>Hello World!</n2:ddd>"
  -     + "<n2:eee />"
  -     + "<n1:aaa>0</n1:aaa>"
  -     + "<n1:bbb>More text</n1:bbb>"
  -     + "<n3:aaa />"
  -     + "<n3:bbb />"
  -     + "<n4:aaa />"
  -     + "<n4:bbb />"
  -     + "<n5:aaa>Even more text, with newlines\n and stuff</n5:aaa>"
  -     + "<n6:aaa />"
  +         + "xmlns:n1=\"http://apache.org/xindice/mockns/n1\"; "
  +         + "xmlns:n2=\"http://apache.org/xindice/mockns/n1/n2\"; "
  +         + "xmlns:n3=\"http://apache.org/xindice/mockns/n1/n3\"; "
  +         + "xmlns:n4=\"http://apache.org/xindice/mockns/n1/n4\"; "
  +         + "xmlns:n5=\"http://apache.org/xindice/mockns/n1/n5\"; "
  +         + "xmlns:n6=\"http://apache.org/xindice/mockns/n1/n6\"; "
  +         + "xmlns:n7=\"http://apache.org/xindice/mockns/n7\"; "
  +         + "n7:aaa=\"n1\" "
  +         + "n7:bbb=\"something\">"
  +         + ""
  +         + "<n2:aaa />"
  +         + "<n2:bbb />"
  +         + "<n2:ccc with=\"an attribute\">Whatever</n2:ccc>"
  +         + "<n2:ddd>Hello World!</n2:ddd>"
  +         + "<n2:eee />"
  +         + "<n1:aaa>0</n1:aaa>"
  +         + "<n1:bbb>More text</n1:bbb>"
  +         + "<n3:aaa />"
  +         + "<n3:bbb />"
  +         + "<n4:aaa />"
  +         + "<n4:bbb />"
  +         + "<n5:aaa>Even more text, with newlines\n and stuff</n5:aaa>"
  +         + "<n6:aaa />"
        + "</n1:n1>";
       
   
  @@ -67,7 +66,6 @@
        * @see junit.framework.TestCase#setUp()
        */
       protected void setUp() throws Exception {
  -        
           // Xindice parsing
           doc = DOMParser.toDocument(XML);
           generator = new SAXEventGenerator(doc);
  @@ -125,7 +123,6 @@
       public void testComment() {
           assertEquals(jaxpHandler.commentCount, xindiceHandler.commentCount);
       }
  -         
   }
   
   /**
  @@ -150,125 +147,78 @@
       int commentCount = 0;   
       ArrayList nameSpacesList = new ArrayList();
       
  -    /**
  -     * @see 
org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
  -     */
       public void setDocumentLocator(Locator arg0) {
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#startDocument()
  -     */
  +
       public void startDocument() throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#endDocument()
  -     */
  +
       public void endDocument() throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, 
java.lang.String)
  -     */
  +
       public void startPrefixMapping(String arg0, String arg1)
  -        throws SAXException {
  -            startPrefixMappingCount++;
  +            throws SAXException {
  +        startPrefixMappingCount++;
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
  -     */
  +
       public void endPrefixMapping(String arg0) throws SAXException {
  -            endPrefixMappingCount++;
  +        endPrefixMappingCount++;
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, 
java.lang.String, java.lang.String, org.xml.sax.Attributes)
  -     */
  -    public void startElement(
  -        String nsUri,
  -        String localName,
  -        String name,
  -        Attributes attrs)
  -        throws SAXException {
  -            
  +
  +    public void startElement(String nsUri, String localName, String name, 
Attributes attrs)
  +            throws SAXException {
           startElementCount++;
  -        
  -        if (!nameSpacesList.contains(nsUri))
  +        if (!nameSpacesList.contains(nsUri)) {
               nameSpacesList.add(nsUri);
  -            
  -        attributesCount += attrs.getLength();
  -       
  +        }
  +        // Do not count namespace declaration attributes
  +        for (int i=0; i <attrs.getLength(); i++) {
  +            if (!attrs.getQName(i).startsWith("xmlns:"))
  +                attributesCount ++;
  +        }
       }
       
  -    /**
  -     * @see org.xml.sax.ContentHandler#endElement(java.lang.String, 
java.lang.String, java.lang.String)
  -     */
  -    public void endElement(
  -        String nsUri, 
  -        String localName, 
  -        String name)
  -        throws SAXException {
  -            
  -        endElementCount++;    
  +    public void endElement(String nsUri, String localName, String name)
  +            throws SAXException {
  +        endElementCount++;
       }
       
  -    /**
  -     * @see org.xml.sax.ContentHandler#characters(char[], int, int)
  -     */
       public void characters(char[] ch, int start, int end)
  -        throws SAXException {
  -            charactersCount += new String(ch, start, end).length();
  +            throws SAXException {
  +        charactersCount += new String(ch, start, end).length();
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
  -     */
  +
       public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
  -        throws SAXException {
  +            throws SAXException {
       }
  -    /**
  -     * @see 
org.xml.sax.ContentHandler#processingInstruction(java.lang.String, 
java.lang.String)
  -     */
  +
       public void processingInstruction(String arg0, String arg1)
  -        throws SAXException {
  +            throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
  -     */
  +
       public void skippedEntity(String arg0) throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, 
java.lang.String, java.lang.String)
  -     */
  +
       public void startDTD(String arg0, String arg1, String arg2)
  -        throws SAXException {
  +            throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#endDTD()
  -     */
  +
       public void endDTD() throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
  -     */
  +
       public void startEntity(String arg0) throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
  -     */
  +
       public void endEntity(String arg0) throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#startCDATA()
  -     */
  +
       public void startCDATA() throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#endCDATA()
  -     */
  +
       public void endCDATA() throws SAXException {
       }
  -    /**
  -     * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
  -     */
  +
       public void comment(char[] ch, int start, int end) throws SAXException {
           commentCount += new String(ch, start, end).length();    
       }
  -    
  -}    
  \ No newline at end of file
  +}
  
  
  

Reply via email to