Search in sources :

Example 31 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method removeCC.

@Test
public void removeCC() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    // Add a cc
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.state = CC;
    reviewerInput.reviewer = user.id().toString();
    gApi.changes().id(changeId).addReviewer(reviewerInput);
    // Remove a cc
    sender.clear();
    gApi.changes().id(changeId).reviewer(user.id().toString()).remove();
    assertThat(gApi.changes().id(changeId).get().reviewers).isEmpty();
    // Make sure the email for removing a cc is correct.
    assertThat(sender.getMessages()).hasSize(1);
    Message message = sender.getMessages().get(0);
    assertThat(message.body()).contains("Removed cc " + user.getNameEmail() + ".");
    // Make sure the change message for removing a reviewer is correct.
    assertThat(Iterables.getLast(gApi.changes().id(changeId).messages()).message).isEqualTo("Removed cc " + user.getNameEmail() + ".");
    ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
    assertThat(changeMessageInfo.message).isEqualTo("Removed cc " + AccountTemplateUtil.getAccountTemplate(user.id()) + ".");
    assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 32 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method implicitlyAddReviewerOnVotingReview.

@Test
public void implicitlyAddReviewerOnVotingReview() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.recommend().message("LGTM"));
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.reviewers.get(REVIEWER).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id().get());
    // Further test: remove the vote, then comment again. The user should be
    // implicitly re-added to the ReviewerSet, as a CC.
    requestScopeOperations.setApiUser(admin.id());
    gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).remove();
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.reviewers.values()).isEmpty();
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(new ReviewInput().message("hi"));
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.reviewers.get(CC).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id().get());
}
Also used : NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) MERGED(com.google.gerrit.extensions.client.ChangeStatus.MERGED) CHANGE_OWNER(com.google.gerrit.server.group.SystemGroupBackend.CHANGE_OWNER) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TestProjectUpdate.blockLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.blockLabel) PROJECT_OWNERS(com.google.gerrit.server.group.SystemGroupBackend.PROJECT_OWNERS) Map(java.util.Map) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) ThrowableSubject(com.google.common.truth.ThrowableSubject) EnumSet(java.util.EnumSet) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) DeleteVoteInput(com.google.gerrit.extensions.api.changes.DeleteVoteInput) Result(org.eclipse.jgit.lib.RefUpdate.Result) Constants(org.eclipse.jgit.lib.Constants) Collectors.joining(java.util.stream.Collectors.joining) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) PersonIdent(org.eclipse.jgit.lib.PersonIdent) UseClockStep(com.google.gerrit.acceptance.UseClockStep) Stream(java.util.stream.Stream) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) PushResult(org.eclipse.jgit.transport.PushResult) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) DiffSummary(com.google.gerrit.server.patch.DiffSummary) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Exports(com.google.gerrit.extensions.annotations.Exports) IndexPreloadingUtil(com.google.gerrit.httpd.raw.IndexPreloadingUtil) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) RawInputUtil(com.google.gerrit.common.RawInputUtil) AccountOperations(com.google.gerrit.acceptance.testsuite.account.AccountOperations) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Lists(com.google.common.collect.Lists) LabelFunction(com.google.gerrit.entities.LabelFunction) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) TestRepository(org.eclipse.jgit.junit.TestRepository) CURRENT_ACTIONS(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) IOException(java.io.IOException) Test(org.junit.Test) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) Project(com.google.gerrit.entities.Project) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) Named(com.google.inject.name.Named) FooterConstants(com.google.gerrit.common.FooterConstants) GitUtil.assertPushOk(com.google.gerrit.acceptance.GitUtil.assertPushOk) AbstractModule(com.google.inject.AbstractModule) RefNames.changeMetaRef(com.google.gerrit.entities.RefNames.changeMetaRef) Inject(com.google.inject.Inject) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) FILE_CONTENT(com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) LabelType(com.google.gerrit.entities.LabelType) REVIEWED(com.google.gerrit.extensions.client.ListChangesOption.REVIEWED) AuthException(com.google.gerrit.extensions.restapi.AuthException) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) CHECK(com.google.gerrit.extensions.client.ListChangesOption.CHECK) IntraLineDiffKey(com.google.gerrit.server.patch.IntraLineDiffKey) ImmutableSet(com.google.common.collect.ImmutableSet) SubmitType(com.google.gerrit.extensions.client.SubmitType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ChangeData(com.google.gerrit.server.query.change.ChangeData) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) LabelId(com.google.gerrit.entities.LabelId) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Function(java.util.function.Function) MessageFormat(java.text.MessageFormat) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) Change(com.google.gerrit.entities.Change) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ChangeContext(com.google.gerrit.server.update.ChangeContext) TestProjectUpdate.allowCapability(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability) UTF_8(java.nio.charset.StandardCharsets.UTF_8) CHANGE_ACTIONS(com.google.gerrit.extensions.client.ListChangesOption.CHANGE_ACTIONS) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors.toList(java.util.stream.Collectors.toList) Message(com.google.gerrit.testing.FakeEmailSender.Message) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) COMMIT_FOOTERS(com.google.gerrit.extensions.client.ListChangesOption.COMMIT_FOOTERS) Cache(com.google.common.cache.Cache) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) TestProjectUpdate.labelPermissionKey(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.labelPermissionKey) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Arrays(java.util.Arrays) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) TrackingIdInfo(com.google.gerrit.extensions.common.TrackingIdInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) DiffSummaryKey(com.google.gerrit.server.patch.DiffSummaryKey) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) GroupOperations(com.google.gerrit.acceptance.testsuite.group.GroupOperations) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) DeleteDraftCommentsInput(com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeMessages(com.google.gerrit.server.change.ChangeMessages) ChangeOperatorFactory(com.google.gerrit.server.query.change.ChangeQueryBuilder.ChangeOperatorFactory) Set(java.util.Set) RefUpdate(org.eclipse.jgit.lib.RefUpdate) TestLabels.label(com.google.gerrit.server.project.testing.TestLabels.label) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) BranchNameKey(com.google.gerrit.entities.BranchNameKey) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) CacheStats(com.google.common.cache.CacheStats) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) TestChangeETagComputation(com.google.gerrit.server.change.testing.TestChangeETagComputation) TestLabels(com.google.gerrit.server.project.testing.TestLabels) ArrayList(java.util.ArrayList) CURRENT_COMMIT(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) PatchSet(com.google.gerrit.entities.PatchSet) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GitUtil(com.google.gerrit.acceptance.GitUtil) Address(com.google.gerrit.entities.Address) WorkInProgressStateChangedListener(com.google.gerrit.extensions.events.WorkInProgressStateChangedListener) AccountGroup(com.google.gerrit.entities.AccountGroup) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) CacheStatsSubject.assertThat(com.google.gerrit.truth.CacheStatsSubject.assertThat) StorageException(com.google.gerrit.exceptions.StorageException) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) Repository(org.eclipse.jgit.lib.Repository) REMOVED(com.google.gerrit.extensions.client.ReviewerState.REMOVED) ALL_REVISIONS(com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) PUSH_CERTIFICATES(com.google.gerrit.extensions.client.ListChangesOption.PUSH_CERTIFICATES) IntraLineDiff(com.google.gerrit.server.patch.IntraLineDiff) PostFilterPredicate(com.google.gerrit.index.query.PostFilterPredicate) DraftApi(com.google.gerrit.extensions.api.changes.DraftApi) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) DEFAULT_LABEL(com.google.gerrit.server.StarredChangesUtil.DEFAULT_LABEL) RefNames(com.google.gerrit.entities.RefNames) Collectors.toSet(java.util.stream.Collectors.toSet) PostReview(com.google.gerrit.server.restapi.change.PostReview) ReviewerInfo(com.google.gerrit.extensions.api.changes.ReviewerInfo) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableMap(com.google.common.collect.ImmutableMap) VerifyNoPiiInChangeNotes(com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) List(java.util.List) Optional(java.util.Optional) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) GitPerson(com.google.gerrit.extensions.common.GitPerson) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) IndexConfig(com.google.gerrit.index.IndexConfig) CC(com.google.gerrit.extensions.client.ReviewerState.CC) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) UseTimezone(com.google.gerrit.acceptance.UseTimezone) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) Range(com.google.gerrit.extensions.client.Comment.Range) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) TRACKING_IDS(com.google.gerrit.extensions.client.ListChangesOption.TRACKING_IDS) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) Iterator(java.util.Iterator) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) IndexedChangeQuery(com.google.gerrit.server.index.change.IndexedChangeQuery) TestProjectUpdate.permissionKey(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.permissionKey) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) ChangeIndex(com.google.gerrit.server.index.change.ChangeIndex) CacheStatsSubject.cloneStats(com.google.gerrit.truth.CacheStatsSubject.cloneStats) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 33 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method removeReviewerNoVotes.

