SimpleMergeRequestManager implements MergeRequestManager { @Override public Comment createComment(Resource requestId, User user, String commentStr) { if (commentStr.length() > MAX_COMMENT_STRING_LENGTH) { throw new IllegalArgumentException("Comment string length must be less than " + MAX_COMMENT_STRING_LENGTH); } OffsetDateTime now = OffsetDateTime.now(); Comment comment = commentFactory.createNew(vf.createIRI(COMMENT_NAMESPACE + UUID.randomUUID())); comment.setProperty(vf.createLiteral(now), vf.createIRI(_Thing.issued_IRI)); comment.setProperty(vf.createLiteral(now), vf.createIRI(_Thing.modified_IRI)); comment.setProperty(user.getResource(), vf.createIRI(_Thing.creator_IRI)); comment.setProperty(vf.createLiteral(commentStr), vf.createIRI(_Thing.description_IRI)); MergeRequest mergeRequest = getMergeRequest(requestId).orElseThrow( () -> new IllegalArgumentException("MergeRequest " + requestId + " does not exist")); comment.setOnMergeRequest(mergeRequest); try (RepositoryConnection connection = configProvider.getRepository().getConnection()) { connection.add(comment.getModel(), comment.getResource()); } return comment; }  @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 createCommentTest() { String commentStr = "This is a test comment."; Comment comment = manager.createComment(request1.getResource(), user1, commentStr); assertEquals(request1.getResource(), comment.getOnMergeRequest_resource().get()); assertEquals(user1.getResource(), comment.getProperty(VALUE_FACTORY.createIRI(_Thing.creator_IRI)).get()); assertEquals(commentStr, comment.getProperty(VALUE_FACTORY.createIRI(_Thing.description_IRI)).get().stringValue()); assertTrue(comment.getProperty(VALUE_FACTORY.createIRI(_Thing.modified_IRI)).isPresent()); assertTrue(comment.getProperty(VALUE_FACTORY.createIRI(_Thing.issued_IRI)).isPresent()); assertFalse(comment.getReplyComment().isPresent()); verify(utilsService).optObject(eq(request1.getResource()), eq(mergeRequestFactory), any(RepositoryConnection.class)); }
@Test public void createCommentLargeStringTest() { thrown.expect(IllegalArgumentException.class); String commentStr = new String(new char[1100000]).replace('\0', ' '); Comment comment = manager.createComment(request1.getResource(), user1, commentStr); verify(utilsService).optObject(eq(request1.getResource()), eq(mergeRequestFactory), any(RepositoryConnection.class)); }
@Test public void createCommentRequestDoesNotExistTest() { thrown.expect(IllegalArgumentException.class); String commentStr = "This is a test comment."; manager.createComment(DOES_NOT_EXIST_IRI, user1, commentStr); verify(utilsService).optObject(eq(request1.getResource()), eq(mergeRequestFactory), any(RepositoryConnection.class)); }
@Test public void createReplyCommentRequestDoesNotExistTest() { thrown.expect(IllegalArgumentException.class); String commentStr = "This is a test comment."; manager.createComment(DOES_NOT_EXIST_IRI, user1, commentStr, commentZ.getResource()); verify(utilsService).optObject(eq(DOES_NOT_EXIST_IRI), eq(mergeRequestFactory), any(RepositoryConnection.class)); }
@Test public void createReplyCommentParentDoesNotExistTest() { thrown.expect(IllegalArgumentException.class); String commentStr = "This is a test comment."; manager.createComment(request1.getResource(), user1, commentStr, DOES_NOT_EXIST_IRI); verify(utilsService).optObject(eq(DOES_NOT_EXIST_IRI), eq(mergeRequestFactory), any(RepositoryConnection.class)); }