Search in sources :

Example 21 with com.google.gerrit.extensions.api.changes.reviewinput

use of com.google.gerrit.extensions.api.changes.reviewinput in project gerrit by GerritCodeReview.

the class PostReviewIT method commentingMakesUserCC.

@Test
public void commentingMakesUserCC() throws Exception {
    // Admin owns the change
    PushOneCommit.Result r = createChange();
    // User adds themselves and changes state
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().message("Foo bar!");
    gApi.changes().id(r.getChangeId()).current().review(input);
    Map<ReviewerState, Collection<AccountInfo>> reviewers = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers).hasSize(1);
    AccountInfo reviewer = Iterables.getOnlyElement(reviewers.get(ReviewerState.CC));
    assertThat(reviewer._accountId).isEqualTo(user.id().get());
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with com.google.gerrit.extensions.api.changes.reviewinput

use of com.google.gerrit.extensions.api.changes.reviewinput in project gerrit by GerritCodeReview.

the class PostReviewIT method validateCommentsInInput_commentCleanedUp.

@Test
public void validateCommentsInInput_commentCleanedUp() throws Exception {
    PushOneCommit.Result r = createChange();
    assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).isEmpty();
    // posting a comment which is empty after trim is a no-op, as the empty comment is dropped
    // during comment cleanup
    ReviewInput input = new ReviewInput();
    CommentInput comment = TestCommentHelper.populate(new CommentInput(), r.getChange().currentFilePaths().get(0), " ");
    comment.updated = new Timestamp(0);
    input.comments = ImmutableMap.of(comment.path, ImmutableList.of(comment));
    gApi.changes().id(r.getChangeId()).current().review(input);
    assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).isEmpty();
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with com.google.gerrit.extensions.api.changes.reviewinput

use of com.google.gerrit.extensions.api.changes.reviewinput in project gerrit by GerritCodeReview.

the class PostReviewIT method validateCommentsInChangeMessage_messageRejected.

@Test
public void validateCommentsInChangeMessage_messageRejected() throws Exception {
    PushOneCommit.Result r = createChange();
    when(mockCommentValidator.validateComments(eq(contextFor(r)), captor.capture())).thenReturn(ImmutableList.of(CHANGE_MESSAGE_FOR_VALIDATION.failValidation("Oh no!")));
    ReviewInput input = new ReviewInput().message(COMMENT_TEXT);
    assertThat(gApi.changes().id(r.getChangeId()).get().messages).hasSize(// From the initial commit.
    1);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> gApi.changes().id(r.getChangeId()).current().review(input));
    assertValidatorCalledWith(CHANGE_MESSAGE_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(gApi.changes().id(r.getChangeId()).get().messages).hasSize(// Unchanged from before.
    1);
    ChangeMessageInfo message = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
    assertThat(message.message).doesNotContain(COMMENT_TEXT);
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) 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 24 with com.google.gerrit.extensions.api.changes.reviewinput

use of com.google.gerrit.extensions.api.changes.reviewinput in project gerrit by GerritCodeReview.

the class PostReviewIT method restrictNumberOfComments.

@Test
@GerritConfig(name = "change.maxComments", value = "7")
public void restrictNumberOfComments() throws Exception {
    when(mockCommentValidator.validateComments(any(), any())).thenReturn(ImmutableList.of());
    PushOneCommit.Result r = createChange();
    String filePath = r.getChange().currentFilePaths().get(0);
    CommentInput commentInput = new CommentInput();
    commentInput.line = 1;
    commentInput.message = "foo";
    commentInput.path = filePath;
    RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(filePath);
    ReviewInput reviewInput = new ReviewInput();
    reviewInput.comments = ImmutableMap.of(filePath, ImmutableList.of(commentInput));
    reviewInput.robotComments = ImmutableMap.of(filePath, ImmutableList.of(robotCommentInput));
    gApi.changes().id(r.getChangeId()).current().review(reviewInput);
    // Counting change messages plus comments we now have 4.
    // reviewInput still has both a user and a robot comment (and deduplication is false). We also
    // create a draft, and there's the change message, so that in total there would be 8 comments.
    // The limit is set to 7, so this verifies that all new comments are considered.
    DraftInput draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, "a draft");
    testCommentHelper.addDraft(r.getChangeId(), r.getPatchSetId().getId(), draftInline);
    reviewInput.drafts = DraftHandling.PUBLISH;
    reviewInput.omitDuplicateComments = false;
    BadRequestException exception = assertThrows(BadRequestException.class, () -> gApi.changes().id(r.getChangeId()).current().review(reviewInput));
    assertThat(exception).hasMessageThat().contains("Exceeding maximum number of comments: 4 (existing) + 4 (new) > 7");
    assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).hasSize(1);
    assertThat(getRobotComments(r.getChangeId())).hasSize(1);
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with com.google.gerrit.extensions.api.changes.reviewinput

use of com.google.gerrit.extensions.api.changes.reviewinput in project gerrit by GerritCodeReview.

the class RevertIT method revertSubmissionPreservesReviewersAndCcs.

@Test
public void revertSubmissionPreservesReviewersAndCcs() throws Exception {
    String change = createChange("first change", "a.txt", "message").getChangeId();
    ReviewInput in = ReviewInput.approve();
    in.reviewer(user.email());
    in.reviewer(accountCreator.user2().email(), ReviewerState.CC, true);
    // Add user as reviewer that will create the revert
    in.reviewer(accountCreator.admin2().email());
    gApi.changes().id(change).current().review(in);
    gApi.changes().id(change).current().submit();
    // expect both the original reviewers and CCs to be preserved
    // original owner should be added as reviewer, user requesting the revert (new owner) removed
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    Map<ReviewerState, Collection<AccountInfo>> result = getChangeApis(gApi.changes().id(change).revertSubmission()).get(0).get().reviewers;
    assertThat(result).containsKey(ReviewerState.REVIEWER);
    List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
    assertThat(result).containsKey(ReviewerState.CC);
    List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
    assertThat(ccs).containsExactly(accountCreator.user2().id().get());
    assertThat(reviewers).containsExactly(user.id().get(), admin.id().get());
}
Also used : TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ArrayList(java.util.ArrayList) PureRevertInfo(com.google.gerrit.extensions.common.PureRevertInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) TestRepository(org.eclipse.jgit.junit.TestRepository) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Test(org.junit.Test) ProjectState(com.google.gerrit.extensions.client.ProjectState) Truth.assertThat(com.google.common.truth.Truth.assertThat) PermissionDeniedException(com.google.gerrit.server.permissions.PermissionDeniedException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Project(com.google.gerrit.entities.Project) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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