@Test
public void removeReviewerNoVotes() throws Exception {
    LabelType verified = label(LabelId.VERIFIED, value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().upsertLabelType(verified);
        u.save();
    }
    projectOperations.project(project).forUpdate().add(allowLabel(verified.getName()).ref(RefNames.REFS_HEADS + "*").group(REGISTERED_USERS).range(-1, 1)).update();
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    gApi.changes().id(changeId).addReviewer(user.id().toString());
    ChangeInfo c = gApi.changes().id(changeId).get(ListChangesOption.DETAILED_LABELS);
    assertThat(getReviewers(c.reviewers.get(CC))).isEmpty();
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactly(user.id());
    sender.clear();
    gApi.changes().id(changeId).reviewer(user.id().toString()).remove();
    assertThat(gApi.changes().id(changeId).get().reviewers).isEmpty();
    assertThat(sender.getMessages()).hasSize(1);
    Message message = sender.getMessages().get(0);
    assertThat(message.body()).contains("Removed reviewer " + user.getNameEmail() + ".");
    assertThat(message.body()).doesNotContain("with the following votes");
    // Make sure the change message for removing a reviewer is correct.
    assertThat(Iterables.getLast(gApi.changes().id(changeId).messages()).message).isEqualTo("Removed reviewer " + user.getNameEmail() + ".");
    ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
    assertThat(changeMessageInfo.message).isEqualTo("Removed reviewer " + AccountTemplateUtil.getAccountTemplate(user.id()) + ".");
    assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
    // Make sure the reviewer can still be added again.
    gApi.changes().id(changeId).addReviewer(user.id().toString());
    c = gApi.changes().id(changeId).get();
    assertThat(getReviewers(c.reviewers.get(CC))).isEmpty();
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactly(user.id());
    // Remove again, and then try to remove once more to verify 404 is
    // returned.
    gApi.changes().id(changeId).reviewer(user.id().toString()).remove();
    assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeId).reviewer(user.id().toString()).remove());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) LabelType(com.google.gerrit.entities.LabelType) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 34 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method emailNotificationForFileLevelComment.

