Fix test issue of GerritCommonTest
The class PRED_get_legacy_label_types_1 of I414e62503 require GerritCommonTest prepare a ChangeControl object for PrologEnvironment, else [1] will be failed. This commit get it done. [1] buck test //gerrit-server:prolog_tests Change-Id: Id12dbec23a71d3bea744b738a48616c18213c241
This commit is contained in:

committed by
David Pursehouse

parent
cc00e00569
commit
42ef48378c
@@ -1,4 +1,7 @@
|
||||
SRCS = glob(['src/main/java/**/*.java'])
|
||||
SRCS = glob([
|
||||
'src/main/java/**/*.java',
|
||||
'src/test/java/com/google/gerrit/server/project/Util.java'
|
||||
])
|
||||
RESOURCES = glob(['src/main/resources/**/*'])
|
||||
|
||||
# TODO(sop) break up gerrit-server java_library(), its too big
|
||||
|
@@ -14,137 +14,77 @@
|
||||
|
||||
package com.google.gerrit.rules;
|
||||
|
||||
import static com.google.gerrit.common.data.Permission.LABEL;
|
||||
import static com.google.gerrit.server.project.Util.value;
|
||||
import static com.google.gerrit.server.project.Util.category;
|
||||
import static com.google.gerrit.server.project.Util.REGISTERED;
|
||||
import static com.google.gerrit.server.project.Util.grant;
|
||||
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.project.Util;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
public class GerritCommonTest extends PrologTestCase {
|
||||
private Projects projects;
|
||||
private final LabelType V = category("Verified",
|
||||
value(1, "Verified"),
|
||||
value(0, "No score"),
|
||||
value(-1, "Fails"));
|
||||
private final LabelType Q = category("Qualified",
|
||||
value(1, "Qualified"),
|
||||
value(0, "No score"),
|
||||
value(-1, "Fails"));
|
||||
|
||||
private final Project.NameKey localKey = new Project.NameKey("local");
|
||||
private ProjectConfig local;
|
||||
private Util util;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
projects = new Projects(new LabelTypes(Arrays.asList(
|
||||
category("Code-Review",
|
||||
value(2, "Looks good to me, approved"),
|
||||
value(1, "Looks good to me, but someone else must approve"),
|
||||
value(0, "No score"),
|
||||
value(-1, "I would prefer that you didn't submit this"),
|
||||
value(-2, "Do not submit")),
|
||||
category("Verified", value(1, "Verified"),
|
||||
value(0, "No score"), value(-1, "Fails")))));
|
||||
util = new Util();
|
||||
load("gerrit", "gerrit_common_test.pl", new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PrologEnvironment.Args.class).toInstance(
|
||||
new PrologEnvironment.Args(
|
||||
projects,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
));
|
||||
new PrologEnvironment.Args(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
}
|
||||
});
|
||||
|
||||
local = new ProjectConfig(localKey);
|
||||
local.createInMemory();
|
||||
Q.setRefPatterns(Arrays.asList("refs/heads/develop"));
|
||||
|
||||
local.getLabelSections().put(V.getName(), V);
|
||||
local.getLabelSections().put(Q.getName(), Q);
|
||||
util.add(local);
|
||||
grant(local, LABEL + V.getName(), -1, +1, REGISTERED, "refs/heads/*");
|
||||
grant(local, LABEL + Q.getName(), -1, +1, REGISTERED, "refs/heads/master");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpEnvironment(PrologEnvironment env) {
|
||||
env.set(StoredValues.CHANGE, new Change(
|
||||
new Change.Key("Ibeef"), new Change.Id(1), new Account.Id(2),
|
||||
new Branch.NameKey(projects.allProjectsName, "master")));
|
||||
Change change =
|
||||
new Change(new Change.Key("Ibeef"), new Change.Id(1),
|
||||
new Account.Id(2),
|
||||
new Branch.NameKey(localKey, "refs/heads/master"));
|
||||
env.set(StoredValues.CHANGE, change);
|
||||
env.set(StoredValues.CHANGE_CONTROL, util.user(local).controlFor(change));
|
||||
}
|
||||
|
||||
public void testGerritCommon() {
|
||||
runPrologBasedTests();
|
||||
}
|
||||
|
||||
private static LabelValue value(int value, String text) {
|
||||
return new LabelValue((short) value, text);
|
||||
}
|
||||
|
||||
private static LabelType category(String name, LabelValue... values) {
|
||||
return new LabelType(name, Arrays.asList(values));
|
||||
}
|
||||
|
||||
private static class Projects implements ProjectCache {
|
||||
private final AllProjectsName allProjectsName;
|
||||
private final ProjectState allProjects;
|
||||
|
||||
private Projects(LabelTypes labelTypes) {
|
||||
allProjectsName = new AllProjectsName("All-Projects");
|
||||
ProjectConfig config = new ProjectConfig(allProjectsName);
|
||||
config.createInMemory();
|
||||
for (LabelType label : labelTypes.getLabelTypes()) {
|
||||
config.getLabelSections().put(label.getName(), label);
|
||||
}
|
||||
allProjects = new ProjectState(null, this, allProjectsName, null, null,
|
||||
null, null, null, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState getAllProjects() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState get(Project.NameKey projectName) {
|
||||
assertEquals(allProjectsName, projectName);
|
||||
return allProjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState checkedGet(Project.NameKey projectName) {
|
||||
return get(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evict(Project p) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evict(Project.NameKey p) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Project p) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Project.NameKey> all() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<AccountGroup.UUID> guessRelevantGroupUUIDs() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Project.NameKey> byName(String prefix) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateProject(Project.NameKey newProjectName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@ import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch;
|
||||
@@ -43,6 +45,7 @@ import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -56,6 +59,21 @@ public class Util {
|
||||
public static AccountGroup.UUID ADMIN = new AccountGroup.UUID("test.admin");
|
||||
public static AccountGroup.UUID DEVS = new AccountGroup.UUID("test.devs");
|
||||
|
||||
public static LabelType CR = category("Code-Review",
|
||||
value(2, "Looks good to me, approved"),
|
||||
value(1, "Looks good to me, but someone else must approve"),
|
||||
value(0, "No score"),
|
||||
value(-1, "I would prefer that you didn't submit this"),
|
||||
value(-2, "Do not submit"));
|
||||
|
||||
public static LabelValue value(int value, String text) {
|
||||
return new LabelValue((short) value, text);
|
||||
}
|
||||
|
||||
public static LabelType category(String name, LabelValue... values) {
|
||||
return new LabelType(name, Arrays.asList(values));
|
||||
}
|
||||
|
||||
static public PermissionRule newRule(ProjectConfig project,
|
||||
AccountGroup.UUID groupUUID) {
|
||||
GroupReference group = new GroupReference(groupUUID, groupUUID.get());
|
||||
@@ -104,6 +122,8 @@ public class Util {
|
||||
public Util() {
|
||||
all = new HashMap<Project.NameKey, ProjectState>();
|
||||
parent.createInMemory();
|
||||
parent.getLabelSections().put(CR.getName(), CR);
|
||||
|
||||
add(parent);
|
||||
|
||||
projectCache = new ProjectCache() {
|
||||
|
Reference in New Issue
Block a user