Search in sources :

Example 1 with Message

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

the class ProjectWatchIT method watchProjectNotifyOnDraftChange.

@Test
public void watchProjectNotifyOnDraftChange() throws Exception {
    String watchedProject = createProject("watchedProject").get();
    // create group that can view all drafts
    GroupInfo groupThatCanViewDrafts = gApi.groups().create("groupThatCanViewDrafts").get();
    grant(new Project.NameKey(watchedProject), "refs/*", Permission.VIEW_DRAFTS, false, new AccountGroup.UUID(groupThatCanViewDrafts.id));
    // watch project as user that can't view drafts
    setApiUser(user);
    watch(watchedProject, null);
    // watch project as user that can view all drafts
    TestAccount userThatCanViewDrafts = accounts.create("user2", "user2@test.com", "User2", groupThatCanViewDrafts.name);
    setApiUser(userThatCanViewDrafts);
    watch(watchedProject, null);
    // push a draft change to watched project -> should trigger email notification for
    // userThatCanViewDrafts, but not for user
    setApiUser(admin);
    TestRepository<InMemoryRepository> watchedRepo = cloneProject(new Project.NameKey(watchedProject), admin);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), watchedRepo, "TRIGGER", "a", "a1").to("refs/for/master%draft");
    r.assertOkStatus();
    // assert email notification
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(userThatCanViewDrafts.emailAddress);
    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.testutil.FakeEmailSender.Message) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Project(com.google.gerrit.reviewdb.client.Project) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with Message

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

the class AbstractDaemonTest method assertNotifyTo.

protected void assertNotifyTo(Address expected) {
    assertThat(sender.getMessages()).hasSize(1);
    Message m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(expected);
    assertThat(((EmailHeader.AddressList) m.headers().get("To")).getAddressList()).containsExactly(expected);
    assertThat(m.headers().get("CC").isEmpty()).isTrue();
}
Also used : Message(com.google.gerrit.testutil.FakeEmailSender.Message)

Aggregations

Message (com.google.gerrit.testutil.FakeEmailSender.Message)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 Project (com.google.gerrit.reviewdb.client.Project)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1 Test (org.junit.Test)1