Search in sources :

Example 6 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ProjectWatchIT method watchProjectNoNotificationForIgnoredChange.

@Test
public void watchProjectNoNotificationForIgnoredChange() throws Exception {
    // watch project
    String watchedProject = createProject("watchedProject").get();
    setApiUser(user);
    watch(watchedProject, null);
    // push a change to watched project
    setApiUser(admin);
    TestRepository<InMemoryRepository> watchedRepo = cloneProject(new Project.NameKey(watchedProject), admin);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), watchedRepo, "ignored change", "a", "a1").to("refs/for/master");
    r.assertOkStatus();
    // ignore the change
    setApiUser(user);
    gApi.accounts().self().setStars(r.getChangeId(), new StarsInput(ImmutableSet.of(IGNORE_LABEL)));
    sender.clear();
    // post a comment -> should not trigger email notification since user ignored the change
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).current().review(in);
    // assert email notification
    assertThat(sender.getMessages()).isEmpty();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) 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 7 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ProjectWatchIT method watchProject.

@Test
public void watchProject() throws Exception {
    // watch project
    String watchedProject = createProject("watchedProject").get();
    setApiUser(user);
    watch(watchedProject, null);
    // push a change to watched project -> should trigger email notification
    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");
    r.assertOkStatus();
    // push a change to non-watched project -> should not trigger email
    // notification
    String notWatchedProject = createProject("otherProject").get();
    TestRepository<InMemoryRepository> notWatchedRepo = cloneProject(new Project.NameKey(notWatchedProject), admin);
    r = pushFactory.create(db, admin.getIdent(), notWatchedRepo, "DONT_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.emailAddress);
    assertThat(m.body()).contains("Change subject: TRIGGER\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testutil.FakeEmailSender.Message) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ProjectWatchIT method watchKeywordAllProjects.

@Test
public void watchKeywordAllProjects() throws Exception {
    String anyProject = createProject("anyProject").get();
    setApiUser(user);
    // watch keyword in project as user
    watch(allProjects.get(), "multimaster");
    // push a change with keyword to any project -> should trigger email
    // notification
    setApiUser(admin);
    TestRepository<InMemoryRepository> anyRepo = cloneProject(new Project.NameKey(anyProject), admin);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), anyRepo, "Document multimaster setup", "a.txt", "a1").to("refs/for/master");
    r.assertOkStatus();
    // assert email notification for user
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress);
    assertThat(m.body()).contains("Change subject: Document multimaster setup\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
    sender.clear();
    // push a change without keyword to any project -> should not trigger email
    // notification
    r = pushFactory.create(db, admin.getIdent(), anyRepo, "Cleanup cache implementation", "b.txt", "b1").to("refs/for/master");
    r.assertOkStatus();
    // assert email notification
    assertThat(sender.getMessages()).isEmpty();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testutil.FakeEmailSender.Message) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ProjectWatchIT method watchFileAllProjects.

@Test
public void watchFileAllProjects() throws Exception {
    String anyProject = createProject("anyProject").get();
    setApiUser(user);
    // watch file in All-Projects project as user to watch the file in all
    // projects
    watch(allProjects.get(), "file:a.txt");
    // push a change to watched file in any project -> should trigger email
    // notification for user
    setApiUser(admin);
    TestRepository<InMemoryRepository> anyRepo = cloneProject(new Project.NameKey(anyProject), admin);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), anyRepo, "TRIGGER", "a.txt", "a1").to("refs/for/master");
    r.assertOkStatus();
    // assert email notification for user
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress);
    assertThat(m.body()).contains("Change subject: TRIGGER\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
    sender.clear();
    // watch project as user2
    TestAccount user2 = accounts.create("user2", "user2@test.com", "User2");
    setApiUser(user2);
    watch(anyProject, null);
    // push a change to non-watched file in any project -> should not trigger
    // email notification for user, only for user2
    r = pushFactory.create(db, admin.getIdent(), anyRepo, "TRIGGER_USER2", "b.txt", "b1").to("refs/for/master");
    r.assertOkStatus();
    // assert email notification
    messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user2.emailAddress);
    assertThat(m.body()).contains("Change subject: TRIGGER_USER2\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testutil.FakeEmailSender.Message) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ProjectWatchIT method watchAllProjects.

@Test
public void watchAllProjects() throws Exception {
    String anyProject = createProject("anyProject").get();
    setApiUser(user);
    // watch the All-Projects project to watch all projects
    watch(allProjects.get(), null);
    // push a change to any project -> should trigger email notification
    setApiUser(admin);
    TestRepository<InMemoryRepository> anyRepo = cloneProject(new Project.NameKey(anyProject), admin);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), 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.emailAddress);
    assertThat(m.body()).contains("Change subject: TRIGGER\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testutil.FakeEmailSender.Message) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)54 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)37 Test (org.junit.Test)37 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)30 Project (com.google.gerrit.reviewdb.client.Project)21 DfsRepositoryDescription (org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription)12 Before (org.junit.Before)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)8 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 PushResult (org.eclipse.jgit.transport.PushResult)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)6 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 CurrentUser (com.google.gerrit.server.CurrentUser)4 Config (org.eclipse.jgit.lib.Config)4 Sandboxed (com.google.gerrit.acceptance.Sandboxed)3 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)3