Search in sources :

Example 16 with ReviewInput

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();
}
Also used : CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with ReviewInput

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");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 18 with ReviewInput

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()));
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 19 with ReviewInput

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();
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with ReviewInput

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");
}
Also used : ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)254 Test (org.junit.Test)217 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)198 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)178 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)47 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)35 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)30 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)26 List (java.util.List)25 Collectors.toList (java.util.stream.Collectors.toList)24 ImmutableList (com.google.common.collect.ImmutableList)23 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)23 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)22 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)21 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)20 ArrayList (java.util.ArrayList)20 TestAccount (com.google.gerrit.acceptance.TestAccount)18 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)18 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)18