* permissions on the dest resource must also be writable
*/
@Test(expected=XMLDBException.class)
public void copyCollectionWithResources_destResourceExists_destResourceIsNotWritable() throws XMLDBException {
Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test1", "test1");
CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl) test.getService("CollectionManagementService", "1.0");
//create collection owned by "test1", and group "users" in /db/securityTest3
Collection source = cms.createCollection("source");
//create resource owned by "test1", and group "users" in /db/securityTest3/source
Resource resSource = source.createResource("source1.xml", XMLResource.RESOURCE_TYPE);
resSource.setContent("<test1/>");
source.storeResource(resSource);
resSource = source.createResource("source2.xml", XMLResource.RESOURCE_TYPE);
resSource.setContent("<test2/>");
source.storeResource(resSource);
//pre-create the destination and set writable by all
final Collection dest = cms.createCollection("copy-of-source");
UserManagementService ums = (UserManagementService) dest.getService("UserManagementService", "1.0");
ums.chmod(0777);
//pre-create a destination resource and set no access to group and others
Resource resDestSource1 = dest.createResource("source1.xml", XMLResource.RESOURCE_TYPE);
resDestSource1.setContent("<old/>");
dest.storeResource(resDestSource1);
ums.chmod(resDestSource1, 0700);
//as the 'test3' user copy the collection
test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test3", "test3");
cms = (CollectionManagementServiceImpl) test.getService("CollectionManagementService", "1.0");
cms.copy("/db/securityTest3/source", "/db/securityTest3", "copy-of-source");
final Collection copyOfSource = test.getChildCollection("copy-of-source");
assertNotNull(copyOfSource);
assertEquals(2, copyOfSource.listResources().length);