Search in sources :

Example 36 with Message

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

the class ChangeIT method testAddReviewerViaPostReview.

private void testAddReviewerViaPostReview(AddReviewerCaller addReviewer) throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Instant oldTs = rsrc.getChange().getLastUpdatedOn();
    addReviewer.call(r.getChangeId(), user.email());
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    assertThat(m.body()).contains("Hello " + user.fullName() + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, admin.email());
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    // Adding a reviewer records that user as reviewer.
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
    // Nobody was added as CC.
    assertThat(c.reviewers.get(CC)).isNull();
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
    // Change status of reviewer and ensure ETag is updated.
    oldETag = rsrc.getETag();
    accountOperations.account(user.id()).forUpdate().status("new status").update();
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Instant(java.time.Instant) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 37 with Message

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

the class ChangeIT method pushCommitOfOtherUser.

@Test
public void pushCommitOfOtherUser() throws Exception {
    // admin pushes commit of user
    PushOneCommit push = pushFactory.create(user.newIdent(), testRepo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id().get());
    CommitInfo commit = change.revisions.get(change.currentRevision).commit;
    assertThat(commit.author.email).isEqualTo(user.email());
    assertThat(commit.committer.email).isEqualTo(user.email());
    // check that the author/committer was added as cc
    Collection<AccountInfo> reviewers = change.reviewers.get(CC);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
    assertThat(change.reviewers.get(REVIEWER)).isNull();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.from().name()).isEqualTo("Administrator (Code Review)");
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    assertThat(m.body()).contains("has uploaded this change for review");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, admin.email());
}
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) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 38 with Message

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

the class RevertIT method revertSubmissionNotifications.

@Test
public void revertSubmissionNotifications() throws Exception {
    String firstResult = createChange("first change", "a.txt", "message").getChangeId();
    approve(firstResult);
    gApi.changes().id(firstResult).addReviewer(user.email());
    String secondResult = createChange("second change", "b.txt", "other").getChangeId();
    approve(secondResult);
    gApi.changes().id(secondResult).addReviewer(user.email());
    gApi.changes().id(secondResult).current().submit();
    sender.clear();
    RevertInput revertInput = new RevertInput();
    revertInput.notify = NotifyHandling.ALL;
    RevertSubmissionInfo revertChanges = gApi.changes().id(secondResult).revertSubmission(revertInput);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(4);
    assertThat(sender.getMessages(revertChanges.revertChanges.get(0).changeId, "newchange")).hasSize(1);
    assertThat(sender.getMessages(firstResult, "revert")).hasSize(1);
    assertThat(sender.getMessages(revertChanges.revertChanges.get(1).changeId, "newchange")).hasSize(1);
    assertThat(sender.getMessages(secondResult, "revert")).hasSize(1);
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 39 with Message

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

the class AbstractPushForReview method pushForMasterWithNotify.

@Test
public void pushForMasterWithNotify() throws Exception {
    // create a user that watches the project
    TestAccount user3 = accountCreator.create("user3", "user3@example.com", "User3", null);
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = project.get();
    pwi.filter = "*";
    pwi.notifyNewChanges = true;
    projectsToWatch.add(pwi);
    requestScopeOperations.setApiUser(user3.id());
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    TestAccount user2 = accountCreator.user2();
    String pushSpec = "refs/for/master%reviewer=" + user.email() + ",cc=" + user2.email();
    sender.clear();
    PushOneCommit.Result r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE);
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.OWNER);
    r.assertOkStatus();
    // no email notification about own changes
    assertThat(sender.getMessages()).isEmpty();
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.OWNER_REVIEWERS);
    r.assertOkStatus();
    assertThat(sender.getMessages()).hasSize(1);
    Message m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.ALL);
    r.assertOkStatus();
    assertThat(sender.getMessages()).hasSize(1);
    m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail(), user3.getNameEmail());
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-to=" + user3.email());
    r.assertOkStatus();
    assertNotifyTo(user3);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-cc=" + user3.email());
    r.assertOkStatus();
    assertNotifyCc(user3);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-bcc=" + user3.email());
    r.assertOkStatus();
    assertNotifyBcc(user3);
    // request that sender gets notified as TO, CC and BCC, email should be sent
    // even if the sender is the only recipient
    sender.clear();
    pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-to=" + admin.email());
    assertNotifyTo(admin);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-cc=" + admin.email());
    r.assertOkStatus();
    assertNotifyCc(admin);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-bcc=" + admin.email());
    r.assertOkStatus();
    assertNotifyBcc(admin);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ChangeMessage(com.google.gerrit.entities.ChangeMessage) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) ArrayList(java.util.ArrayList) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 40 with Message

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

the class AccountIT method adminCanAddOrRemoveSshKeyOnOtherAccount.

@Test
@UseSsh
public void adminCanAddOrRemoveSshKeyOnOtherAccount() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        // The test account should initially have exactly one ssh key
        List<SshKeyInfo> info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(1);
        assertSequenceNumbers(info);
        SshKeyInfo key = info.get(0);
        KeyPair keyPair = sshKeys.getKeyPair(admin);
        String initial = TestSshKeys.publicKey(keyPair, admin.email());
        assertThat(key.sshPublicKey).isEqualTo(initial);
        accountIndexedCounter.assertNoReindex();
        // Add a new key
        sender.clear();
        String newKey = TestSshKeys.publicKey(SshSessionFactory.genSshKey(), user.email());
        gApi.accounts().id(user.username()).addSshKey(newKey);
        info = gApi.accounts().id(user.username()).listSshKeys();
        assertThat(info).hasSize(2);
        assertSequenceNumbers(info);
        accountIndexedCounter.assertReindexOf(user);
        assertThat(sender.getMessages()).hasSize(1);
        Message message = sender.getMessages().get(0);
        assertThat(message.rcpt()).containsExactly(user.getNameEmail());
        assertThat(message.body()).contains("new SSH keys have been added");
        // Delete key
        sender.clear();
        gApi.accounts().id(user.username()).deleteSshKey(1);
        info = gApi.accounts().id(user.username()).listSshKeys();
        assertThat(info).hasSize(1);
        accountIndexedCounter.assertReindexOf(user);
        assertThat(sender.getMessages()).hasSize(1);
        message = sender.getMessages().get(0);
        assertThat(message.rcpt()).containsExactly(user.getNameEmail());
        assertThat(message.body()).contains("SSH keys have been deleted");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) KeyPair(java.security.KeyPair) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) SshKeyInfo(com.google.gerrit.extensions.common.SshKeyInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseSsh(com.google.gerrit.acceptance.UseSsh)

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