SimpleMergeRequestManager implements MergeRequestManager { @Override public List<List<Comment>> getComments(Resource requestId) { getMergeRequest(requestId).orElseThrow( () -> new IllegalArgumentException("MergeRequest " + requestId + " does not exist")); List<List<Comment>> commentChains = new ArrayList<>(); try (RepositoryConnection conn = configProvider.getRepository().getConnection()) { TupleQuery query = conn.prepareTupleQuery(GET_COMMENT_CHAINS); query.setBinding("mergeRequest", requestId); query.evaluate().forEach(bindings -> { bindings.getValue("parent").ifPresent(parent -> { List<String> chain = new ArrayList<String>(Arrays.asList( Bindings.requiredLiteral(bindings, "chain").stringValue().split(" "))); chain.add(0, parent.stringValue()); chain.remove(""); commentChains.add(chain.stream().map(vf::createIRI) .map(iri -> getComment(iri).orElseThrow(() -> new IllegalStateException("Comment " + iri + " does not exist."))) .collect(Collectors.toList())); }); }); } return commentChains; }  @Override List<MergeRequest> getMergeRequests(MergeRequestFilterParams params); @Override List<MergeRequest> getMergeRequests(MergeRequestFilterParams params, RepositoryConnection conn); @Override MergeRequest createMergeRequest(MergeRequestConfig config, Resource localCatalog); @Override MergeRequest createMergeRequest(MergeRequestConfig config, Resource localCatalog,
                                           RepositoryConnection conn); @Override void addMergeRequest(MergeRequest request); @Override void addMergeRequest(MergeRequest request, RepositoryConnection conn); @Override Optional<MergeRequest> getMergeRequest(Resource requestId); @Override Optional<MergeRequest> getMergeRequest(Resource requestId, RepositoryConnection conn); @Override void updateMergeRequest(Resource requestId, MergeRequest request); @Override void updateMergeRequest(Resource requestId, MergeRequest request, RepositoryConnection conn); @Override void deleteMergeRequest(Resource requestId); @Override void deleteMergeRequest(Resource requestId, RepositoryConnection conn); @Override void acceptMergeRequest(Resource requestId, User user); @Override void acceptMergeRequest(Resource requestId, User user,  RepositoryConnection conn); @Override void deleteMergeRequestsWithRecordId(Resource recordId); @Override void deleteMergeRequestsWithRecordId(Resource recordId, RepositoryConnection conn); @Override void cleanMergeRequests(Resource recordId, Resource branchId); @Override void cleanMergeRequests(Resource recordId, Resource branchId, RepositoryConnection conn); @Override Comment createComment(Resource requestId, User user, String commentStr); @Override Comment createComment(Resource requestId, User user, String commentStr, Resource parentCommentId); @Override List<List<Comment>> getComments(Resource requestId); @Override Optional<Comment> getComment(Resource commentId); @Override Optional<Comment> getComment(Resource commentId, RepositoryConnection conn); @Override void updateComment(Resource commentId, Comment comment); @Override void deleteComment(Resource commentId); @Override void deleteCommentsWithRequestId(Resource requestId);  }
@Test public void getCommentsTest() { List<List<Comment>> comments = manager.getComments(request1.getResource()); assertEquals(3, comments.size()); String firstThreadTime = comments.get(0).get(0).getProperty(VALUE_FACTORY.createIRI(_Thing.issued_IRI)).get().stringValue(); String secondThreadTime = comments.get(1).get(0).getProperty(VALUE_FACTORY.createIRI(_Thing.issued_IRI)).get().stringValue(); assertTrue(OffsetDateTime.parse(firstThreadTime).isBefore(OffsetDateTime.parse(secondThreadTime))); }
@Test public void getCommentsDoesNotExistTest() { thrown.expect(IllegalArgumentException.class); manager.getComments(DOES_NOT_EXIST_IRI); }
@Test public void getCommentsWithNoCommentsOnRequestTest() { List<List<Comment>> comments = manager.getComments(request5.getResource()); assertEquals(0, comments.size()); }