Search in sources :

Example 31 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class ReceiveCommitsCommentValidationIT method attentionSetNotUpdatedWhenNoCommentsPublished.

@Test
public void attentionSetNotUpdatedWhenNoCommentsPublished() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    gApi.changes().id(changeId).addReviewer(user.email());
    gApi.changes().id(changeId).attention(user.email()).remove(new AttentionSetInput("removed"));
    ImmutableSet<AttentionSetUpdate> attentionSet = result.getChange().attentionSet();
    Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
    assertThat(attentionSet).isEqualTo(amendResult.getChange().attentionSet());
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 32 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class ReceiveCommitsCommentValidationIT method publishCommentsAddsAllUsersInCommentThread.

@Test
public void publishCommentsAddsAllUsersInCommentThread() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    String revId = result.getCommit().getName();
    requestScopeOperations.setApiUser(user.id());
    DraftInput comment = testCommentHelper.newDraft(COMMENT_TEXT);
    testCommentHelper.addDraft(changeId, revId, comment);
    ReviewInput reviewInput = new ReviewInput().blockAutomaticAttentionSetRules();
    reviewInput.drafts = ReviewInput.DraftHandling.PUBLISH;
    change(result).current().review(reviewInput);
    requestScopeOperations.setApiUser(admin.id());
    comment = testCommentHelper.newDraft(COMMENT_TEXT, Iterables.getOnlyElement(gApi.changes().id(changeId).current().commentsAsList()).id);
    testCommentHelper.addDraft(changeId, revId, comment);
    Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
    AttentionSetUpdate attentionSetUpdate = Iterables.getOnlyElement(amendResult.getChange().attentionSet());
    assertThat(attentionSetUpdate.account()).isEqualTo(user.id());
    assertThat(attentionSetUpdate.reason()).isEqualTo("Someone else replied on a comment you posted");
    assertThat(attentionSetUpdate.operation()).isEqualTo(AttentionSetUpdate.Operation.ADD);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 33 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class ReceiveCommitsCommentValidationIT method emailsSentOnPublishCommentsHaveDifferentMessageIds.

@Test
public void emailsSentOnPublishCommentsHaveDifferentMessageIds() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    gApi.changes().id(changeId).addReviewer(user.email());
    sender.clear();
    String revId = result.getCommit().getName();
    DraftInput comment = testCommentHelper.newDraft(COMMENT_TEXT);
    testCommentHelper.addDraft(changeId, revId, comment);
    amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
    List<FakeEmailSender.Message> messages = sender.getMessages();
    assertThat(messages).hasSize(2);
    FakeEmailSender.Message newPatchsetMessage = messages.get(0);
    assertThat(newPatchsetMessage.body()).contains("new patch set");
    assertThat(newPatchsetMessage.headers().get("Message-ID").toString()).doesNotContain("EmailReviewComments");
    FakeEmailSender.Message newCommentsMessage = messages.get(1);
    assertThat(newCommentsMessage.body()).contains("has posted comments on this change");
    assertThat(newCommentsMessage.headers().get("Message-ID").toString()).contains("EmailReviewComments");
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 34 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class ReceiveCommitsCommentValidationIT method limitCumulativeCommentSize.

@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "500")
public void limitCumulativeCommentSize() throws Exception {
    when(mockCommentValidator.validateComments(any(), any())).thenReturn(ImmutableList.of());
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    String revId = result.getCommit().getName();
    String filePath = result.getChange().currentFilePaths().get(0);
    String commentText400Bytes = new String(new char[400]).replace("\0", "x");
    DraftInput draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, commentText400Bytes);
    testCommentHelper.addDraft(changeId, revId, draftInline);
    amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
    assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).hasSize(1);
    draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, commentText400Bytes);
    testCommentHelper.addDraft(changeId, revId, draftInline);
    Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
    assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).hasSize(1);
    amendResult.assertMessage("exceeding maximum cumulative size of comments");
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Result(com.google.gerrit.acceptance.PushOneCommit.Result) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 35 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class ReceiveCommitsCommentValidationIT method validateComments_commentRejected.

@Test
public void validateComments_commentRejected() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    String revId = result.getCommit().getName();
    when(mockCommentValidator.validateComments(CommentValidationContext.create(result.getChange().getId().get(), result.getChange().project().get(), result.getChange().change().getDest().branch()), ImmutableList.of(COMMENT_FOR_VALIDATION))).thenReturn(ImmutableList.of(COMMENT_FOR_VALIDATION.failValidation("Oh no!")));
    DraftInput comment = testCommentHelper.newDraft(COMMENT_TEXT);
    testCommentHelper.addDraft(changeId, revId, comment);
    assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).isEmpty();
    Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
    amendResult.assertOkStatus();
    amendResult.assertMessage("Comment validation failure:");
    assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).isEmpty();
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Result (com.google.gerrit.acceptance.PushOneCommit.Result)75 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)59 Test (org.junit.Test)59 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)28 RestResponse (com.google.gerrit.acceptance.RestResponse)17 ObjectId (org.eclipse.jgit.lib.ObjectId)11 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)9 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)8 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)7 BasicHeader (org.apache.http.message.BasicHeader)7 Request (org.apache.http.client.fluent.Request)6 FileInfo (com.google.gerrit.extensions.common.FileInfo)5 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)4 TagInput (com.google.gerrit.extensions.api.projects.TagInput)4 Project (com.google.gerrit.entities.Project)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)3 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)3 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Before (org.junit.Before)3