From: Sebastian B. <bo...@us...> - 2004-09-03 09:05:43
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12598/src/org/exist/xmldb/test Modified Files: RemoteCollectionTest.java AllTests.java Added Files: RemoteDBTest.java RemoteDatabaseImplTest.java Log Message: Make DatabaseImpl's RPCClient cache aware of different user identities. This fixes bug #1021687. --- NEW FILE: RemoteDatabaseImplTest.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-04 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.exist.xmldb.test; import org.exist.security.Permission; import org.exist.xmldb.UserManagementService; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Database; import org.xmldb.api.base.Resource; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.CollectionManagementService; /** * @author Sebastian Bossung, Technische Universitaet Hamburg-Harburg */ public class RemoteDatabaseImplTest extends RemoteDBTest { protected final static String ADMIN_PASSWORD = "somepwd"; protected final static String ADMIN_COLLECTION_NAME = "admin-collection"; public RemoteDatabaseImplTest(String name) { super(name); } public void testGetCollection() throws Exception { startServer(); Class cl = Class.forName(DB_DRIVER); Database database = (Database) cl.newInstance(); DatabaseManager.registerDatabase(database); Collection rootCollection = DatabaseManager.getCollection(URI + "/db", "admin", null); CollectionManagementService cms = (CollectionManagementService) rootCollection.getService( "CollectionManagementService", "1.0"); Collection adminCollection = cms.createCollection(ADMIN_COLLECTION_NAME); UserManagementService ums = (UserManagementService) rootCollection.getService("UserManagementService", "1.0"); if (ums != null) { Permission p = new Permission(); p.setPermissions("user=+read,+write,group=-read,-write,other=-read,-write"); ums.setPermissions(adminCollection, p); Collection guestCollection = DatabaseManager.getCollection(URI + "/db/" + ADMIN_COLLECTION_NAME, "guest", "guest"); Resource resource = guestCollection.createResource("testguest", "BinaryResource"); resource.setContent("123".getBytes()); try { guestCollection.storeResource(resource); fail(); } catch (XMLDBException e) { } cms.removeCollection(ADMIN_COLLECTION_NAME); stopServer(rootCollection); } } } Index: RemoteCollectionTest.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/test/RemoteCollectionTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RemoteCollectionTest.java 1 Sep 2004 17:41:31 -0000 1.2 --- RemoteCollectionTest.java 3 Sep 2004 09:05:33 -0000 1.3 *************** *** 8,15 **** import java.util.Iterator; - import junit.framework.TestCase; - import org.exist.Server; import org.exist.schema.RemoteSchemaService; - import org.exist.xmldb.RemoteCollection; import org.exist.xmldb.RemoteCollectionManagementService; import org.exist.xmldb.RemoteDatabaseInstanceManager; --- 8,12 ---- *************** *** 18,37 **** import org.exist.xmldb.RemoteXPathQueryService; import org.exist.xmldb.RemoteXUpdateQueryService; - import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; - import org.xmldb.api.base.Database; import org.xmldb.api.base.Resource; import org.xmldb.api.base.Service; import org.xmldb.api.base.XMLDBException; - import org.xmldb.api.modules.CollectionManagementService; /** WORK IN PROGRESS !!! * @author jmv */ ! public class RemoteCollectionTest extends TestCase { ! protected final static String URI = "xmldb:exist://localhost:8081/exist/xmlrpc"; ! private final static String COLLECTION_NAME = "unit-testing-collection"; ! private final static String DB_DRIVER = "org.exist.xmldb.DatabaseImpl"; ! private RemoteCollection collection = null; /** --- 15,27 ---- import org.exist.xmldb.RemoteXPathQueryService; import org.exist.xmldb.RemoteXUpdateQueryService; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Resource; import org.xmldb.api.base.Service; import org.xmldb.api.base.XMLDBException; /** WORK IN PROGRESS !!! * @author jmv */ ! public class RemoteCollectionTest extends RemoteDBTest { /** *************** *** 42,83 **** } - /** ? @see junit.framework.TestCase#setUp() - */ protected void setUp() throws Exception { ! String[] args = {"standalone"}; ! //Server.main(args); ! // Thread ?? ! Server.main(new String[] { } ); ! ! Class cl = Class.forName(DB_DRIVER); ! Database database = (Database) cl.newInstance(); ! DatabaseManager.registerDatabase(database); ! ! Collection rootCollection = DatabaseManager.getCollection(URI + "/db", "admin", null); ! ! Collection childCollection = rootCollection.getChildCollection(COLLECTION_NAME); ! if (childCollection == null) { ! CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0"); ! collection = (RemoteCollection) cms.createCollection(COLLECTION_NAME); ! } else { ! throw new Exception("Cannot run test because the collection /db/" + COLLECTION_NAME + " already " + ! "exists. If it is a left-over of a previous test run, please remove it manually."); ! } ! } ! /** ? @see junit.framework.TestCase#tearDown() ! */ ! protected void tearDown() throws Exception { ! Collection rootCollection = DatabaseManager.getCollection(URI + "/db", "admin", null); ! CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0"); ! cms.removeCollection(COLLECTION_NAME); ! Server.main(new String[] { "shutdown" } ); } ! public void testIndexQueryService() { // TODO ............. } public void testGetServices() throws XMLDBException { ! Service[] services = collection.getServices(); assertEquals(7, services.length); assertEquals(RemoteXPathQueryService.class, services[0].getClass()); --- 32,50 ---- } protected void setUp() throws Exception { ! setUpRemoteDatabase(); } ! ! protected void tearDown() throws Exception { ! removeCollection(); } ! ! ! public void testIndexQueryService() { // TODO ............. } public void testGetServices() throws XMLDBException { ! Service[] services = getCollection().getServices(); assertEquals(7, services.length); assertEquals(RemoteXPathQueryService.class, services[0].getClass()); *************** *** 91,102 **** public void testIsRemoteCollection() throws XMLDBException { ! assertTrue(collection.isRemoteCollection()); } public void testGetPath() throws XMLDBException { ! assertEquals("/db/" + COLLECTION_NAME, collection.getPath()); } public void testCreateResource() throws XMLDBException { { // XML resource: Resource resource = collection.createResource("testresource", "XMLResource"); --- 58,70 ---- public void testIsRemoteCollection() throws XMLDBException { ! assertTrue(getCollection().isRemoteCollection()); } public void testGetPath() throws XMLDBException { ! assertEquals("/db/" + getTestCollectionName(), getCollection().getPath()); } public void testCreateResource() throws XMLDBException { + Collection collection = getCollection(); { // XML resource: Resource resource = collection.createResource("testresource", "XMLResource"); *************** *** 127,131 **** createResources(binaryNames, "BinaryResource"); ! String[] actualContents = collection.listResources(); System.out.println(actualContents); for (int i = 0; i < actualContents.length; i++) { --- 95,99 ---- createResources(binaryNames, "BinaryResource"); ! String[] actualContents = getCollection().listResources(); System.out.println(actualContents); for (int i = 0; i < actualContents.length; i++) { *************** *** 144,148 **** private void createResources(ArrayList names, String type) throws XMLDBException { for (Iterator i = names.iterator(); i.hasNext(); ) ! collection.createResource((String) i.next(), type); } --- 112,116 ---- private void createResources(ArrayList names, String type) throws XMLDBException { for (Iterator i = names.iterator(); i.hasNext(); ) ! getCollection().createResource((String) i.next(), type); } Index: AllTests.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/test/AllTests.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AllTests.java 3 Aug 2004 16:45:45 -0000 1.5 --- AllTests.java 3 Sep 2004 09:05:33 -0000 1.6 *************** *** 13,16 **** --- 13,17 ---- // suite.addTest(new TestSuite(ResourceSetTest.class)); suite.addTest(new TestSuite(TestEXistXMLSerialize.class)); + suite.addTest(new TestSuite(RemoteCollectionTest.class)); //$JUnit-END$ return suite; --- NEW FILE: RemoteDBTest.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-04 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.exist.xmldb.test; import junit.framework.TestCase; import org.exist.Server; import org.exist.xmldb.DatabaseInstanceManager; import org.exist.xmldb.RemoteCollection; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Database; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.CollectionManagementService; /** * @author Sebastian Bossung, Technische Universitaet Hamburg-Harburg */ public abstract class RemoteDBTest extends TestCase { protected final static String URI = "xmldb:exist://localhost:8081/exist/xmlrpc"; private final static String COLLECTION_NAME = "unit-testing-collection"; public final static String DB_DRIVER = "org.exist.xmldb.DatabaseImpl"; private RemoteCollection collection = null; /** * @param name */ public RemoteDBTest(String name) { super(name); } /** * @throws Exception * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws XMLDBException */ protected void setUpRemoteDatabase() throws Exception, ClassNotFoundException, InstantiationException, IllegalAccessException, XMLDBException { startServer(); Class cl = Class.forName(DB_DRIVER); Database database = (Database) cl.newInstance(); DatabaseManager.registerDatabase(database); Collection rootCollection = DatabaseManager.getCollection(URI + "/db", "admin", null); Collection childCollection = rootCollection.getChildCollection(COLLECTION_NAME); if (childCollection == null) { CollectionManagementService cms = (CollectionManagementService) rootCollection.getService( "CollectionManagementService", "1.0"); setCollection((RemoteCollection) cms.createCollection(COLLECTION_NAME)); } else { throw new Exception("Cannot run test because the collection /db/" + COLLECTION_NAME + " already " + "exists. If it is a left-over of a previous test run, please remove it manually."); } } /** * @throws Exception */ protected void startServer() throws Exception { String[] args = { "standalone" }; //Server.main(args); // Thread ?? Server.main(new String[] {}); } /** * @throws XMLDBException * @throws Exception */ protected void removeCollection() throws XMLDBException, Exception { Collection rootCollection = DatabaseManager.getCollection(URI + "/db", "admin", null); CollectionManagementService cms = (CollectionManagementService) rootCollection.getService( "CollectionManagementService", "1.0"); cms.removeCollection(COLLECTION_NAME); } protected void stopServer(Collection current) throws XMLDBException { DatabaseInstanceManager mgr = (DatabaseInstanceManager) current.getService("DatabaseInstanceManager", "1.0"); if (mgr != null) mgr.shutdown(); } /** * @return Returns the collection. */ public RemoteCollection getCollection() { return collection; } /** * @param collection * The collection to set. */ public void setCollection(RemoteCollection collection) { this.collection = collection; } protected String getTestCollectionName() { return COLLECTION_NAME; } } |