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 access for all
Resource resDestSource1 = dest.createResource("source1.xml", XMLResource.RESOURCE_TYPE);
resDestSource1.setContent("<old/>");
dest.storeResource(resDestSource1);
ums.chmod(resDestSource1, 0777);
//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);
ums = (UserManagementService) copyOfSource.getService("UserManagementService", "1.0");
//permissions should NOT have changed as the dest already existed!
Permission permissions = ums.getPermissions(copyOfSource);
assertEquals("test1", permissions.getOwner().getName());
assertEquals("users", permissions.getGroup().getName());
final Resource resCopyOfSource1 = copyOfSource.getResource("source1.xml");
assertEquals("<test1/>", resCopyOfSource1.getContent().toString());
//permissions should NOT have changed as the dest resource already existed!
permissions = ums.getPermissions(resCopyOfSource1);
assertEquals("test1", permissions.getOwner().getName());
assertEquals("users", permissions.getGroup().getName());
final Resource resCopyOfSource2 = copyOfSource.getResource("source2.xml");
assertEquals("<test2/>", resCopyOfSource2.getContent().toString());
//permissions SHOULD have changed as the dest resource is did NOT exist
permissions = ums.getPermissions(resCopyOfSource2);
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
}