@Test
public void emailNotificationForFileLevelComment() throws Exception {
    String changeId = createChange().getChangeId();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    gApi.changes().id(changeId).addReviewer(in);
    sender.clear();
    ReviewInput review = new ReviewInput();
    ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
    comment.path = PushOneCommit.FILE_NAME;
    comment.side = Side.REVISION;
    comment.message = "comment 1";
    review.comments = new HashMap<>();
    review.comments.put(comment.path, Lists.newArrayList(comment));
    gApi.changes().id(changeId).current().review(review);
    assertThat(sender.getMessages()).hasSize(1);
    Message m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 35 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method ignore.

@Test
public void ignore() throws Exception {
    String email = "user2@example.com";
    String fullname = "User2";
    accountOperations.newAccount().username("user2").preferredEmail(email).fullname(fullname).create();
    PushOneCommit.Result r = createChange();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    in = new ReviewerInput();
    in.reviewer = email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(r.getChangeId()).ignore(true);
    assertThat(gApi.changes().id(r.getChangeId()).ignored()).isTrue();
    // New patch set notification is not sent to users ignoring the change
    sender.clear();
    requestScopeOperations.setApiUser(admin.id());
    amendChange(r.getChangeId());
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Address address = Address.create(fullname, email);
    assertThat(messages.get(0).rcpt()).containsExactly(address);
    // Review notification is not sent to users ignoring the change
    sender.clear();
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
    messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).rcpt()).containsExactly(address);
    // Abandoned notification is not sent to users ignoring the change
    sender.clear();
    gApi.changes().id(r.getChangeId()).abandon();
    messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).rcpt()).containsExactly(address);
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(r.getChangeId()).ignore(false);
    assertThat(gApi.changes().id(r.getChangeId()).ignored()).isFalse();
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Address(com.google.gerrit.entities.Address) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Message (com.google.gerrit.testing.FakeEmailSender.Message)56 Test (org.junit.Test)49 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)39 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)35 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)24 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)24 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)15 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)15 TestAccount (com.google.gerrit.acceptance.TestAccount)13 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)12 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 MailMessage (com.google.gerrit.mail.MailMessage)10 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)9 Address (com.google.gerrit.entities.Address)7 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)7 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)7 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)5