Search in sources :

Example 6 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class WatchedProjectsIT method watchNonExistingProject.

@Test
public void watchNonExistingProject() throws Exception {
    String projectName = NEW_PROJECT_NAME + "3";
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>(2);
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    exception.expect(UnprocessableEntityException.class);
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ArrayList(java.util.ArrayList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method watch.

protected void watch(String project, String filter) throws RestApiException {
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = project;
    pwi.filter = filter;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ArrayList(java.util.ArrayList)

Example 8 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo 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 = accounts.create("user3", "user3@example.com", "User3");
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = project.get();
    pwi.filter = "*";
    pwi.notifyNewChanges = true;
    projectsToWatch.add(pwi);
    setApiUser(user3);
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    TestAccount user2 = accounts.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.emailAddress);
    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.emailAddress, user2.emailAddress, user3.emailAddress);
    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();
    r = 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) Message(com.google.gerrit.testutil.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 9 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class WatchedProjectsIT method setAndGetWatchedProjects.

@Test
public void setAndGetWatchedProjects() throws Exception {
    String projectName1 = createProject(NEW_PROJECT_NAME).get();
    String projectName2 = createProject(NEW_PROJECT_NAME + "2").get();
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>(2);
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName1;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    pwi = new ProjectWatchInfo();
    pwi.project = projectName2;
    pwi.filter = "branch:master";
    pwi.notifySubmittedChanges = true;
    pwi.notifyNewPatchSets = true;
    projectsToWatch.add(pwi);
    List<ProjectWatchInfo> persistedWatchedProjects = gApi.accounts().self().setWatchedProjects(projectsToWatch);
    assertThat(persistedWatchedProjects).containsAllIn(projectsToWatch).inOrder();
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ArrayList(java.util.ArrayList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class WatchedProjectsIT method deleteNonExistingProjectWatch.

@Test
public void deleteNonExistingProjectWatch() throws Exception {
    String projectName = project.get();
    // Let another user watch a project
    setApiUser(admin);
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    // Try to delete a watched project using a different user
    List<ProjectWatchInfo> d = Lists.newArrayList(pwi);
    gApi.accounts().self().deleteWatchedProjects(d);
    // Check that trying to delete a non-existing watch doesn't fail
    setApiUser(user);
    gApi.accounts().self().deleteWatchedProjects(d);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ArrayList(java.util.ArrayList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ProjectWatchInfo (com.google.gerrit.extensions.client.ProjectWatchInfo)13 ArrayList (java.util.ArrayList)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 Test (org.junit.Test)9 ProjectWatchKey (com.google.gerrit.server.account.WatchConfig.ProjectWatchKey)2 Set (java.util.Set)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 Account (com.google.gerrit.reviewdb.client.Account)1 NotifyType (com.google.gerrit.server.account.WatchConfig.NotifyType)1 Message (com.google.gerrit.testutil.FakeEmailSender.Message)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1