Search in sources :

Example 21 with Message

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

the class MailProcessorIT method validateChangeMessage_rejected.

@Test
public void validateChangeMessage_rejected() throws Exception {
    String changeId = createChangeWithReview();
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
    setupFailValidation(CommentForValidation.CommentType.CHANGE_MESSAGE, changeInfo.project, changeInfo._number);
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", COMMENT_TEXT, null, null);
    b.textContent(txt + textFooterForChange(changeInfo._number, ts));
    List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
    mailProcessor.process(b.build());
    assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
    assertNotifyTo(user);
    Message message = sender.nextMessage();
    assertThat(message.body()).contains("rejected one or more comments");
    // ensure the message header contains a valid message id.
    assertThat(((StringEmailHeader) message.headers().get("Message-ID")).getString()).containsMatch("<someid-REJECTION-HTML@" + new URL(canonicalWebUrl.get()).getHost() + ">");
}
Also used : MailMessage(com.google.gerrit.mail.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) MailMessage(com.google.gerrit.mail.MailMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) URL(java.net.URL) Test(org.junit.Test)

Example 22 with Message

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

the class ProjectWatchIT method watchAllProjects.

@Test
public void watchAllProjects() throws Exception {
    String anyProject = projectOperations.newProject().create().get();
    requestScopeOperations.setApiUser(user.id());
    // watch the All-Projects project to watch all projects
    watch(allProjects.get());
    // push a change to any project -> should trigger email notification
    requestScopeOperations.setApiUser(admin.id());
    TestRepository<InMemoryRepository> anyRepo = cloneProject(Project.nameKey(anyProject), admin);
    PushOneCommit.Result r = pushFactory.create(admin.newIdent(), anyRepo, "TRIGGER", "a", "a1").to("refs/for/master");
    r.assertOkStatus();
    // assert email notification
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    assertThat(m.body()).contains("Change subject: TRIGGER\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testing.FakeEmailSender.Message) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 23 with Message

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

the class AccountIT method addEmailSendsConfirmationEmail.

@Test
@GerritConfig(name = "auth.registerEmailPrivateKey", value = "HsOc6l_2lhS9G7sE_RsnS7Z6GJjdRDX14co=")
public void addEmailSendsConfirmationEmail() throws Exception {
    String email = "new.email@example.com";
    EmailInput input = newEmailInput(email, false);
    gApi.accounts().self().addEmail(input);
    assertThat(sender.getMessages()).hasSize(1);
    Message m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(Address.create(email));
}
Also used : Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with Message

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

the class AccountIT method addExistingReviewersUsingAddReviewer.

@Test
public void addExistingReviewersUsingAddReviewer() throws Exception {
    PushOneCommit.Result r = createChange();
    // First reviewer added to the change
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = user.email();
    gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message message = messages.get(0);
    assertThat(message.rcpt()).containsExactly(user.getNameEmail());
    assertMailReplyTo(message, admin.email());
    sender.clear();
    // Second reviewer added to the change
    TestAccount user2 = accountCreator.user2();
    ReviewerInput reviewerInput2 = new ReviewerInput();
    reviewerInput2.reviewer = user2.email();
    gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput2);
    List<Message> messages2 = sender.getMessages();
    assertThat(messages2).hasSize(1);
    Message message2 = messages2.get(0);
    assertThat(message2.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail());
    assertMailReplyTo(message2, admin.email());
    sender.clear();
    // Exiting reviewer re-added to the change: no notifications
    ReviewerInput reviewerInput3 = new ReviewerInput();
    reviewerInput3.reviewer = user2.email();
    gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput3);
    List<Message> messages3 = sender.getMessages();
    assertThat(messages3).isEmpty();
}
Also used : Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with Message

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

the class AccountIT method addReviewerToIgnoredChange.

@Test
public void addReviewerToIgnoredChange() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        PushOneCommit.Result r = createChange();
        requestScopeOperations.setApiUser(user.id());
        gApi.changes().id(r.getChangeId()).ignore(true);
        sender.clear();
        requestScopeOperations.setApiUser(admin.id());
        ReviewerInput in = new ReviewerInput();
        in.reviewer = user.email();
        gApi.changes().id(r.getChangeId()).addReviewer(in);
        List<Message> messages = sender.getMessages();
        assertThat(messages).hasSize(0);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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