//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("<test/>");
source.storeResource(resSource);
resSource = source.createResource("source2.xml", XMLResource.RESOURCE_TYPE);
resSource.setContent("<test/>");
source.storeResource(resSource);
//create sub-collection "sub" owned by "test1", and group "users" in /db/securityTest3/source
CollectionManagementService cms1 = (CollectionManagementServiceImpl)source.getService("CollectionManagementService", "1.0");
Collection sub = cms1.createCollection("sub");
//create resource owned by "test1", and group "users" in /db/securityTest3/source/sub1
Resource resSub = sub.createResource("sub1.xml", XMLResource.RESOURCE_TYPE);
resSub.setContent("<test-sub/>");
sub.storeResource(resSub);
//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);
final Collection copyOfSub = copyOfSource.getChildCollection("sub");
assertNotNull(copyOfSub);
assertEquals(1, copyOfSub.listResources().length);
//collection should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source
UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
Permission permissions = ums.getPermissions(copyOfSource);
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
//resource in collection should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source/source1.xml
ums = (UserManagementService) copyOfSource.getService("UserManagementService", "1.0");
final Resource resCopyOfSource1 = copyOfSource.getResource("source1.xml");
permissions = ums.getPermissions(resCopyOfSource1);
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
//resource in collection should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source/source2.xml
final Resource resCopyOfSource2 = copyOfSource.getResource("source2.xml");
permissions = ums.getPermissions(resCopyOfSource2);
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
//sub-collection should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source/sub
ums = (UserManagementService)copyOfSub.getService("UserManagementService", "1.0");
permissions = ums.getPermissions(copyOfSub);
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
//sub-collection/resource should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source/sub/sub1.xml
final Resource resCopyOfSub1 = copyOfSub.getResource("sub1.xml");
permissions = ums.getPermissions(resCopyOfSub1);
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
}