final XmldbURI src = XmldbURI.create("/db/test/source");
final XmldbURI dest = XmldbURI.create("/db/test");
final XmldbURI newName = XmldbURI.create("dest");
final Collection srcCollection = EasyMock.createStrictMock(Collection.class);
final Permission srcPermissions = EasyMock.createStrictMock(Permission.class);
final DocumentImpl srcSubDocument = EasyMock.createStrictMock(DocumentImpl.class);
final Permission srcSubDocumentPermissions = EasyMock.createStrictMock(Permission.class);
final Collection destCollection = EasyMock.createStrictMock(Collection.class);
final Permission destPermissions = EasyMock.createStrictMock(Permission.class);
final Collection newDestCollection = EasyMock.createStrictMock(Collection.class);
final Permission newDestPermissions = EasyMock.createStrictMock(Permission.class);
final NativeBroker broker = EasyMock.createMockBuilder(NativeBroker.class)
.addMockedMethod("getCollection")
.addMockedMethod("getSubject")
.createStrictMock();
final Subject subject = EasyMock.createStrictMock(Subject.class);
//grant EXECUTE and READ permissions on the src
expect(srcCollection.getPermissionsNoLock()).andReturn(srcPermissions);
expect(broker.getSubject()).andReturn(subject);
expect(srcPermissions.validate(subject, Permission.EXECUTE | Permission.READ)).andReturn(true);
//grant EXECUTE and WRITE permission on the dest
expect(broker.getCollection(dest)).andReturn(destCollection);
final Capture<XmldbURI> newDestURICapture = new Capture<XmldbURI>();
expect(broker.getCollection(capture(newDestURICapture))).andReturn(newDestCollection);
expect(destCollection.getPermissionsNoLock()).andReturn(destPermissions);
expect(broker.getSubject()).andReturn(subject);
expect(destPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);
expect(newDestCollection.getPermissionsNoLock()).andReturn(newDestPermissions);
expect(broker.getSubject()).andReturn(subject);
expect(newDestPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);
//one sub-document with READ permission
expect(srcCollection.iterator(broker)).andReturn(new ArrayIterator<DocumentImpl>(srcSubDocument));
expect(srcSubDocument.getPermissions()).andReturn(srcSubDocumentPermissions);
expect(broker.getSubject()).andReturn(subject);