Source:
public void setUp() { DocumentModel doc = session.createDocumentModel("/", "myDoc", "File"); docModel = session.createDocument(doc); session.save(); Comment commentToCreate = new CommentImpl(); commentToCreate.setParentId(docModel.getId()); commentToCreate.setAuthor(session.getPrincipal().getName()); commentToCreate.setText("main comment"); comment = commentManager.createComment(session, commentToCreate); replies = new ArrayList<>(); Instant date = Instant.now(); Comment firstReply = new CommentImpl(); firstReply.setParentId(comment.getId()); firstReply.setAuthor(session.getPrincipal().getName()); firstReply.setText("first reply"); firstReply.setCreationDate(date); Comment secondReply = new CommentImpl(); secondReply.setParentId(comment.getId()); secondReply.setAuthor(session.getPrincipal().getName()); secondReply.setText("second reply"); secondReply.setCreationDate(date.plusSeconds(1)); Comment thirdReply = new CommentImpl(); thirdReply.setParentId(comment.getId()); thirdReply.setAuthor(session.getPrincipal().getName()); thirdReply.setText("third reply"); thirdReply.setCreationDate(date.plusSeconds(2)); ((CommentImpl) thirdReply).setOrigin("origin"); ((CommentImpl) thirdReply).setEntity("entity"); ((CommentImpl) thirdReply).setEntityId("entityId"); replies.add(commentManager.createComment(session, firstReply)); replies.add(commentManager.createComment(session, secondReply)); replies.add(commentManager.createComment(session, thirdReply)); ACPImpl acp = new ACPImpl(); ACL acl = acp.getOrCreateACL(); acl.add(new ACE("james", SecurityConstants.READ, true)); session.setACP(doc.getRef(), acp, false); session.save(); }

Target:
public void setUp() { DocumentModel doc = session.createDocumentModel("/", "myDoc", "File"); docModel = session.createDocument(doc); session.save(); Comment commentToCreate = new CommentImpl(); commentToCreate.setParentId(docModel.getId()); commentToCreate.setAuthor(session.getPrincipal().getName()); commentToCreate.setText("main comment"); comment = commentManager.createComment(session, commentToCreate); replies = new ArrayList<>(); Instant date = Instant.now(); Comment firstReply = new CommentImpl(); firstReply.setParentId(comment.getId()); firstReply.setAuthor(session.getPrincipal().getName()); firstReply.setText("first reply"); firstReply.setCreationDate(date); Comment secondReply = new CommentImpl(); secondReply.setParentId(comment.getId()); secondReply.setAuthor(session.getPrincipal().getName()); secondReply.setText("second reply"); secondReply.setCreationDate(date.plusSeconds(1)); Comment thirdReply = new CommentImpl(); thirdReply.setParentId(comment.getId()); thirdReply.setAuthor(session.getPrincipal().getName()); thirdReply.setText("third reply"); thirdReply.setCreationDate(date.plusSeconds(2)); ((CommentImpl) thirdReply).setOrigin("origin"); ((CommentImpl) thirdReply).setEntity("entity"); ((CommentImpl) thirdReply).setEntityId("entityId"); replies.add(commentManager.createComment(session, firstReply)); replies.add(commentManager.createComment(session, secondReply)); replies.add(commentManager.createComment(session, thirdReply)); ACP acp = doc.getACP(); ACL acl = acp.getOrCreateACL(); acl.add(new ACE("james", SecurityConstants.READ, true)); session.setACP(doc.getRef(), acp, false); session.save(); }