kevinross 2003/07/14 14:26:12
Modified: java/tests/src/org/apache/xindice/integration/client/basic CollectionTest.java java/tests/src/org/apache/xindice/integration/client AbstractXmlDbClientTest.java Log: formatted Revision Changes Path 1.6 +174 -184 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CollectionTest.java 10 Jul 2003 14:43:51 -0000 1.5 +++ CollectionTest.java 14 Jul 2003 21:26:11 -0000 1.6 @@ -73,188 +73,178 @@ * @version $Revision$, $Date$ * @author Vladimir R. Bossicard <[EMAIL PROTECTED]> */ -public class CollectionTest - extends AbstractXmlDbClientTest { +public class CollectionTest extends AbstractXmlDbClientTest { - /* This is just to make sure that the system is up and running. */ - public void testListInitialCollections() - throws Exception { - String[] collections = this.client.listCollections(XmlDbClientSetup.INSTANCE_NAME); - assertEquals(2, collections.length); - List col = new Vector(Arrays.asList(collections)); - assertTrue(col.contains(XmlDbClientSetup.TEST_COLLECTION_NAME)); - assertTrue(col.contains("system")); - } - - public void testCreateNestedCollection() - throws Exception { - this.client.createCollection(TEST_COLLECTION_PATH, "nested"); - assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH)); - - this.client.createCollection(TEST_COLLECTION_PATH + "/nested", "child2"); - this.client.createCollection(TEST_COLLECTION_PATH + "/nested", "child3"); - assertEquals(2, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); - - this.client.dropCollection(TEST_COLLECTION_PATH + "/nested", "child2"); - assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); - - this.client.dropCollection(TEST_COLLECTION_PATH + "/nested", "child3"); - assertEquals(0, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); - - this.client.dropCollection(TEST_COLLECTION_PATH, "nested"); - } - - public void testCreateDuplicateCollection() - throws Exception { - this.client.createCollection(TEST_COLLECTION_PATH, "duplicate"); - try { - this.client.createCollection(TEST_COLLECTION_PATH, "duplicate"); - } catch (XMLDBException e) { - //assertTrue( e.getMessage().lastIndexOf( "Duplicate Collection" ) > 0 ); - } - - this.client.dropCollection(TEST_COLLECTION_PATH, "duplicate"); - } - - public void testCreateCollectionEmptyName() - throws Exception { - try { - this.client.createCollection(TEST_COLLECTION_PATH, ""); - } catch (XMLDBException e) { - //assertTrue( e.getMessage().lastIndexOf( "Duplicate Collection" ) > 0 ); - return; - } - fail(); - } - - public void testCreateCollectionNullName() - throws Exception { - try { - this.client.createCollection(TEST_COLLECTION_PATH, null); - } catch (XMLDBException e) { - //assertTrue( e.getMessage().lastIndexOf( "Duplicate Collection" ) > 0 ); - return; - } - fail(); - } - - public void testDropCollectionTwice() - throws Exception { - this.client.createCollection(TEST_COLLECTION_PATH, "droptwice"); - - this.client.dropCollection(TEST_COLLECTION_PATH, "droptwice"); - try { - this.client.dropCollection(TEST_COLLECTION_PATH, "droptwice"); - } catch (XMLDBException e) { - //assertTrue( e.getMessage().lastIndexOf( "could not be found" ) > 0 ); - return; - } - fail(); - } - - public void testDropCollectionNullName() - throws Exception { - try { - this.client.dropCollection(TEST_COLLECTION_PATH, null); - } catch (XMLDBException e) { - //assertTrue( e.getMessage().lastIndexOf( "could not be found" ) > 0 ); - return; - } - fail(); - } - - public void testDropCollectionEmptyName() - throws Exception { - try { - this.client.dropCollection(TEST_COLLECTION_PATH, ""); - } catch (XMLDBException e) { - //assertTrue( e.getMessage().lastIndexOf( "could not be found" ) > 0 ); - return; - } - fail(); - } - - public void testGetCollectionCount() - throws Exception { - this.client.createCollection(TEST_COLLECTION_PATH, "count"); - assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH)); - - this.client.dropCollection(TEST_COLLECTION_PATH, "count"); - assertEquals(0, this.client.countCollections(TEST_COLLECTION_PATH)); - } - - public void testListCollections() - throws Exception { - String[] collections = this.client.listCollections(TEST_COLLECTION_PATH); - assertEquals(0, collections.length); - - this.client.createCollection(TEST_COLLECTION_PATH, "child1"); - this.client.createCollection(TEST_COLLECTION_PATH, "child2"); - - collections = this.client.listCollections(TEST_COLLECTION_PATH); - assertEquals(2, collections.length); - List col = new Vector(Arrays.asList(collections)); - assertTrue(col.contains("child1")); - assertTrue(col.contains("child2")); - - this.client.dropCollection(TEST_COLLECTION_PATH, "child1"); - collections = this.client.listCollections(TEST_COLLECTION_PATH); - assertEquals(1, collections.length); - assertEquals("child2", collections[0]); - - this.client.dropCollection(TEST_COLLECTION_PATH, "child2"); - - collections = this.client.listCollections(TEST_COLLECTION_PATH); - assertEquals(0, collections.length); - } - - public void testGetName() - 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 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"); - - Collection parent = col.getParentCollection(); - assertNotNull(parent); - assertEquals("current", parent.getName()); - - parent = parent.getParentCollection(); - assertNotNull(parent); - assertEquals("testing", parent.getName()); - - parent = parent.getParentCollection(); - assertNull(parent); - - this.client.dropCollection(TEST_COLLECTION_PATH, "childcol"); - } - - public void testGetCollectionUnknown() - throws Exception { - assertNull(this.client.getCollection(TEST_COLLECTION_PATH + "/unknown")); - } - - public void testChildCollectionCount() - throws Exception { - Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol"); - assertEquals(0, col.getChildCollectionCount()); - - this.client.createCollection(TEST_COLLECTION_PATH, "colcount"); - assertEquals(0, col.getChildCollectionCount()); - - this.client.dropCollection(TEST_COLLECTION_PATH, "colcount"); - assertEquals(0, col.getChildCollectionCount()); - } + /* This is just to make sure that the system is up and running. */ + public void testListInitialCollections() throws Exception { + String[] collections = this.client.listCollections(XmlDbClientSetup.INSTANCE_NAME); + assertEquals(2, collections.length); + List col = new Vector(Arrays.asList(collections)); + assertTrue(col.contains(XmlDbClientSetup.TEST_COLLECTION_NAME)); + assertTrue(col.contains("system")); + } + + public void testCreateNestedCollection() throws Exception { + this.client.createCollection(TEST_COLLECTION_PATH, "nested"); + assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH)); + + this.client.createCollection(TEST_COLLECTION_PATH + "/nested", "child2"); + this.client.createCollection(TEST_COLLECTION_PATH + "/nested", "child3"); + assertEquals(2, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); + + this.client.dropCollection(TEST_COLLECTION_PATH + "/nested", "child2"); + assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); + + this.client.dropCollection(TEST_COLLECTION_PATH + "/nested", "child3"); + assertEquals(0, this.client.countCollections(TEST_COLLECTION_PATH + "/nested")); + + this.client.dropCollection(TEST_COLLECTION_PATH, "nested"); + } + + public void testCreateDuplicateCollection() throws Exception { + this.client.createCollection(TEST_COLLECTION_PATH, "duplicate"); + try { + this.client.createCollection(TEST_COLLECTION_PATH, "duplicate"); + } + catch (XMLDBException e) { + //assertTrue( e.getMessage().lastIndexOf( "Duplicate Collection" ) > 0 ); + } + + this.client.dropCollection(TEST_COLLECTION_PATH, "duplicate"); + } + + public void testCreateCollectionEmptyName() throws Exception { + try { + this.client.createCollection(TEST_COLLECTION_PATH, ""); + } + catch (XMLDBException e) { + //assertTrue( e.getMessage().lastIndexOf( "Duplicate Collection" ) > 0 ); + return; + } + fail(); + } + + public void testCreateCollectionNullName() throws Exception { + try { + this.client.createCollection(TEST_COLLECTION_PATH, null); + } + catch (XMLDBException e) { + //assertTrue( e.getMessage().lastIndexOf( "Duplicate Collection" ) > 0 ); + return; + } + fail(); + } + + public void testDropCollectionTwice() throws Exception { + this.client.createCollection(TEST_COLLECTION_PATH, "droptwice"); + + this.client.dropCollection(TEST_COLLECTION_PATH, "droptwice"); + try { + this.client.dropCollection(TEST_COLLECTION_PATH, "droptwice"); + } + catch (XMLDBException e) { + //assertTrue( e.getMessage().lastIndexOf( "could not be found" ) > 0 ); + return; + } + fail(); + } + + public void testDropCollectionNullName() throws Exception { + try { + this.client.dropCollection(TEST_COLLECTION_PATH, null); + } + catch (XMLDBException e) { + //assertTrue( e.getMessage().lastIndexOf( "could not be found" ) > 0 ); + return; + } + fail(); + } + + public void testDropCollectionEmptyName() throws Exception { + try { + this.client.dropCollection(TEST_COLLECTION_PATH, ""); + } + catch (XMLDBException e) { + //assertTrue( e.getMessage().lastIndexOf( "could not be found" ) > 0 ); + return; + } + fail("Dropping a collection with empty name should throw an exception."); + } + + public void testGetCollectionCount() throws Exception { + this.client.createCollection(TEST_COLLECTION_PATH, "count"); + assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH)); + + this.client.dropCollection(TEST_COLLECTION_PATH, "count"); + assertEquals(0, this.client.countCollections(TEST_COLLECTION_PATH)); + } + + public void testListCollections() throws Exception { + String[] collections = this.client.listCollections(TEST_COLLECTION_PATH); + assertEquals(0, collections.length); + + this.client.createCollection(TEST_COLLECTION_PATH, "child1"); + this.client.createCollection(TEST_COLLECTION_PATH, "child2"); + + collections = this.client.listCollections(TEST_COLLECTION_PATH); + assertEquals(2, collections.length); + List col = new Vector(Arrays.asList(collections)); + assertTrue(col.contains("child1")); + assertTrue(col.contains("child2")); + + this.client.dropCollection(TEST_COLLECTION_PATH, "child1"); + collections = this.client.listCollections(TEST_COLLECTION_PATH); + assertEquals(1, collections.length); + assertEquals("child2", collections[0]); + + this.client.dropCollection(TEST_COLLECTION_PATH, "child2"); + + collections = this.client.listCollections(TEST_COLLECTION_PATH); + assertEquals(0, collections.length); + } + + public void testGetName() 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 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"); + + Collection parent = col.getParentCollection(); + assertNotNull(parent); + assertEquals("current", parent.getName()); + + parent = parent.getParentCollection(); + assertNotNull(parent); + assertEquals("testing", parent.getName()); + + parent = parent.getParentCollection(); + assertNull(parent); + + this.client.dropCollection(TEST_COLLECTION_PATH, "childcol"); + } + + public void testGetCollectionUnknown() throws Exception { + assertNull(this.client.getCollection(TEST_COLLECTION_PATH + "/unknown")); + } + + public void testChildCollectionCount() throws Exception { + Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol"); + assertEquals(0, col.getChildCollectionCount()); + + this.client.createCollection(TEST_COLLECTION_PATH, "colcount"); + assertEquals(0, col.getChildCollectionCount()); + + this.client.dropCollection(TEST_COLLECTION_PATH, "colcount"); + assertEquals(0, col.getChildCollectionCount()); + } } 1.3 +16 -20 xml-xindice/java/tests/src/org/apache/xindice/integration/client/AbstractXmlDbClientTest.java Index: AbstractXmlDbClientTest.java =================================================================== RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/AbstractXmlDbClientTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractXmlDbClientTest.java 28 Oct 2002 08:39:20 -0000 1.2 +++ AbstractXmlDbClientTest.java 14 Jul 2003 21:26:11 -0000 1.3 @@ -65,24 +65,20 @@ * @version $Revision$, $Date$ * @author Vladimir R. Bossicard <[EMAIL PROTECTED]> */ -public abstract class AbstractXmlDbClientTest - extends TestCase { +public abstract class AbstractXmlDbClientTest extends TestCase { - protected XmlDbClient client; - static public final String TEST_COLLECTION_PATH = XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME + "/current"; + protected XmlDbClient client; + static public final String TEST_COLLECTION_PATH = XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME + "/current"; - public void setXmlDbClient(XmlDbClient client) { - this.client = client; - } + public void setXmlDbClient(XmlDbClient client) { + this.client = client; + } - public void setUp() - throws Exception { - this.client.createCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME, "current"); - } - - public void tearDown() - throws Exception { - this.client.dropCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME, "current"); - } + public void setUp() throws Exception { + this.client.createCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME, "current"); + } + public void tearDown() throws Exception { + this.client.dropCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME, "current"); + } }