SimpleMergeRequestManager implements MergeRequestManager { @Override public void updateComment(Resource commentId, Comment comment) { try (RepositoryConnection conn = configProvider.getRepository().getConnection()) { Optional<com.mobi.rdf.api.Value> description = comment.getProperty(vf.createIRI(_Thing.description_IRI)); if (description.isPresent() && description.get().stringValue().length() > MAX_COMMENT_STRING_LENGTH) { throw new IllegalArgumentException("Comment string length must be less than " + MAX_COMMENT_STRING_LENGTH); } if (!description.isPresent() || StringUtils.isBlank(description.get().stringValue())) { throw new IllegalArgumentException("Comment string is required"); } OffsetDateTime now = OffsetDateTime.now(); comment.setProperty(vf.createLiteral(now), vf.createIRI(_Thing.modified_IRI)); catalogUtils.validateResource(commentId, commentFactory.getTypeIRI(), conn); catalogUtils.updateObject(comment, conn); } }  @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 updateCommentTest() { Comment comment1Update = commentFactory.createNew(VALUE_FACTORY.createIRI("http: comment1Update.setProperty(VALUE_FACTORY.createLiteral("Comment1Update"), VALUE_FACTORY.createIRI(_Thing.description_IRI)); manager.updateComment(comment1Update.getResource(), comment1Update); verify(utilsService).validateResource(eq(comment1Update.getResource()), eq(commentFactory.getTypeIRI()), any(RepositoryConnection.class)); verify(utilsService).updateObject(eq(comment1Update), any(RepositoryConnection.class)); }
@Test public void updateCommentTooLargeTest() { thrown.expect(IllegalArgumentException.class); Comment comment1Update = commentFactory.createNew(VALUE_FACTORY.createIRI("http: comment1Update.setProperty(VALUE_FACTORY.createLiteral(StringUtils.repeat("*", 2000000)), VALUE_FACTORY.createIRI(_Thing.description_IRI)); manager.updateComment(comment1Update.getResource(), comment1Update); verify(utilsService, never()).validateResource(eq(comment1Update.getResource()), eq(commentFactory.getTypeIRI()), any(RepositoryConnection.class)); verify(utilsService, never()).updateObject(eq(comment1Update), any(RepositoryConnection.class)); }
@Test public void updateCommentEmptyDescriptionTest() { thrown.expect(IllegalArgumentException.class); Comment comment1Update = commentFactory.createNew(VALUE_FACTORY.createIRI("http: comment1Update.setProperty(VALUE_FACTORY.createLiteral(""), VALUE_FACTORY.createIRI(_Thing.description_IRI)); manager.updateComment(comment1Update.getResource(), comment1Update); verify(utilsService, never()).validateResource(eq(comment1Update.getResource()), eq(commentFactory.getTypeIRI()), any(RepositoryConnection.class)); verify(utilsService, never()).updateObject(eq(comment1Update), any(RepositoryConnection.class)); }
@Test public void updateCommentNoDescriptionTest() { thrown.expect(IllegalArgumentException.class); Comment comment1Update = commentFactory.createNew(VALUE_FACTORY.createIRI("http: manager.updateComment(comment1Update.getResource(), comment1Update); verify(utilsService, never()).validateResource(eq(comment1Update.getResource()), eq(commentFactory.getTypeIRI()), any(RepositoryConnection.class)); verify(utilsService, never()).updateObject(eq(comment1Update), any(RepositoryConnection.class)); }
@Test public void updateCommentDoesNotExistTest() { thrown.expect(IllegalArgumentException.class); Comment commentDoesNotExist = commentFactory.createNew(DOES_NOT_EXIST_IRI); commentDoesNotExist.setProperty(VALUE_FACTORY.createLiteral("commentDoesNotExist"), VALUE_FACTORY.createIRI(_Thing.description_IRI)); manager.updateComment(DOES_NOT_EXIST_IRI, commentDoesNotExist); verify(utilsService).validateResource(eq(commentDoesNotExist.getResource()), eq(commentFactory.getTypeIRI()), any(RepositoryConnection.class)); verify(utilsService).updateObject(eq(commentDoesNotExist), any(RepositoryConnection.class)); }
@Test public void updateCommentTimeTest() { Optional<Value> preUpdateTime = comment1.getProperty(VALUE_FACTORY.createIRI(_Thing.modified_IRI)); manager.updateComment(comment1.getResource(), comment1); Optional<Value> postUpdateTime = comment1.getProperty(VALUE_FACTORY.createIRI(_Thing.modified_IRI)); assertNotEquals(preUpdateTime.get().stringValue(), postUpdateTime.get().stringValue()); verify(utilsService).validateResource(eq(comment1.getResource()), eq(commentFactory.getTypeIRI()), any(RepositoryConnection.class)); verify(utilsService).updateObject(eq(comment1), any(RepositoryConnection.class)); }