use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class PostReviewIT method validateCommentsInInput_commentRejected.
@Test
public void validateCommentsInInput_commentRejected() throws Exception {
PushOneCommit.Result r = createChange();
when(mockCommentValidator.validateComments(eq(contextFor(r)), captor.capture())).thenReturn(ImmutableList.of(FILE_COMMENT_FOR_VALIDATION.failValidation("Oh no!")));
ReviewInput input = new ReviewInput().message(COMMENT_TEXT);
CommentInput comment = newComment(r.getChange().currentFilePaths().get(0));
comment.updated = new Timestamp(0);
input.comments = ImmutableMap.of(comment.path, ImmutableList.of(comment));
assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).isEmpty();
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> gApi.changes().id(r.getChangeId()).current().review(input));
assertValidatorCalledWith(CHANGE_MESSAGE_FOR_VALIDATION, FILE_COMMENT_FOR_VALIDATION);
assertThat(badRequestException.getCause()).isInstanceOf(CommentsRejectedException.class);
assertThat(Iterables.getOnlyElement(((CommentsRejectedException) badRequestException.getCause()).getCommentValidationFailures()).getComment().getText()).isEqualTo(COMMENT_TEXT);
assertThat(badRequestException.getCause()).hasMessageThat().contains("Oh no!");
assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class RevisionIT method commentOnNonExistingFile.
@Test
public void commentOnNonExistingFile() throws Exception {
PushOneCommit.Result r1 = createChange();
PushOneCommit.Result r2 = updateChange(r1, "new content");
CommentInput in = new CommentInput();
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = "non-existing.txt";
ReviewInput reviewInput = new ReviewInput();
Map<String, List<CommentInput>> comments = new HashMap<>();
comments.put("non-existing.txt", Collections.singletonList(in));
reviewInput.comments = comments;
reviewInput.message = "comment test";
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(r2.getChangeId()).revision(1).review(reviewInput));
assertThat(thrown).hasMessageThat().contains(String.format("not found in revision %d,1", r2.getChange().change().getId().get()));
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class SubmitWithStickyApprovalDiffIT method autoGeneratedPostSubmitDiffIsPartOfTheCommentSizeLimit.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "10k")
public void autoGeneratedPostSubmitDiffIsPartOfTheCommentSizeLimit() throws Exception {
Change.Id changeId = changeOperations.newChange().project(project).file("file").content("content").create();
gApi.changes().id(changeId.get()).current().review(ReviewInput.approve());
String content = new String(new char[800]).replace("\0", "a");
changeOperations.change(changeId).newPatchset().file("file").content(content).create();
// Post a submit diff that is almost the cumulativeCommentSizeLimit
gApi.changes().id(changeId.get()).current().submit();
assertThat(Iterables.getLast(gApi.changes().id(changeId.get()).messages()).message).doesNotContain("The diff is too large to show. Please review the diff");
// unrelated comment and change message posting doesn't work, since the post submit diff is
// counted towards the cumulativeCommentSizeLimit for unrelated follow-up comments.
// 800 + 9500 > 10k.
String message = new String(new char[9500]).replace("\0", "a");
ReviewInput reviewInput = new ReviewInput().message(message);
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.path = "file";
reviewInput.comments = ImmutableMap.of("file", ImmutableList.of(commentInput));
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId.get()).current().review(reviewInput));
assertThat(thrown).hasMessageThat().contains("Exceeding maximum cumulative size of comments and change messages");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method deletedCommentsAreResolved.
@Test
public void deletedCommentsAreResolved() throws Exception {
requestScopeOperations.setApiUser(admin.id());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String commentMessage = "to be deleted";
CommentInput comment = CommentsUtil.newComment(COMMIT_MSG, Side.REVISION, /*line= */
0, commentMessage, /*unresolved= */
true);
CommentsUtil.addComments(gApi, changeId, revId, comment);
Map<String, List<CommentInfo>> results = getPublishedComments(changeId, revId);
CommentInfo oldComment = Iterables.getOnlyElement(results.get(COMMIT_MSG));
DeleteCommentInput input = new DeleteCommentInput("reason");
gApi.changes().id(changeId).revision(revId).comment(oldComment.id).delete(input);
CommentInfo updatedComment = Iterables.getOnlyElement(getPublishedComments(changeId, revId).get(COMMIT_MSG));
assertThat(updatedComment.message).doesNotContain(commentMessage);
assertThat(updatedComment.unresolved).isFalse();
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method deleteCommentCannotBeAppliedByUser.
@Test
public void deleteCommentCannotBeAppliedByUser() throws Exception {
PushOneCommit.Result result = createChange();
CommentInput targetComment = CommentsUtil.addComment(gApi, result.getChangeId());
Map<String, List<CommentInfo>> commentsMap = getPublishedComments(result.getChangeId(), result.getCommit().name());
assertThat(commentsMap).hasSize(1);
assertThat(commentsMap.get(FILE_NAME)).hasSize(1);
String uuid = commentsMap.get(targetComment.path).get(0).id;
DeleteCommentInput input = new DeleteCommentInput("contains confidential information");
requestScopeOperations.setApiUser(user.id());
assertThrows(AuthException.class, () -> gApi.changes().id(result.getChangeId()).current().comment(uuid).delete(input));
}
Aggregations