Source:
protected void testCopyFolderContainingACollection(int nbMembers) throws InterruptedException { List<DocumentModel> files = new ArrayList<DocumentModel>(); testWorkspace = session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace"); testWorkspace = session.createDocument(testWorkspace); DocumentModel folder = session.createDocumentModel(testWorkspace.getPathAsString(), TEST_FOLDER, "Folder"); folder = session.createDocument(folder); DocumentModel memberFolder = session.createDocumentModel(folder.getPathAsString(), "MemberFolder", "Folder"); memberFolder = session.createDocument(memberFolder); for (int i = 1; i <= nbMembers; i++) { DocumentModel testFile = session.createDocumentModel(memberFolder.getPath().toString(), TEST_FILE_NAME + i, "File"); testFile = session.createDocument(testFile); files.add(testFile); } DocumentModel collectionInFolder = session.createDocumentModel(folder.getPathAsString(), TEST_COLLECTION_IN_FOLDER, CollectionConstants.COLLECTION_TYPE); collectionInFolder = session.createDocument(collectionInFolder); session.save(); collectionManager.addToCollection(collectionInFolder, files, session); DocumentModel copiedFolder = session.copy(folder.getRef(), testWorkspace.getRef(), TEST_FOLDER + "_BIS"); awaitCollectionWorks(); final String copiedCollectionPath = copiedFolder.getPathAsString() + "/" + TEST_COLLECTION_IN_FOLDER; PathRef copiedCollectionPathRef = new PathRef(copiedCollectionPath); DocumentModel copiedCollection = session.getDocument(copiedCollectionPathRef); final String copiedCollectionId = copiedCollection.getId(); Collection copiedCollectionAdapter = copiedCollection.getAdapter(Collection.class); for (DocumentModel file : files) { assertTrue(copiedCollectionAdapter.getCollectedDocumentIds().contains(file.getId())); CollectionMember collectionMemberAdapter = session.getDocument(file.getRef()) .getAdapter(CollectionMember.class); assertTrue(collectionMemberAdapter.getCollectionIds().contains(copiedCollectionId)); } }

Target:
protected void testCopyFolderContainingACollection(int nbMembers) throws InterruptedException { List<DocumentModel> files = new ArrayList<DocumentModel>(); testWorkspace = session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace"); testWorkspace = session.createDocument(testWorkspace); DocumentModel folder = session.createDocumentModel(testWorkspace.getPathAsString(), TEST_FOLDER, "Folder"); folder = session.createDocument(folder); DocumentModel memberFolder = session.createDocumentModel(folder.getPathAsString(), "MemberFolder", "Folder"); memberFolder = session.createDocument(memberFolder); for (int i = 1; i <= nbMembers; i++) { DocumentModel testFile = session.createDocumentModel(memberFolder.getPath().toString(), TEST_FILE_NAME + i, "File"); testFile = session.createDocument(testFile); files.add(testFile); } DocumentModel collectionInFolder = session.createDocumentModel(folder.getPathAsString(), TEST_COLLECTION_IN_FOLDER, CollectionConstants.COLLECTION_TYPE); collectionInFolder = session.createDocument(collectionInFolder); session.save(); collectionManager.addToCollection(collectionInFolder, files, session); DocumentModel copiedFolder = session.copy(folder.getRef(), testWorkspace.getRef(), TEST_FOLDER + "_BIS"); awaitCollectionWorks(); String copiedCollectionPath = copiedFolder.getPathAsString() + "/" + TEST_COLLECTION_IN_FOLDER; PathRef copiedCollectionPathRef = new PathRef(copiedCollectionPath); DocumentModel copiedCollection = session.getDocument(copiedCollectionPathRef); final String copiedCollectionId = copiedCollection.getId(); Collection copiedCollectionAdapter = copiedCollection.getAdapter(Collection.class); for (DocumentModel file : files) { assertTrue(copiedCollectionAdapter.getCollectedDocumentIds().contains(file.getId())); CollectionMember collectionMemberAdapter = session.getDocument(file.getRef()) .getAdapter(CollectionMember.class); assertTrue(collectionMemberAdapter.getCollectionIds().contains(copiedCollectionId)); } }