kevinross    2003/07/10 07:43:52

  Modified:    java/tests/src/org/apache/xindice/integration/client
                        XmlDbClient.java
               java/tests/src/org/apache/xindice/integration/client/basic
                        CollectionTest.java DocumentTest.java
               java/src/org/apache/xindice/client/xmldb
                        XindiceCollection.java
  Log:
  PR: 21462
  Patch Submitted by: Kevin O'Neill ([EMAIL PROTECTED])
  Reviewed by: Kevin Ross
  
  Unit tests updated and run.
  
  If a collection is requested and it's name ends with a / then the collection
  name returned from getName is "". This patch strips the / from the end of the
  name when the collection object is created.
  
  There is also an additional test for this condition and a getContentAsSAX 
test I
  used to debug a problem elsewhere.
  
  Revision  Changes    Path
  1.6       +18 -2     
xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java
  
  Index: XmlDbClient.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XmlDbClient.java  3 Jun 2003 02:18:58 -0000       1.5
  +++ XmlDbClient.java  10 Jul 2003 14:43:51 -0000      1.6
  @@ -63,6 +63,7 @@
   import org.apache.xindice.util.XindiceException;
   import org.apache.xindice.xml.dom.DOMParser;
   import org.w3c.dom.Document;
  +import org.xml.sax.ContentHandler;
   import org.xmldb.api.DatabaseManager;
   import org.xmldb.api.base.Collection;
   import org.xmldb.api.modules.XMLResource;
  @@ -204,6 +205,21 @@
   
                return document.getContent().toString();
        }
  +
  +     public void getDocumentAsSax(String path, String name, ContentHandler 
handler) throws Exception {
  +             Collection col = DatabaseManager.getCollection(driver + "/" + 
path);
  +             if (col == null) {
  +                     throw new 
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") 
returned null");
  +             }
  +             XMLResource document = (XMLResource) col.getResource(name);
  +
  +             if (document == null) {
  +                     return;
  +             }
  +
  +             document.getContentAsSAX(handler);
  +     }
  +
   
        public String[] listDocuments(String path) throws Exception {
                Collection col = DatabaseManager.getCollection(driver + "/" + 
path);
  
  
  
  1.5       +9 -2      
xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/CollectionTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CollectionTest.java       6 Apr 2003 05:37:16 -0000       1.4
  +++ CollectionTest.java       10 Jul 2003 14:43:51 -0000      1.5
  @@ -215,6 +215,13 @@
         this.client.dropCollection(TEST_COLLECTION_PATH, "getname");
      }
   
  +   public void testGetNameEndWithSlash()
  +              throws Exception {
  +       this.client.createCollection(TEST_COLLECTION_PATH, "getname");
  +       assertEquals("getname", this.client.getName(TEST_COLLECTION_PATH + 
"/getname/"));
  +       this.client.dropCollection(TEST_COLLECTION_PATH, "getname");
  +   }
  +
      public void testGetParentCollection()
            throws Exception {
         Collection col = this.client.createCollection(TEST_COLLECTION_PATH, 
"childcol");
  
  
  
  1.4       +22 -3     
xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/DocumentTest.java
  
  Index: DocumentTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/DocumentTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DocumentTest.java 28 Oct 2002 08:39:20 -0000      1.3
  +++ DocumentTest.java 10 Jul 2003 14:43:51 -0000      1.4
  @@ -59,8 +59,10 @@
   
   package org.apache.xindice.integration.client.basic;
   
  -import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
  +import java.io.StringWriter;
   
  +import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
  +import org.apache.xml.serialize.XMLSerializer;
   import org.xmldb.api.base.XMLDBException;
   
   /**
  @@ -121,6 +123,23 @@
         this.client.removeDocument(TEST_COLLECTION_PATH, "doc1");
      }
   
  +     public void testGetDocumentAsSAX() throws Exception {
  +             String testDocument = "<?xml 
version=\"1.0\"?>\n<data><test>test data</test></data>";
  +             this.client.insertDocument(TEST_COLLECTION_PATH, "doc1", 
testDocument);
  +
  +             StringWriter out = new StringWriter();
  +             XMLSerializer serializer = new XMLSerializer();
  +             serializer.setOutputCharStream(out); 
  +
  +             this.client.getDocumentAsSax(TEST_COLLECTION_PATH, "doc1", 
serializer);
  +             String doc = out.toString();
  +             
  +             assertNotNull(doc);
  +             assertEquals(testDocument, doc);
  +
  +             this.client.removeDocument(TEST_COLLECTION_PATH, "doc1");
  +     }       
  +     
      public void testGetInexistantDocument()
            throws Exception {
         String doc = this.client.getDocument(TEST_COLLECTION_PATH, "ghostdoc");
  
  
  
  1.7       +2 -2      
xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
  
  Index: XindiceCollection.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XindiceCollection.java    21 Nov 2002 07:44:35 -0000      1.6
  +++ XindiceCollection.java    10 Jul 2003 14:43:52 -0000      1.7
  @@ -104,7 +104,7 @@
        */
       public XindiceCollection(String collPath) throws XMLDBException {
           
  -        this.collPath = collPath;
  +        this.collPath = collPath.endsWith("/") ? collPath.substring(0, 
collPath.length() - 1) : collPath;
   
           services = new Hashtable();
           
  
  
  

Reply via email to