DraftChangeIT: Also test when allowDrafts=false
Rename the class from DeleteDraftChangeIT to DraftChangeIT since the tests in it are not limited to deleting draft changes. Add a configuration with the allowDrafts setting disabled. Add a test to ensure that pushing a draft change is rejected when the setting is disabled. Change-Id: I9273fd6cf756a9c7974c29700835a35dba7b09f1
This commit is contained in:
@@ -39,6 +39,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
@@ -116,6 +117,9 @@ public abstract class AbstractDaemonTest {
|
||||
@Inject
|
||||
protected Provider<InternalChangeQuery> queryProvider;
|
||||
|
||||
@Inject
|
||||
protected @GerritServerConfig Config cfg;
|
||||
|
||||
protected Git git;
|
||||
protected GerritServer server;
|
||||
protected TestAccount admin;
|
||||
@@ -165,6 +169,16 @@ public abstract class AbstractDaemonTest {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
protected static Config allowDraftsDisabledConfig() {
|
||||
Config cfg = new Config();
|
||||
cfg.setBoolean("change", null, "allowDrafts", false);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
protected boolean isAllowDrafts() {
|
||||
return cfg.getBoolean("change", "allowDrafts", true);
|
||||
}
|
||||
|
||||
private void beforeTest(Config cfg, boolean memory, boolean enableHttpd) throws Exception {
|
||||
server = startServer(cfg, memory, enableHttpd);
|
||||
server.getTestInjector().injectMembers(this);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.TruthJUnit.assume;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -24,66 +25,89 @@ import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeleteDraftChangeIT extends AbstractDaemonTest {
|
||||
public class DraftChangeIT extends AbstractDaemonTest {
|
||||
@ConfigSuite.Config
|
||||
public static Config allowDraftsDisabled() {
|
||||
return allowDraftsDisabledConfig();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteChange() throws Exception {
|
||||
String changeId = createChange().getChangeId();
|
||||
PushOneCommit.Result result = createChange();
|
||||
result.assertOkStatus();
|
||||
String changeId = result.getChangeId();
|
||||
String triplet = "p~master~" + changeId;
|
||||
ChangeInfo c = get(triplet);
|
||||
assertThat(c.id).isEqualTo(triplet);
|
||||
assertThat(c.status).isEqualTo(ChangeStatus.NEW);
|
||||
RestResponse r = deleteChange(changeId, adminSession);
|
||||
assertThat(r.getEntityContent()).isEqualTo("Change is not a draft");
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
|
||||
RestResponse response = deleteChange(changeId, adminSession);
|
||||
assertThat(response.getEntityContent()).isEqualTo("Change is not a draft");
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteDraftChange() throws Exception {
|
||||
String changeId = createDraftChange();
|
||||
assume().that(isAllowDrafts()).isTrue();
|
||||
PushOneCommit.Result result = createDraftChange();
|
||||
result.assertOkStatus();
|
||||
String changeId = result.getChangeId();
|
||||
String triplet = "p~master~" + changeId;
|
||||
ChangeInfo c = get(triplet);
|
||||
assertThat(c.id).isEqualTo(triplet);
|
||||
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
|
||||
RestResponse r = deleteChange(changeId, adminSession);
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
RestResponse response = deleteChange(changeId, adminSession);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishDraftChange() throws Exception {
|
||||
String changeId = createDraftChange();
|
||||
assume().that(isAllowDrafts()).isTrue();
|
||||
PushOneCommit.Result result = createDraftChange();
|
||||
result.assertOkStatus();
|
||||
String changeId = result.getChangeId();
|
||||
String triplet = "p~master~" + changeId;
|
||||
ChangeInfo c = get(triplet);
|
||||
assertThat(c.id).isEqualTo(triplet);
|
||||
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
|
||||
RestResponse r = publishChange(changeId);
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
RestResponse response = publishChange(changeId);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
c = get(triplet);
|
||||
assertThat(c.status).isEqualTo(ChangeStatus.NEW);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishDraftPatchSet() throws Exception {
|
||||
String changeId = createDraftChange();
|
||||
assume().that(isAllowDrafts()).isTrue();
|
||||
PushOneCommit.Result result = createDraftChange();
|
||||
result.assertOkStatus();
|
||||
String changeId = result.getChangeId();
|
||||
String triplet = "p~master~" + changeId;
|
||||
ChangeInfo c = get(triplet);
|
||||
assertThat(c.id).isEqualTo(triplet);
|
||||
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
|
||||
RestResponse r = publishPatchSet(changeId);
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
RestResponse response = publishPatchSet(changeId);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
assertThat(get(triplet).status).isEqualTo(ChangeStatus.NEW);
|
||||
}
|
||||
|
||||
private String createDraftChange() throws Exception {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
return push.to(git, "refs/drafts/master").getChangeId();
|
||||
@Test
|
||||
public void createDraftChangeWhenDraftsNotAllowed() throws Exception {
|
||||
assume().that(isAllowDrafts()).isFalse();
|
||||
PushOneCommit.Result r = createDraftChange();
|
||||
r.assertErrorStatus("cannot upload drafts");
|
||||
}
|
||||
|
||||
private PushOneCommit.Result createDraftChange() throws Exception {
|
||||
return pushTo("refs/drafts/master");
|
||||
}
|
||||
|
||||
private static RestResponse deleteChange(String changeId,
|
||||
Reference in New Issue
Block a user