Merge "Support to control notifications when creating changes through REST"
This commit is contained in:
@@ -28,6 +28,7 @@ import com.google.gerrit.acceptance.PushOneCommit.Result;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
@@ -43,6 +44,7 @@ import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
||||
import com.google.gerrit.server.git.ChangeAlreadyMergedException;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gerrit.testutil.TestTimeUtil;
|
||||
import com.google.gerrit.testutil.FakeEmailSender.Message;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -55,6 +57,8 @@ import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateChangeIT extends AbstractDaemonTest {
|
||||
@ConfigSuite.Config
|
||||
public static Config allowDraftsDisabled() {
|
||||
@@ -100,6 +104,30 @@ public class CreateChangeIT extends AbstractDaemonTest {
|
||||
assertCreateSucceeds(newChangeInput(ChangeStatus.NEW));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notificationsOnChangeCreation() throws Exception {
|
||||
setApiUser(user);
|
||||
watch(project.get(), null);
|
||||
|
||||
// check that watcher is notified
|
||||
setApiUser(admin);
|
||||
assertCreateSucceeds(newChangeInput(ChangeStatus.NEW));
|
||||
|
||||
List<Message> messages = sender.getMessages();
|
||||
assertThat(messages).hasSize(1);
|
||||
Message m = messages.get(0);
|
||||
assertThat(m.rcpt()).containsExactly(user.emailAddress);
|
||||
assertThat(m.body())
|
||||
.contains(admin.fullName + " has uploaded this change for review.");
|
||||
|
||||
// check that watcher is not notified if notify=NONE
|
||||
sender.clear();
|
||||
ChangeInput input = newChangeInput(ChangeStatus.NEW);
|
||||
input.notify = NotifyHandling.NONE;
|
||||
assertCreateSucceeds(input);
|
||||
assertThat(sender.getMessages()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNewChangeSignedOffByFooter() throws Exception {
|
||||
assume().that(isAllowDrafts()).isTrue();
|
||||
|
||||
@@ -21,8 +21,6 @@ import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.Sandboxed;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.account.WatchConfig.NotifyType;
|
||||
import com.google.gerrit.server.git.NotifyConfig;
|
||||
@@ -34,7 +32,6 @@ import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -312,17 +309,4 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
||||
// assert email notification
|
||||
assertThat(sender.getMessages()).hasSize(0);
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user