use of com.google.gerrit.acceptance.PushOneCommit.FILE_NAME in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnAllRevisions.
@Test
public void publishCommentsOnPushPublishesDraftsOnAllRevisions() throws Exception {
PushOneCommit.Result r = createChange();
String rev1 = r.getCommit().name();
CommentInfo c1 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment2"));
r = amendChange(r.getChangeId());
String rev2 = r.getCommit().name();
CommentInfo c3 = addDraft(r.getChangeId(), rev2, newDraft(FILE_NAME, 1, "comment3"));
assertThat(getPublishedComments(r.getChangeId())).isEmpty();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
sender.clear();
amendChange(r.getChangeId(), "refs/for/master%publish-comments");
Collection<CommentInfo> comments = getPublishedComments(r.getChangeId());
assertThat(comments.stream().map(c -> c.id)).containsExactly(c1.id, c2.id, c3.id);
assertThat(comments.stream().map(c -> c.message)).containsExactly("comment1", "comment2", "comment3");
/* Assert the correctness of the API messages */
List<ChangeMessageInfo> allMessages = getMessages(r.getChangeId());
List<String> messagesText = allMessages.stream().map(m -> m.message).collect(toList());
assertThat(messagesText).containsExactly("Uploaded patch set 1.", "Uploaded patch set 2.", "Uploaded patch set 3.", "Patch Set 3:\n\n(3 comments)").inOrder();
/* Assert the tags - PS#2 comments do not have tags, PS#3 upload is autogenerated */
List<String> messagesTags = allMessages.stream().map(m -> m.tag).collect(toList());
assertThat(messagesTags.get(2)).isEqualTo("autogenerated:gerrit:newPatchSet");
assertThat(messagesTags.get(3)).isNull();
/* Assert the correctness of the emails sent */
List<String> emailMessages = sender.getMessages().stream().map(Message::body).sorted(Comparator.comparingInt(m -> m.contains("reexamine") ? 0 : 1)).collect(toList());
assertThat(emailMessages).hasSize(2);
assertThat(emailMessages.get(0)).contains("Gerrit-MessageType: newpatchset");
assertThat(emailMessages.get(0)).contains("I'd like you to reexamine a change");
assertThat(emailMessages.get(0)).doesNotContain("Uploaded patch set 3");
assertThat(emailMessages.get(1)).contains("Gerrit-MessageType: comment");
assertThat(emailMessages.get(1)).contains("Patch Set 3:\n\n(3 comments)");
assertThat(emailMessages.get(1)).contains("PS1, Line 1:");
assertThat(emailMessages.get(1)).contains("PS2, Line 1:");
/* Assert the correctness of the NoteDb change meta commits */
List<RevCommit> commitMessages = getChangeMetaCommitsInReverseOrder(r.getChange().getId());
assertThat(commitMessages).hasSize(5);
assertThat(commitMessages.get(0).getShortMessage()).isEqualTo("Create change");
assertThat(commitMessages.get(1).getShortMessage()).isEqualTo("Create patch set 2");
assertThat(commitMessages.get(2).getShortMessage()).isEqualTo("Update patch set 2");
assertThat(commitMessages.get(3).getShortMessage()).isEqualTo("Create patch set 3");
assertThat(commitMessages.get(4).getFullMessage()).isEqualTo("Update patch set 3\n" + "\n" + "Patch Set 3:\n" + "\n" + "(3 comments)\n" + "\n" + "Patch-set: 3\n");
}
use of com.google.gerrit.acceptance.PushOneCommit.FILE_NAME in project gerrit by GerritCodeReview.
the class CommentsIT method deleteOneCommentMultipleTimes.
@Test
public void deleteOneCommentMultipleTimes() throws Exception {
PushOneCommit.Result result = createChange();
Change.Id id = result.getChange().getId();
String changeId = result.getChangeId();
String ps1 = result.getCommit().name();
CommentInput c1 = CommentsUtil.newComment(FILE_NAME, "comment 1");
CommentInput c2 = CommentsUtil.newComment(FILE_NAME, "comment 2");
CommentInput c3 = CommentsUtil.newComment(FILE_NAME, "comment 3");
CommentsUtil.addComments(gApi, changeId, ps1, c1);
CommentsUtil.addComments(gApi, changeId, ps1, c2);
CommentsUtil.addComments(gApi, changeId, ps1, c3);
List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(id.get());
assertThat(commentsBeforeDelete).hasSize(3);
Optional<CommentInfo> targetComment = commentsBeforeDelete.stream().filter(c -> c.message.equals("comment 2")).findFirst();
assertThat(targetComment).isPresent();
String uuid = targetComment.get().id;
CommentInfo oldComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
List<RevCommit> commitsBeforeDelete = getChangeMetaCommitsInReverseOrder(id);
requestScopeOperations.setApiUser(admin.id());
for (int i = 0; i < 3; i++) {
DeleteCommentInput input = new DeleteCommentInput("delete comment 2, iteration: " + i);
gApi.changes().id(changeId).revision(ps1).comment(uuid).delete(input);
}
CommentInfo updatedComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName(), "delete comment 2, iteration: 2");
assertThat(updatedComment.message).isEqualTo(expectedMsg);
oldComment.message = expectedMsg;
assertThat(updatedComment).isEqualTo(oldComment);
assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
assertThat(getChangeSortedComments(id.get())).hasSize(3);
}
Aggregations