vgritsenko 2003/12/25 18:41:58
Modified: java/src/org/apache/xindice/client/xmldb XindiceCollection.java java/src/org/apache/xindice/client/xmldb/embed CollectionImpl.java java/src/org/apache/xindice/client/xmldb/services CollectionManager.java java/src/org/apache/xindice/client/xmldb/xmlrpc CollectionImpl.java java/src/org/apache/xindice/core CollectionManager.java java/tests/src/org/apache/xindice/integration/client XmlDbClient.java java/tests/src/org/apache/xindice/integration/client/basic CollectionTest.java java/tests/src/org/apache/xindice/integration/client/resources BinaryResourceTest.java java/tests/src/org/apache/xindice/integration/client/services IndexedSearchTest.java Log: First argument in xindice's API createCollection method is path, which was treated as name on several occasions. Attempt to fix collection integration test. Revision Changes Path 1.16 +11 -7 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- XindiceCollection.java 24 Dec 2003 02:22:12 -0000 1.15 +++ XindiceCollection.java 26 Dec 2003 02:41:58 -0000 1.16 @@ -323,23 +323,27 @@ public abstract Collection createCollection(String name) throws XMLDBException; /** - * Creates a new child collection in this collection + * Creates a new child collection. + * If path is a simple name (no '/' character), collection will be created + * in this collection. If path contains more then one element, collection will be + * created in the corresponding sub-collection of this collection (which must + * already exist). * - * @param name The name for new child collection + * @param path The path for new child collection * @return object representing newly created collection * @exception XMLDBException thrown if collection creation fails for some * reason */ - public abstract Collection createCollection(String name, Document configuration) throws XMLDBException; + public abstract Collection createCollection(String path, Document configuration) throws XMLDBException; /** * Removes child collection from this collection * - * @param childName name of child collection + * @param name name of child collection * @exception XMLDBException thrown if collection creation fails for some * reason */ - public abstract void removeCollection(String childName) throws XMLDBException; + public abstract void removeCollection(String name) throws XMLDBException; /** * Returns a list of all indexers for this collection. 1.30 +25 -6 xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java Index: CollectionImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- CollectionImpl.java 24 Dec 2003 02:52:44 -0000 1.29 +++ CollectionImpl.java 26 Dec 2003 02:41:58 -0000 1.30 @@ -61,6 +61,7 @@ import java.util.Enumeration; import java.util.Hashtable; +import java.util.StringTokenizer; import org.apache.xindice.client.xmldb.ResourceSetImpl; import org.apache.xindice.client.xmldb.XindiceCollection; @@ -507,14 +508,32 @@ } } - /* see superclass for documentation */ - public org.xmldb.api.base.Collection createCollection(String name, Document configuration) throws XMLDBException { + // See superclass for documentation. Note that first argument is the path, not the name. + public org.xmldb.api.base.Collection createCollection(String path, Document configuration) throws XMLDBException { checkOpen(); try { Configuration config = new Configuration(configuration.getDocumentElement(), false); - col.createCollection(name, config); + col.createCollection(path, config); + + // Traverse path to get newly created collection + org.xmldb.api.base.Collection col = this; + if (path.indexOf("/") != -1) { + StringTokenizer st = new StringTokenizer(path, "/"); + while (col != null && st.hasMoreTokens()) { + path = st.nextToken().trim(); + if (path.length() == 0) { + continue; + } + + if (st.hasMoreTokens()) { + col = col.getChildCollection(path); + } else { + break; + } + } + } - return getChildCollection(name); + return col.getChildCollection(path); } catch (Exception e) { throw FaultCodes.createXMLDBException(ErrorCodes.INVALID_COLLECTION, FaultCodes.GEN_UNKNOWN, 1.10 +3 -2 xml-xindice/java/src/org/apache/xindice/client/xmldb/services/CollectionManager.java Index: CollectionManager.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/services/CollectionManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CollectionManager.java 7 Aug 2003 20:13:20 -0000 1.9 +++ CollectionManager.java 26 Dec 2003 02:41:58 -0000 1.10 @@ -72,6 +72,7 @@ * @version CVS $Revision$, $Date$ */ public interface CollectionManager { + /** * Returns the name of the collection that this manager is associated with. * 1.42 +24 -6 xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java Index: CollectionImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- CollectionImpl.java 25 Dec 2003 19:16:06 -0000 1.41 +++ CollectionImpl.java 26 Dec 2003 02:41:58 -0000 1.42 @@ -608,20 +608,38 @@ return createCollection(name, null); } - /* see superclass for documentation */ - public Collection createCollection(String name, Document configuration) throws XMLDBException { + // See superclass for documentation. Note that first argument is the path, not the name. + public Collection createCollection(String path, Document configuration) throws XMLDBException { checkOpen(); try { Hashtable params = new Hashtable(); params.put(RPCDefaultMessage.COLLECTION, collPath); - params.put(RPCDefaultMessage.NAME, name); + params.put(RPCDefaultMessage.NAME, path); if (configuration != null) { params.put(RPCDefaultMessage.CONFIGURATION, TextWriter.toString(configuration)); } runRemoteCommand("CreateCollection", params); - return getChildCollection(name); + // Traverse path to get newly created collection + org.xmldb.api.base.Collection col = this; + if (path.indexOf("/") != -1) { + StringTokenizer st = new StringTokenizer(path, "/"); + while (col != null && st.hasMoreTokens()) { + path = st.nextToken().trim(); + if (path.length() == 0) { + continue; + } + + if (st.hasMoreTokens()) { + col = col.getChildCollection(path); + } else { + break; + } + } + } + + return col.getChildCollection(path); } catch (XMLDBException x) { throw x; // propagate any xmldb exception. 1.24 +6 -2 xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java Index: CollectionManager.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- CollectionManager.java 25 Dec 2003 20:04:40 -0000 1.23 +++ CollectionManager.java 26 Dec 2003 02:41:58 -0000 1.24 @@ -243,6 +243,10 @@ * @return The Collection (or null) */ public Collection getCollection(String path) throws DBException { + if (path == null) { + return null; + } + if (path.indexOf("/") != -1) { CollectionManager cm = this; StringTokenizer st = new StringTokenizer(path, "/"); 1.13 +15 -17 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- XmlDbClient.java 23 Dec 2003 12:11:12 -0000 1.12 +++ XmlDbClient.java 26 Dec 2003 02:41:58 -0000 1.13 @@ -93,28 +93,26 @@ return col.getName(); } - public Collection createCollection(String path, String name) throws Exception { - Collection col = DatabaseManager.getCollection(driver + "/" + path); - if (col == null) { - throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null"); - } - CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0"); + public Collection createCollection(String parent, String name) throws Exception { + return createCollection(parent, name, name); + } + public Collection createCollection(String parent, String path, String name) throws Exception { // FIXME: inline metadata conflicts with indexers? - String collectionConfig - = "<collection compressed=\"true\" name=\"" + name + "\" inline-metadata=\"false\">" - + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>" - + "</collection>"; - return service.createCollection(name, DOMParser.toDocument(collectionConfig)); + String config = + "<collection compressed=\"true\" name=\"" + name + "\" inline-metadata=\"false\">" + + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>" + + "</collection>"; + return createCollection(parent, path, DOMParser.toDocument(config)); } - public Collection createCollection(String path, String name, Document configuration) throws Exception { - Collection col = DatabaseManager.getCollection(driver + "/" + path); + public Collection createCollection(String parent, String path, Document configuration) throws Exception { + Collection col = DatabaseManager.getCollection(driver + "/" + parent); if (col == null) { - throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null"); + throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + parent + ") returned null"); } CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0"); - return service.createCollection(name, configuration); + return service.createCollection(path, configuration); } public Collection getCollection(String path) throws Exception { 1.15 +18 -12 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- CollectionTest.java 24 Dec 2003 15:23:53 -0000 1.14 +++ CollectionTest.java 26 Dec 2003 02:41:58 -0000 1.15 @@ -108,7 +108,9 @@ this.client.createCollection(TEST_COLLECTION_PATH, "nested"); assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH)); - this.client.createCollection(TEST_COLLECTION_PATH + "/nested", "child2"); + // Test create collection with path + this.client.createCollection(TEST_COLLECTION_PATH, "nested/child2", "child2"); + this.client.createCollection(TEST_COLLECTION_PATH + "/nested", "child3"); assertEquals(2, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); @@ -134,10 +136,10 @@ public void testCreateCollectionEmptyName() throws Exception { try { - this.client.createCollection(TEST_COLLECTION_PATH, ""); + this.client.createCollection(TEST_COLLECTION_PATH, "emptyname", ""); } catch (XMLDBException e) { - assertTrue(e.vendorErrorCode == FaultCodes.COL_CANNOT_CREATE); - assertTrue(e.getMessage().lastIndexOf("No name specified") > 0); + assertTrue("Error Code (Expected " + FaultCodes.COL_CANNOT_CREATE + ", got " + e.vendorErrorCode, + e.vendorErrorCode == FaultCodes.COL_CANNOT_CREATE); return; } fail(); @@ -145,9 +147,10 @@ public void testCreateCollectionNullName() throws Exception { try { - this.client.createCollection(TEST_COLLECTION_PATH, null); + this.client.createCollection(TEST_COLLECTION_PATH, "nullname", (String) null); } catch (XMLDBException e) { - // TODO assertTrue(e.vendorErrorCode == FaultCodes.COL_CANNOT_CREATE); + assertTrue("Error Code (Expected " + FaultCodes.COL_CANNOT_CREATE + ", got " + e.vendorErrorCode, + e.vendorErrorCode == FaultCodes.COL_CANNOT_CREATE); return; } fail(); @@ -155,9 +158,10 @@ public void testCreateCollectionInvalidName() throws Exception { try { - this.client.createCollection(TEST_COLLECTION_PATH, "my/collection"); + this.client.createCollection(TEST_COLLECTION_PATH, "invalidname", "my/collection"); } catch (XMLDBException e) { - // TODO assertTrue(e.vendorErrorCode == FaultCodes.COL_CANNOT_CREATE); + assertTrue("Error Code (Expected " + FaultCodes.COL_CANNOT_CREATE + ", got " + e.vendorErrorCode, + e.vendorErrorCode == FaultCodes.COL_CANNOT_CREATE); return; } fail(); @@ -170,7 +174,8 @@ try { this.client.dropCollection(TEST_COLLECTION_PATH, "droptwice"); } catch (XMLDBException e) { - assertTrue(e.vendorErrorCode == FaultCodes.COL_COLLECTION_NOT_FOUND); + assertTrue("Error Code (Expected " + FaultCodes.COL_COLLECTION_NOT_FOUND + ", got " + e.vendorErrorCode, + e.vendorErrorCode == FaultCodes.COL_COLLECTION_NOT_FOUND); return; } fail(); @@ -180,7 +185,8 @@ try { this.client.dropCollection(TEST_COLLECTION_PATH, null); } catch (XMLDBException e) { - // TODO assertTrue(e.vendorErrorCode == FaultCodes.COL_CANNOT_DROP); + assertTrue("Error Code (Expected " + FaultCodes.COL_COLLECTION_NOT_FOUND + ", got " + e.vendorErrorCode, + e.vendorErrorCode == FaultCodes.COL_COLLECTION_NOT_FOUND); return; } fail(); 1.3 +3 -2 xml-xindice/java/tests/src/org/apache/xindice/integration/client/resources/BinaryResourceTest.java Index: BinaryResourceTest.java =================================================================== RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/resources/BinaryResourceTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BinaryResourceTest.java 24 Dec 2003 02:50:14 -0000 1.2 +++ BinaryResourceTest.java 26 Dec 2003 02:41:58 -0000 1.3 @@ -78,7 +78,8 @@ = "<collection compressed=\"true\" name=\"" + name + "\" inline-metadata=\"true\">" + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>" + "</collection>"; - this.client.createCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME, name, DOMParser.toDocument(cfg)); + this.client.createCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME, + name, DOMParser.toDocument(cfg)); } public void testRoundTrip() throws Exception { 1.4 +4 -4 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- IndexedSearchTest.java 14 Dec 2003 19:52:10 -0000 1.3 +++ IndexedSearchTest.java 26 Dec 2003 02:41:58 -0000 1.4 @@ -530,7 +530,7 @@ "SEWA", // index name "Name", // index type "[EMAIL PROTECTED]", // index pattern - 10, // indexed query speedup expected (conservative) + 6, // indexed query speedup expected (conservative) new String[] { // test docs specifically for this test "<?xml version='1.0'?>" + "<person number3='yes'>" + @@ -749,7 +749,7 @@ "SENA", // index name "Value", // index type "[EMAIL PROTECTED]", // index pattern - 7, // indexed query speedup expected (conservative) + 6, // indexed query speedup expected (conservative) new String[] { // test docs specifically for this test "<?xml version='1.0'?>" + "<person number3='yes'>" +