use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentsIT method publishPartialDraftsForAnotherUserIsNotAllowed.
@Test
public void publishPartialDraftsForAnotherUserIsNotAllowed() throws Exception {
pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "initial content\n").to("refs/heads/master");
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "File content in PS1\n").to("refs/for/master");
// Add drafts with user scope
requestScopeOperations.setApiUser(accountCreator.user1().id());
CommentInfo draft = addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "comment 1"));
ReviewInput reviewInput = createReviewInput(DraftHandling.PUBLISH_ALL_REVISIONS, "review message", /* draftIdsToPublish= */
ImmutableList.of(draft.id));
// Try to publish the drafts using user2 scope
requestScopeOperations.setApiUser(accountCreator.user2().id());
Exception error = assertThrows(BadRequestException.class, () -> gApi.changes().id(r1.getChangeId()).current().review(reviewInput));
assertThat(error).hasMessageThat().isEqualTo(String.format("Non-existing draft IDs: [%s]", draft.id));
// Request will succeed if done by user
requestScopeOperations.setApiUser(accountCreator.user1().id());
gApi.changes().id(r1.getChangeId()).current().review(reviewInput);
assertThat(gApi.changes().id(r1.getChangeId()).commentsRequest().getAsList().stream().map(c -> c.id)).containsExactly(draft.id);
assertThat(gApi.changes().id(r1.getChangeId()).draftsRequest().getAsList()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class PostReviewIT method onPostReviewExtensionThatDoesntExtendTheChangeMessage.
@Test
public void onPostReviewExtensionThatDoesntExtendTheChangeMessage() throws Exception {
PushOneCommit.Result r = createChange();
TestOnPostReview testOnPostReview = new TestOnPostReview(/* message= */
null);
try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview)) {
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
gApi.changes().id(r.getChangeId()).current().review(input);
Collection<ChangeMessageInfo> messages = gApi.changes().id(r.getChangeId()).get().messages;
assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1: Code-Review+1");
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class PostReviewIT method validateDrafts_inlineVsFileComments_allOK.
@Test
public void validateDrafts_inlineVsFileComments_allOK() throws Exception {
PushOneCommit.Result r = createChange();
DraftInput draftInline = testCommentHelper.newDraft(r.getChange().currentFilePaths().get(0), Side.REVISION, 1, COMMENT_TEXT);
testCommentHelper.addDraft(r.getChangeId(), r.getCommit().getName(), draftInline);
DraftInput draftFile = testCommentHelper.newDraft(COMMENT_TEXT);
testCommentHelper.addDraft(r.getChangeId(), r.getCommit().getName(), draftFile);
assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).isEmpty();
when(mockCommentValidator.validateComments(any(), captor.capture())).thenReturn(ImmutableList.of());
ReviewInput input = new ReviewInput().message(COMMENT_TEXT);
input.drafts = DraftHandling.PUBLISH;
gApi.changes().id(r.getChangeId()).current().review(input);
assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).hasSize(2);
assertValidatorCalledWith(CHANGE_MESSAGE_FOR_VALIDATION, CommentForValidation.create(CommentForValidation.CommentSource.HUMAN, CommentForValidation.CommentType.INLINE_COMMENT, draftInline.message, draftInline.message.length()), CommentForValidation.create(CommentForValidation.CommentSource.HUMAN, CommentForValidation.CommentType.FILE_COMMENT, draftFile.message, draftFile.message.length()));
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class PostReviewIT method votingTheSameVoteSecondTimeDoesNotFireOnCommentAdded.
@Test
public void votingTheSameVoteSecondTimeDoesNotFireOnCommentAdded() throws Exception {
PushOneCommit.Result r = createChange();
// Add a new vote.
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
assertThat(r.getChange().approvals().values()).hasSize(1);
TestListener testListener = new TestListener();
try (Registration registration = extensionRegistry.newRegistration().add(testListener)) {
// Post without changing the vote.
input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
// Event not fired.
assertThat(testListener.lastCommentAddedEvent).isNull();
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class PostReviewIT method votingTheSameVoteSecondTime.
@Test
public void votingTheSameVoteSecondTime() throws Exception {
PushOneCommit.Result r = createChange();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
sender.clear();
// Add a new vote.
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
assertThat(r.getChange().approvals().values()).hasSize(1);
// Post without changing the vote.
input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
// Second vote replaced the original vote, so still only one vote.
assertThat(r.getChange().approvals().values()).hasSize(1);
List<ChangeMessageInfo> changeMessages = gApi.changes().id(r.getChangeId()).messages();
// Only the last change message is about Code-Review+2
assertThat(Iterables.getLast(changeMessages).message).isEqualTo("Patch Set 1: Code-Review+2");
changeMessages.remove(changeMessages.size() - 1);
assertThat(Iterables.getLast(changeMessages).message).isNotEqualTo("Patch Set 1: Code-Review+2");
// Only one email is about Code-Review +2 was sent.
assertThat(Iterables.getOnlyElement(sender.getMessages()).body()).contains("Patch Set 1: Code-Review+2");
}
Aggregations