Factor methods out to AbstractDaemonTest
Move the `grant`, `blockRead` and `pushTo` methods out into the AbstractDaemonTest class, so they can be used by other tests. Change-Id: I55a023d0ab831a67040ec9525258211eb8fc63cf
This commit is contained in:
@@ -17,11 +17,16 @@ package com.google.gerrit.acceptance;
|
||||
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
|
||||
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
||||
import static com.google.gerrit.acceptance.GitUtil.initSsh;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.server.project.Util.block;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.primitives.Chars;
|
||||
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
@@ -32,6 +37,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
@@ -48,6 +54,8 @@ import com.google.inject.util.Providers;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestRule;
|
||||
@@ -93,6 +101,9 @@ public abstract class AbstractDaemonTest {
|
||||
@Inject
|
||||
protected ProjectCache projectCache;
|
||||
|
||||
@Inject
|
||||
protected GroupCache groupCache;
|
||||
|
||||
protected Git git;
|
||||
protected GerritServer server;
|
||||
protected TestAccount admin;
|
||||
@@ -266,4 +277,29 @@ public abstract class AbstractDaemonTest {
|
||||
}
|
||||
projectCache.evict(cfg.getProject());
|
||||
}
|
||||
|
||||
protected void grant(String permission, Project.NameKey project, String ref)
|
||||
throws RepositoryNotFoundException, IOException, ConfigInvalidException {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
||||
md.setMessage(String.format("Grant %s on %s", permission, ref));
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
AccessSection s = config.getAccessSection(ref, true);
|
||||
Permission p = s.getPermission(permission, true);
|
||||
AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
|
||||
p.add(new PermissionRule(config.resolve(adminGroup)));
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
|
||||
protected void blockRead(Project.NameKey project, String ref) throws Exception {
|
||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
||||
block(cfg, Permission.READ, REGISTERED_USERS, ref);
|
||||
saveProjectConfig(project, cfg);
|
||||
}
|
||||
|
||||
protected PushOneCommit.Result pushTo(String ref) throws GitAPIException,
|
||||
IOException {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
return push.to(git, ref);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,10 +278,4 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
|
||||
PushOneCommit.Result r = pushTo("refs/for/master%hashtag=tag1");
|
||||
r.assertErrorStatus("cannot add hashtags; noteDb is disabled");
|
||||
}
|
||||
|
||||
private PushOneCommit.Result pushTo(String ref) throws GitAPIException,
|
||||
IOException {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
return push.to(git, ref);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +58,6 @@ public class DraftChangeBlockedIT extends AbstractDaemonTest {
|
||||
r.assertErrorStatus("cannot upload drafts");
|
||||
}
|
||||
|
||||
private PushOneCommit.Result pushTo(String ref) throws GitAPIException,
|
||||
IOException {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
return push.to(git, ref);
|
||||
}
|
||||
|
||||
private void saveProjectConfig(ProjectConfig cfg) throws IOException {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(allProjects);
|
||||
try {
|
||||
|
||||
@@ -22,28 +22,21 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.git.CommitMergeStatus;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
@@ -62,9 +55,6 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
|
||||
@Inject
|
||||
private ApprovalsUtil approvalsUtil;
|
||||
|
||||
@Inject
|
||||
private GroupCache groupCache;
|
||||
|
||||
@Inject
|
||||
private ChangeNotes.Factory changeNotesFactory;
|
||||
|
||||
@@ -217,19 +207,6 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
|
||||
assertEquals(Change.Status.MERGED, c.getStatus());
|
||||
}
|
||||
|
||||
private void grant(String permission, Project.NameKey project, String ref)
|
||||
throws RepositoryNotFoundException, IOException, ConfigInvalidException {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.create(project);
|
||||
md.setMessage(String.format("Grant %s on %s", permission, ref));
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
AccessSection s = config.getAccessSection(ref, true);
|
||||
Permission p = s.getPermission(permission, true);
|
||||
AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
|
||||
p.add(new PermissionRule(config.resolve(adminGroup)));
|
||||
config.commit(md);
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
|
||||
private PatchSetApproval getSubmitter(PatchSet.Id patchSetId)
|
||||
throws OrmException {
|
||||
Change c = db.changes().get(patchSetId.getParentKey());
|
||||
@@ -291,12 +268,6 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
|
||||
}
|
||||
}
|
||||
|
||||
private PushOneCommit.Result pushTo(String ref) throws GitAPIException,
|
||||
IOException {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
return push.to(git, ref);
|
||||
}
|
||||
|
||||
private PushOneCommit.Result push(String ref, String subject,
|
||||
String fileName, String content) throws GitAPIException, IOException {
|
||||
PushOneCommit push =
|
||||
|
||||
@@ -16,17 +16,12 @@ package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
||||
import static com.google.gerrit.acceptance.rest.project.BranchAssert.assertBranches;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.server.project.Util.block;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.project.ListBranches.BranchInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@@ -123,12 +118,6 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
return adminSession.get(endpoint);
|
||||
}
|
||||
|
||||
private void blockRead(Project.NameKey project, String ref) throws Exception {
|
||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
||||
block(cfg, Permission.READ, REGISTERED_USERS, ref);
|
||||
saveProjectConfig(project, cfg);
|
||||
}
|
||||
|
||||
private static List<BranchInfo> toBranchInfoList(RestResponse r)
|
||||
throws IOException {
|
||||
List<BranchInfo> result =
|
||||
@@ -136,10 +125,4 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
new TypeToken<List<BranchInfo>>() {}.getType());
|
||||
return result;
|
||||
}
|
||||
|
||||
private PushOneCommit.Result pushTo(String ref) throws GitAPIException,
|
||||
IOException {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
return push.to(git, ref);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user