vgritsenko    2004/02/23 19:22:46

  Modified:    java/tests/src/org/apache/xindice
                        IntegrationXmlRpcTests.java
               java/tests/src/org/apache/xindice/integration/client
                        XmlDbClientSetup.java
               java/tests/src/org/apache/xindice/integration/client/basic
                        CollectionTest.java DocumentTest.java
               java/tests/src/org/apache/xindice/integration/client/services
                        IndexedSearchTest.java
  Log:
  Add couple of tests; formatting changes.
  
  Revision  Changes    Path
  1.9       +4 -5      
xml-xindice/java/tests/src/org/apache/xindice/IntegrationXmlRpcTests.java
  
  Index: IntegrationXmlRpcTests.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/IntegrationXmlRpcTests.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- IntegrationXmlRpcTests.java       8 Feb 2004 03:57:16 -0000       1.8
  +++ IntegrationXmlRpcTests.java       24 Feb 2004 03:22:45 -0000      1.9
  @@ -49,19 +49,18 @@
        }
   
       public static Test suite() throws Exception {
  -
           String url = "xmldb:xindice://";
           String hostport = System.getProperty("test.xmlrpc.hostport", 
"localhost:8888");
           if (hostport != null) {
               url = url + hostport;
           }
  +
           return new TestSetup(new 
XmlDbClientSetup(IntegrationTests.testSuite("XmlRpc client integration tests"), 
new XmlDbClient(url))) {
   
               private Database database;
   
               public void setUp() throws Exception {
                   String driver = 
"org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl";
  -                //String driver = 
"org.apache.xindice.client.xmldb.DatabaseImpl";
                   Class cls = Class.forName(driver);
   
                   database = (Database) cls.newInstance();
  @@ -73,7 +72,7 @@
                   if (xmlrpcDriver != null) {
                       database.setProperty("xmlrpc-driver", xmlrpcDriver);
                   }
  -                
  +
                   DatabaseManager.registerDatabase(database);
               }
   
  
  
  
  1.8       +4 -4      
xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClientSetup.java
  
  Index: XmlDbClientSetup.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClientSetup.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XmlDbClientSetup.java     8 Feb 2004 03:57:02 -0000       1.7
  +++ XmlDbClientSetup.java     24 Feb 2004 03:22:45 -0000      1.8
  @@ -28,8 +28,8 @@
    */
   public class XmlDbClientSetup extends TestSetup {
   
  -    static public final String INSTANCE_NAME = "db";
  -    static public final String TEST_COLLECTION_NAME = "testing";
  +    public static final String INSTANCE_NAME = "db";
  +    public static final String TEST_COLLECTION_NAME = "testing";
   
       private XmlDbClient client;
   
  
  
  
  1.18      +12 -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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CollectionTest.java       19 Feb 2004 03:29:01 -0000      1.17
  +++ CollectionTest.java       24 Feb 2004 03:22:45 -0000      1.18
  @@ -225,6 +225,16 @@
           assertNull(this.client.getCollection(TEST_COLLECTION_PATH + 
"/unknown"));
       }
   
  +    public void testGetChildCollectionEndsWithSlash() throws Exception {
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +        try {
  +            col.getChildCollection("/db");
  +            fail("Expected ErrorCodes.INVALID_COLLECTION");
  +        } catch (XMLDBException e) {
  +            assertEquals("ErrorCodes.INVALID_COLLECTION", 
ErrorCodes.INVALID_COLLECTION, e.errorCode);
  +        }
  +    }
  +
       public void testChildCollectionCount() throws Exception {
           Collection col = this.client.createCollection(TEST_COLLECTION_PATH, 
"childcol");
           assertEquals(0, col.getChildCollectionCount());
  
  
  
  1.10      +31 -21    
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DocumentTest.java 8 Feb 2004 03:57:02 -0000       1.9
  +++ DocumentTest.java 24 Feb 2004 03:22:46 -0000      1.10
  @@ -35,6 +35,7 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.XMLReader;
   import org.xmldb.api.base.XMLDBException;
  +import org.xmldb.api.base.ErrorCodes;
   
   /**
    * @version CVS $Revision$, $Date$
  @@ -50,6 +51,15 @@
         assertEquals(0, this.client.countDocument(TEST_COLLECTION_PATH));
      }
   
  +   public void testInsertDocumentNullContent() throws Exception {
  +       try {
  +           this.client.insertDocument(TEST_COLLECTION_PATH, "testdoc", null);
  +           fail("Insert null document should fail");
  +       } catch (XMLDBException e) {
  +           assertEquals("ErrorCodes.INVALID_RESOURCE", 
ErrorCodes.INVALID_RESOURCE, e.errorCode);
  +       }
  +   }
  +
      public void testRemoveDocumentInvalidName() throws Exception {
         try {
            this.client.removeDocument(TEST_COLLECTION_PATH, "invalidname");
  @@ -97,13 +107,13 @@
   
                this.client.getDocumentAsSax(TEST_COLLECTION_PATH, "doc1", 
serializer);
                String doc = out.toString();
  -             
  +
                assertNotNull(doc);
                assertXMLEqual(testDocument, doc);
   
                this.client.removeDocument(TEST_COLLECTION_PATH, "doc1");
  -     }       
  -     
  +     }
  +
      public void testGetInexistantDocument() throws Exception {
         String doc = this.client.getDocument(TEST_COLLECTION_PATH, "ghostdoc");
         assertNull(doc);
  @@ -159,11 +169,11 @@
         this.client.removeDocument(TEST_COLLECTION_PATH, "doc2");
         assertEquals(0, this.client.countDocument(TEST_COLLECTION_PATH));
      }
  -   
  +
      public void testDocumentWithNameSpaces() throws Exception
      {
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
  -             
  +
                final String testDocument = fetchTestDocument("namespaces.xml");
                this.client.insertDocument(TEST_COLLECTION_PATH, 
"namespaces.xml", testDocument);
   
  @@ -174,11 +184,11 @@
                this.client.removeDocument(TEST_COLLECTION_PATH, 
"namespaces.xml");
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
      }
  -   
  +
      public void testDocumentWithNameSpacesSAX() throws Exception
      {
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
  -             
  +
                final String testDocument = fetchTestDocument("namespaces.xml");
                this.client.insertDocument(TEST_COLLECTION_PATH, 
"namespaces.xml", testDocument);
   
  @@ -209,7 +219,7 @@
                this.client.removeDocument(TEST_COLLECTION_PATH, 
"namespaces.xml");
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
        }
  -     
  +
        public void testDocumentWithSimpleNameSpacePrefixesSAX() throws 
Exception
        {
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
  @@ -243,15 +253,15 @@
   
                this.client.removeDocument(TEST_COLLECTION_PATH, 
"namespaces.xml");
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
  -     }       
  -   
  +     }
  +
        public void testDocumentWithChangingNameSpacePrefixesSAX() throws 
Exception
        {
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
   
                final String testDocument = 
fetchTestDocument("namespace-changingprefixes.xml");
                this.client.insertDocument(TEST_COLLECTION_PATH, 
"namespaces.xml", testDocument);
  -             
  +
                final StringWriter out = new StringWriter();
                final ContentHandler serializer = createSerializer(out);
   
  @@ -263,16 +273,16 @@
   
                this.client.removeDocument(TEST_COLLECTION_PATH, 
"namespaces.xml");
                assertEquals(0, 
this.client.countDocument(TEST_COLLECTION_PATH));
  -     }       
  +     }
   
        private String fetchTestDocument(String name) throws IOException, 
SAXException, ParserConfigurationException
        {
                final StringWriter out = new StringWriter();
                final ContentHandler serializer = createSerializer(out);
  -             
  +
                parseTestDocument(name, serializer);
  -             
  -             return out.toString(); 
  +
  +             return out.toString();
        }
   
        private void parseTestDocument(String name, ContentHandler handler) 
throws IOException, SAXException, ParserConfigurationException
  @@ -288,11 +298,11 @@
                factory.setNamespaceAware(true);
   
                final XMLReader saxReader = 
factory.newSAXParser().getXMLReader();
  -                             
  -             saxReader.setContentHandler(handler);           
  +
  +             saxReader.setContentHandler(handler);
                saxReader.parse(new InputSource(in));
        }
  -     
  +
        private ContentHandler createSerializer(final Writer out)
        {
                final ContentHandler serializer = new StringSerializer()
  @@ -300,7 +310,7 @@
                        public void endDocument() throws SAXException
                        {
                                super.endDocument();
  -                             
  +
                                try
                                {
                                        out.write(this.toString());
  
  
  
  1.9       +11 -11    
xml-xindice/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java
  
  Index: IndexedSearchTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- IndexedSearchTest.java    19 Feb 2004 03:29:01 -0000      1.8
  +++ IndexedSearchTest.java    24 Feb 2004 03:22:46 -0000      1.9
  @@ -22,7 +22,9 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
   import org.apache.xindice.integration.client.XmlDbClientSetup;
  +import org.apache.xindice.xml.NodeSource;
   import org.apache.xindice.xml.TextWriter;
  +import org.apache.xindice.xml.dom.NodeImpl;
   
   import org.custommonkey.xmlunit.XMLAssert;
   import org.w3c.dom.Document;
  @@ -36,7 +38,6 @@
   
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
  -
   import java.io.StringReader;
   
   /**
  @@ -296,15 +297,14 @@
               DocumentBuilder aBuilder = 
itsDocumentBuilderFactory.newDocumentBuilder();
               Document aDocument = aBuilder.parse(
                       new InputSource(new StringReader(theXML)));
  -            Element aRootElement = aDocument.getDocumentElement();
  +            Element elm = aDocument.getDocumentElement();
   
  -            final String aPrefix = "src";
  -            
aRootElement.setAttribute(org.apache.xindice.xml.dom.NodeImpl.XMLNS_PREFIX + 
":" + aPrefix,
  -                                      
org.apache.xindice.xml.NodeSource.SOURCE_NS);
  -            aRootElement.setAttribute(aPrefix + ":" + 
org.apache.xindice.xml.NodeSource.SOURCE_COL,
  -                                      "/" + 
INDEXED_SEARCH_TEST_COLLECTION_PATH);
  -            aRootElement.setAttribute(aPrefix + ":" + 
org.apache.xindice.xml.NodeSource.SOURCE_KEY, theKey);
  -            return TextWriter.toString(aRootElement);
  +            final String pfx = "src";
  +            elm.setAttribute(NodeImpl.XMLNS_PREFIX + ":" + pfx, 
NodeSource.SOURCE_NS);
  +            elm.setAttribute(pfx + ":" + NodeSource.SOURCE_COL,
  +                             "/" + INDEXED_SEARCH_TEST_COLLECTION_PATH);
  +            elm.setAttribute(pfx + ":" + NodeSource.SOURCE_KEY, theKey);
  +            return TextWriter.toString(elm);
           }
   
           /**
  
  
  

Reply via email to