Use new project creation API
Change-Id: I1508490fa3144515055c1eda2f567160cc3969b9
This commit is contained in:
@@ -552,24 +552,49 @@ public abstract class AbstractDaemonTest {
|
|||||||
return resourcePrefix + name;
|
return resourcePrefix + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Project.NameKey createProject(String nameSuffix) throws RestApiException {
|
protected Project.NameKey createProject(String nameSuffix) throws Exception {
|
||||||
return createProject(nameSuffix, null);
|
return projectOperations.newProject().withEmptyCommit().create();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Project.NameKey createProject(String nameSuffix, Project.NameKey parent)
|
protected Project.NameKey createProject(String nameSuffix, Project.NameKey parent)
|
||||||
throws RestApiException {
|
throws Exception {
|
||||||
// Default for createEmptyCommit should match TestProjectConfig.
|
// Default for createEmptyCommit should match TestProjectConfig.
|
||||||
return createProject(nameSuffix, parent, true, null);
|
return projectOperations.newProject().withEmptyCommit().parent(parent).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Project.NameKey createProject(
|
protected Project.NameKey createProject(
|
||||||
String nameSuffix, Project.NameKey parent, boolean createEmptyCommit)
|
String nameSuffix, Project.NameKey parent, boolean createEmptyCommit) throws Exception {
|
||||||
throws RestApiException {
|
|
||||||
// Default for createEmptyCommit should match TestProjectConfig.
|
// Default for createEmptyCommit should match TestProjectConfig.
|
||||||
return createProject(nameSuffix, parent, createEmptyCommit, null);
|
if (parent == null) {
|
||||||
|
return projectOperations.newProject().createEmptyCommit(createEmptyCommit).create();
|
||||||
|
}
|
||||||
|
return projectOperations
|
||||||
|
.newProject()
|
||||||
|
.parent(parent)
|
||||||
|
.createEmptyCommit(createEmptyCommit)
|
||||||
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Project.NameKey createProject(
|
protected Project.NameKey createProject(
|
||||||
|
String nameSuffix, Project.NameKey parent, boolean createEmptyCommit, SubmitType submitType)
|
||||||
|
throws Exception {
|
||||||
|
if (parent == null) {
|
||||||
|
return projectOperations
|
||||||
|
.newProject()
|
||||||
|
.createEmptyCommit(createEmptyCommit)
|
||||||
|
.submitType(submitType)
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
return projectOperations
|
||||||
|
.newProject()
|
||||||
|
.submitType(submitType)
|
||||||
|
.parent(parent)
|
||||||
|
.createEmptyCommit(createEmptyCommit)
|
||||||
|
.parent(parent)
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Project.NameKey createProjectOverAPI(
|
||||||
String nameSuffix, Project.NameKey parent, boolean createEmptyCommit, SubmitType submitType)
|
String nameSuffix, Project.NameKey parent, boolean createEmptyCommit, SubmitType submitType)
|
||||||
throws RestApiException {
|
throws RestApiException {
|
||||||
ProjectInput in = new ProjectInput();
|
ProjectInput in = new ProjectInput();
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ import com.google.gerrit.acceptance.PushOneCommit;
|
|||||||
import com.google.gerrit.acceptance.TestProjectInput;
|
import com.google.gerrit.acceptance.TestProjectInput;
|
||||||
import com.google.gerrit.acceptance.testsuite.account.AccountOperations;
|
import com.google.gerrit.acceptance.testsuite.account.AccountOperations;
|
||||||
import com.google.gerrit.acceptance.testsuite.group.GroupOperations;
|
import com.google.gerrit.acceptance.testsuite.group.GroupOperations;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.common.FooterConstants;
|
import com.google.gerrit.common.FooterConstants;
|
||||||
import com.google.gerrit.common.data.LabelFunction;
|
import com.google.gerrit.common.data.LabelFunction;
|
||||||
import com.google.gerrit.common.data.LabelType;
|
import com.google.gerrit.common.data.LabelType;
|
||||||
@@ -196,6 +197,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
@Inject private IndexConfig indexConfig;
|
@Inject private IndexConfig indexConfig;
|
||||||
|
|
||||||
@Inject protected GroupOperations groupOperations;
|
@Inject protected GroupOperations groupOperations;
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
private ChangeIndexedCounter changeIndexedCounter;
|
private ChangeIndexedCounter changeIndexedCounter;
|
||||||
private RegistrationHandle changeIndexedCounterHandle;
|
private RegistrationHandle changeIndexedCounterHandle;
|
||||||
@@ -1613,7 +1615,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void pushCommitWithFooterOfOtherUserThatCannotSeeChange() throws Exception {
|
public void pushCommitWithFooterOfOtherUserThatCannotSeeChange() throws Exception {
|
||||||
// create hidden project that is only visible to administrators
|
// create hidden project that is only visible to administrators
|
||||||
Project.NameKey p = createProject("p");
|
Project.NameKey p = projectOperations.newProject().create();
|
||||||
try (ProjectConfigUpdate u = updateProject(p)) {
|
try (ProjectConfigUpdate u = updateProject(p)) {
|
||||||
Util.allow(u.getConfig(), Permission.READ, adminGroupUuid(), "refs/*");
|
Util.allow(u.getConfig(), Permission.READ, adminGroupUuid(), "refs/*");
|
||||||
Util.block(u.getConfig(), Permission.READ, REGISTERED_USERS, "refs/*");
|
Util.block(u.getConfig(), Permission.READ, REGISTERED_USERS, "refs/*");
|
||||||
@@ -1657,7 +1659,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void addReviewerThatCannotSeeChange() throws Exception {
|
public void addReviewerThatCannotSeeChange() throws Exception {
|
||||||
// create hidden project that is only visible to administrators
|
// create hidden project that is only visible to administrators
|
||||||
Project.NameKey p = createProject("p");
|
Project.NameKey p = projectOperations.newProject().create();
|
||||||
try (ProjectConfigUpdate u = updateProject(p)) {
|
try (ProjectConfigUpdate u = updateProject(p)) {
|
||||||
Util.allow(u.getConfig(), Permission.READ, adminGroupUuid(), "refs/*");
|
Util.allow(u.getConfig(), Permission.READ, adminGroupUuid(), "refs/*");
|
||||||
Util.block(u.getConfig(), Permission.READ, REGISTERED_USERS, "refs/*");
|
Util.block(u.getConfig(), Permission.READ, REGISTERED_USERS, "refs/*");
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
|||||||
import com.google.gerrit.acceptance.RestResponse;
|
import com.google.gerrit.acceptance.RestResponse;
|
||||||
import com.google.gerrit.acceptance.TestAccount;
|
import com.google.gerrit.acceptance.TestAccount;
|
||||||
import com.google.gerrit.acceptance.testsuite.group.GroupOperations;
|
import com.google.gerrit.acceptance.testsuite.group.GroupOperations;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.config.AccessCheckInfo;
|
import com.google.gerrit.extensions.api.config.AccessCheckInfo;
|
||||||
import com.google.gerrit.extensions.api.config.AccessCheckInput;
|
import com.google.gerrit.extensions.api.config.AccessCheckInput;
|
||||||
@@ -40,7 +41,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CheckAccessIT extends AbstractDaemonTest {
|
public class CheckAccessIT extends AbstractDaemonTest {
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
@Inject private GroupOperations groupOperations;
|
@Inject private GroupOperations groupOperations;
|
||||||
|
|
||||||
private Project.NameKey normalProject;
|
private Project.NameKey normalProject;
|
||||||
@@ -50,9 +51,9 @@ public class CheckAccessIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
normalProject = createProject("normal");
|
normalProject = projectOperations.newProject().create();
|
||||||
secretProject = createProject("secret");
|
secretProject = projectOperations.newProject().create();
|
||||||
secretRefProject = createProject("secretRef");
|
secretRefProject = projectOperations.newProject().create();
|
||||||
AccountGroup.UUID privilegedGroupUuid =
|
AccountGroup.UUID privilegedGroupUuid =
|
||||||
groupOperations.newGroup().name(name("privilegedGroup")).create();
|
groupOperations.newGroup().name(name("privilegedGroup")).create();
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import static java.util.stream.Collectors.toList;
|
|||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.common.data.SubscribeSection;
|
import com.google.gerrit.common.data.SubscribeSection;
|
||||||
@@ -29,6 +30,7 @@ import com.google.gerrit.server.project.ProjectConfig;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.eclipse.jgit.dircache.DirCache;
|
import org.eclipse.jgit.dircache.DirCache;
|
||||||
import org.eclipse.jgit.dircache.DirCacheBuilder;
|
import org.eclipse.jgit.dircache.DirCacheBuilder;
|
||||||
import org.eclipse.jgit.dircache.DirCacheEditor;
|
import org.eclipse.jgit.dircache.DirCacheEditor;
|
||||||
@@ -57,6 +59,12 @@ import org.junit.Before;
|
|||||||
|
|
||||||
public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
|
public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
|
||||||
|
|
||||||
|
protected TestRepository<?> superRepo;
|
||||||
|
protected Project.NameKey superKey;
|
||||||
|
protected TestRepository<?> subRepo;
|
||||||
|
protected Project.NameKey subKey;
|
||||||
|
@Inject protected ProjectOperations projectOperations;
|
||||||
|
|
||||||
protected SubmitType getSubmitType() {
|
protected SubmitType getSubmitType() {
|
||||||
return cfg.getEnum("project", null, "submitType", SubmitType.MERGE_IF_NECESSARY);
|
return cfg.getEnum("project", null, "submitType", SubmitType.MERGE_IF_NECESSARY);
|
||||||
}
|
}
|
||||||
@@ -109,10 +117,6 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static AtomicInteger contentCounter = new AtomicInteger(0);
|
private static AtomicInteger contentCounter = new AtomicInteger(0);
|
||||||
protected TestRepository<?> superRepo;
|
|
||||||
protected Project.NameKey superKey;
|
|
||||||
protected TestRepository<?> subRepo;
|
|
||||||
protected Project.NameKey subKey;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|||||||
@@ -468,9 +468,9 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@GerritConfig(name = "submodule.verboseSuperprojectUpdate", value = "SUBJECT_ONLY")
|
@GerritConfig(name = "submodule.verboseSuperprojectUpdate", value = "SUBJECT_ONLY")
|
||||||
// The value 195 must tuned to the test environment, and is sensitive to the
|
// The value 110 must tuned to the test environment, and is sensitive to the
|
||||||
// length of the uniquified repository name.
|
// length of the uniquified repository name.
|
||||||
@GerritConfig(name = "submodule.maxCombinedCommitMessageSize", value = "200")
|
@GerritConfig(name = "submodule.maxCombinedCommitMessageSize", value = "110")
|
||||||
public void submoduleSubjectCommitMessageSizeLimit() throws Exception {
|
public void submoduleSubjectCommitMessageSizeLimit() throws Exception {
|
||||||
assume().that(isSubmitWholeTopicEnabled()).isFalse();
|
assume().that(isSubmitWholeTopicEnabled()).isFalse();
|
||||||
testSubmoduleSubjectCommitMessageAndExpectTruncation();
|
testSubmoduleSubjectCommitMessageAndExpectTruncation();
|
||||||
@@ -481,7 +481,6 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
|
|||||||
// Make sure that the commit is created at an earlier timestamp than the submit timestamp.
|
// Make sure that the commit is created at an earlier timestamp than the submit timestamp.
|
||||||
TestTimeUtil.resetWithClockStep(1, SECONDS);
|
TestTimeUtil.resetWithClockStep(1, SECONDS);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
allowMatchingSubmoduleSubscription(
|
allowMatchingSubmoduleSubscription(
|
||||||
subKey, "refs/heads/master", superKey, "refs/heads/master");
|
subKey, "refs/heads/master", superKey, "refs/heads/master");
|
||||||
createSubmoduleSubscription(superRepo, "master", subKey, "master");
|
createSubmoduleSubscription(superRepo, "master", subKey, "master");
|
||||||
|
|||||||
@@ -18,21 +18,25 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class WatchedProjectsIT extends AbstractDaemonTest {
|
public class WatchedProjectsIT extends AbstractDaemonTest {
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
private static final String NEW_PROJECT_NAME = "newProjectAccess";
|
private static final String NEW_PROJECT_NAME = "newProjectAccess";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAndGetWatchedProjects() throws Exception {
|
public void setAndGetWatchedProjects() throws Exception {
|
||||||
String projectName1 = createProject(NEW_PROJECT_NAME).get();
|
String projectName1 = projectOperations.newProject().name(NEW_PROJECT_NAME).create().get();
|
||||||
String projectName2 = createProject(NEW_PROJECT_NAME + "2").get();
|
String projectName2 =
|
||||||
|
projectOperations.newProject().name(NEW_PROJECT_NAME + "2").create().get();
|
||||||
|
|
||||||
List<ProjectWatchInfo> projectsToWatch = new ArrayList<>(2);
|
List<ProjectWatchInfo> projectsToWatch = new ArrayList<>(2);
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ import com.google.gerrit.acceptance.NoHttpd;
|
|||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.acceptance.TestAccount;
|
import com.google.gerrit.acceptance.TestAccount;
|
||||||
import com.google.gerrit.acceptance.TestProjectInput;
|
import com.google.gerrit.acceptance.TestProjectInput;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.TestProjectCreation;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||||
@@ -65,6 +67,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project.NameKey;
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
@@ -120,6 +123,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
@Inject private Submit submitHandler;
|
@Inject private Submit submitHandler;
|
||||||
|
|
||||||
@Inject private IdentifiedUser.GenericFactory userFactory;
|
@Inject private IdentifiedUser.GenericFactory userFactory;
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
@Inject private DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners;
|
@Inject private DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners;
|
||||||
private RegistrationHandle onSubmitValidatorHandle;
|
private RegistrationHandle onSubmitValidatorHandle;
|
||||||
@@ -315,7 +319,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void submitNoPermission() throws Exception {
|
public void submitNoPermission() throws Exception {
|
||||||
// create project where submit is blocked
|
// create project where submit is blocked
|
||||||
Project.NameKey p = createProject("p");
|
Project.NameKey p = projectOperations.newProject().create();
|
||||||
block(p, "refs/*", Permission.SUBMIT, REGISTERED_USERS);
|
block(p, "refs/*", Permission.SUBMIT, REGISTERED_USERS);
|
||||||
|
|
||||||
TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
|
TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
|
||||||
@@ -329,7 +333,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void noSelfSubmit() throws Exception {
|
public void noSelfSubmit() throws Exception {
|
||||||
// create project where submit is blocked for the change owner
|
// create project where submit is blocked for the change owner
|
||||||
Project.NameKey p = createProject("p");
|
Project.NameKey p = projectOperations.newProject().create();
|
||||||
try (ProjectConfigUpdate u = updateProject(p)) {
|
try (ProjectConfigUpdate u = updateProject(p)) {
|
||||||
Util.block(u.getConfig(), Permission.SUBMIT, CHANGE_OWNER, "refs/*");
|
Util.block(u.getConfig(), Permission.SUBMIT, CHANGE_OWNER, "refs/*");
|
||||||
Util.allow(u.getConfig(), Permission.SUBMIT, REGISTERED_USERS, "refs/heads/*");
|
Util.allow(u.getConfig(), Permission.SUBMIT, REGISTERED_USERS, "refs/heads/*");
|
||||||
@@ -355,7 +359,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onlySelfSubmit() throws Exception {
|
public void onlySelfSubmit() throws Exception {
|
||||||
// create project where only the change owner can submit
|
// create project where only the change owner can submit
|
||||||
Project.NameKey p = createProject("p");
|
Project.NameKey p = projectOperations.newProject().create();
|
||||||
try (ProjectConfigUpdate u = updateProject(p)) {
|
try (ProjectConfigUpdate u = updateProject(p)) {
|
||||||
Util.block(u.getConfig(), Permission.SUBMIT, REGISTERED_USERS, "refs/*");
|
Util.block(u.getConfig(), Permission.SUBMIT, REGISTERED_USERS, "refs/*");
|
||||||
Util.allow(u.getConfig(), Permission.SUBMIT, CHANGE_OWNER, "refs/*");
|
Util.allow(u.getConfig(), Permission.SUBMIT, CHANGE_OWNER, "refs/*");
|
||||||
@@ -385,8 +389,10 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
String topic = "test-topic";
|
String topic = "test-topic";
|
||||||
|
|
||||||
// Create test projects
|
// Create test projects
|
||||||
TestRepository<?> repoA = createProjectWithPush("project-a", null, getSubmitType());
|
Project.NameKey keyA = createProjectForPush(null, getSubmitType());
|
||||||
TestRepository<?> repoB = createProjectWithPush("project-b", null, getSubmitType());
|
TestRepository<?> repoA = cloneProject(keyA);
|
||||||
|
Project.NameKey keyB = createProjectForPush(null, getSubmitType());
|
||||||
|
TestRepository<?> repoB = cloneProject(keyB);
|
||||||
|
|
||||||
// Create changes on project-a
|
// Create changes on project-a
|
||||||
PushOneCommit.Result change1 =
|
PushOneCommit.Result change1 =
|
||||||
@@ -419,15 +425,15 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
String topic = "test-topic";
|
String topic = "test-topic";
|
||||||
|
|
||||||
// Create test project
|
// Create test project
|
||||||
String projectName = "project-a";
|
Project.NameKey keyA = createProjectForPush(null, getSubmitType());
|
||||||
TestRepository<?> repoA = createProjectWithPush(projectName, null, getSubmitType());
|
TestRepository<?> repoA = cloneProject(keyA);
|
||||||
|
|
||||||
RevCommit initialHead = getRemoteHead(new Project.NameKey(name(projectName)), "master");
|
RevCommit initialHead = getRemoteHead(keyA, "master");
|
||||||
|
|
||||||
// Create the dev branch on the test project
|
// Create the dev branch on the test project
|
||||||
BranchInput in = new BranchInput();
|
BranchInput in = new BranchInput();
|
||||||
in.revision = initialHead.name();
|
in.revision = initialHead.name();
|
||||||
gApi.projects().name(name(projectName)).branch("dev").create(in);
|
gApi.projects().name(keyA.get()).branch("dev").create(in);
|
||||||
|
|
||||||
// Create changes on master
|
// Create changes on master
|
||||||
PushOneCommit.Result change1 =
|
PushOneCommit.Result change1 =
|
||||||
@@ -769,8 +775,10 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
String topic = "test-topic";
|
String topic = "test-topic";
|
||||||
|
|
||||||
// Create test projects
|
// Create test projects
|
||||||
TestRepository<?> repoA = createProjectWithPush("project-a", null, getSubmitType());
|
Project.NameKey keyA = createProjectForPush(null, getSubmitType());
|
||||||
TestRepository<?> repoB = createProjectWithPush("project-b", null, getSubmitType());
|
TestRepository<?> repoA = cloneProject(keyA);
|
||||||
|
Project.NameKey keyB = createProjectForPush(null, getSubmitType());
|
||||||
|
TestRepository<?> repoB = cloneProject(keyB);
|
||||||
|
|
||||||
// Create changes on project-a
|
// Create changes on project-a
|
||||||
PushOneCommit.Result change1 =
|
PushOneCommit.Result change1 =
|
||||||
@@ -815,15 +823,13 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
submitWithConflict(change4.getChangeId(), "time to fail");
|
submitWithConflict(change4.getChangeId(), "time to fail");
|
||||||
assertThat(projectsCalled).containsExactly(name("project-a"), name("project-b"));
|
assertThat(projectsCalled).containsExactly(keyA.get(), keyB.get());
|
||||||
for (PushOneCommit.Result change : changes) {
|
for (PushOneCommit.Result change : changes) {
|
||||||
change.assertChange(Change.Status.NEW, name(topic), admin);
|
change.assertChange(Change.Status.NEW, name(topic), admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
submit(change4.getChangeId());
|
submit(change4.getChangeId());
|
||||||
assertThat(projectsCalled)
|
assertThat(projectsCalled).containsExactly(keyA.get(), keyB.get(), keyA.get(), keyB.get());
|
||||||
.containsExactly(
|
|
||||||
name("project-a"), name("project-b"), name("project-a"), name("project-b"));
|
|
||||||
for (PushOneCommit.Result change : changes) {
|
for (PushOneCommit.Result change : changes) {
|
||||||
change.assertChange(Change.Status.MERGED, name(topic), admin);
|
change.assertChange(Change.Status.MERGED, name(topic), admin);
|
||||||
}
|
}
|
||||||
@@ -934,8 +940,10 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
|
|
||||||
String topic = "test-topic";
|
String topic = "test-topic";
|
||||||
|
|
||||||
TestRepository<?> repoA = createProjectWithPush("project-a", null, getSubmitType());
|
Project.NameKey keyA = createProjectForPush(null, getSubmitType());
|
||||||
TestRepository<?> repoB = createProjectWithPush("project-b", null, getSubmitType());
|
Project.NameKey keyB = createProjectForPush(null, getSubmitType());
|
||||||
|
TestRepository<?> repoA = cloneProject(keyA);
|
||||||
|
TestRepository<?> repoB = cloneProject(keyB);
|
||||||
|
|
||||||
PushOneCommit.Result change1 =
|
PushOneCommit.Result change1 =
|
||||||
createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
|
createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
|
||||||
@@ -962,13 +970,13 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
|
|
||||||
repoA.git().fetch().call();
|
repoA.git().fetch().call();
|
||||||
RevWalk rwA = repoA.getRevWalk();
|
RevWalk rwA = repoA.getRevWalk();
|
||||||
RevCommit masterA = rwA.parseCommit(getRemoteHead(name("project-a"), "master"));
|
RevCommit masterA = rwA.parseCommit(getRemoteHead(keyA, "master"));
|
||||||
RevCommit change1Ps = parseCurrentRevision(rwA, change1.getChangeId());
|
RevCommit change1Ps = parseCurrentRevision(rwA, change1.getChangeId());
|
||||||
assertThat(rwA.isMergedInto(change1Ps, masterA)).isTrue();
|
assertThat(rwA.isMergedInto(change1Ps, masterA)).isTrue();
|
||||||
|
|
||||||
repoB.git().fetch().call();
|
repoB.git().fetch().call();
|
||||||
RevWalk rwB = repoB.getRevWalk();
|
RevWalk rwB = repoB.getRevWalk();
|
||||||
RevCommit masterB = rwB.parseCommit(getRemoteHead(name("project-b"), "master"));
|
RevCommit masterB = rwB.parseCommit(getRemoteHead(keyB, "master"));
|
||||||
RevCommit change2Ps = parseCurrentRevision(rwB, change2.getChangeId());
|
RevCommit change2Ps = parseCurrentRevision(rwB, change2.getChangeId());
|
||||||
assertThat(rwB.isMergedInto(change2Ps, masterB)).isTrue();
|
assertThat(rwB.isMergedInto(change2Ps, masterB)).isTrue();
|
||||||
|
|
||||||
@@ -1353,12 +1361,18 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestRepository<?> createProjectWithPush(
|
// TODO(hanwen): the submodule tests have a similar method; maybe we could share code?
|
||||||
String name, @Nullable Project.NameKey parent, SubmitType submitType) throws Exception {
|
protected Project.NameKey createProjectForPush(@Nullable NameKey parent, SubmitType submitType)
|
||||||
Project.NameKey project = createProject(name, parent, true, submitType);
|
throws Exception {
|
||||||
|
TestProjectCreation.Builder b =
|
||||||
|
projectOperations.newProject().withEmptyCommit().submitType(submitType);
|
||||||
|
if (parent != null) {
|
||||||
|
b.parent(parent);
|
||||||
|
}
|
||||||
|
Project.NameKey project = b.create();
|
||||||
grant(project, "refs/heads/*", Permission.PUSH);
|
grant(project, "refs/heads/*", Permission.PUSH);
|
||||||
grant(project, "refs/for/refs/heads/*", Permission.SUBMIT);
|
grant(project, "refs/for/refs/heads/*", Permission.SUBMIT);
|
||||||
return cloneProject(project);
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PushOneCommit.Result createChange(
|
protected PushOneCommit.Result createChange(
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
|||||||
import com.google.gerrit.acceptance.GitUtil;
|
import com.google.gerrit.acceptance.GitUtil;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.acceptance.TestProjectInput;
|
import com.google.gerrit.acceptance.TestProjectInput;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||||
@@ -31,6 +32,7 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
|||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
import com.google.gerrit.server.project.testing.Util;
|
import com.google.gerrit.server.project.testing.Util;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||||
import org.eclipse.jgit.junit.TestRepository;
|
import org.eclipse.jgit.junit.TestRepository;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
@@ -43,6 +45,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConfigChangeIT extends AbstractDaemonTest {
|
public class ConfigChangeIT extends AbstractDaemonTest {
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
try (ProjectConfigUpdate u = updateProject(project)) {
|
try (ProjectConfigUpdate u = updateProject(project)) {
|
||||||
@@ -144,8 +148,8 @@ public class ConfigChangeIT extends AbstractDaemonTest {
|
|||||||
public void rejectDoubleInheritance() throws Exception {
|
public void rejectDoubleInheritance() throws Exception {
|
||||||
setApiUser(admin);
|
setApiUser(admin);
|
||||||
// Create separate projects to test the config
|
// Create separate projects to test the config
|
||||||
Project.NameKey parent = createProject("projectToInheritFrom");
|
Project.NameKey parent = createProjectOverAPI("projectToInheritFrom", null, true, null);
|
||||||
Project.NameKey child = createProject("projectWithMalformedConfig");
|
Project.NameKey child = createProjectOverAPI("projectWithMalformedConfig", null, true, null);
|
||||||
|
|
||||||
String config =
|
String config =
|
||||||
gApi.projects()
|
gApi.projects()
|
||||||
|
|||||||
@@ -789,6 +789,6 @@ public class SubmitByMergeIfNecessaryIT extends AbstractSubmitByMerge {
|
|||||||
untarredFiles.add(entry.getName());
|
untarredFiles.add(entry.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertThat(untarredFiles).containsExactly(name("project-name") + ".git");
|
assertThat(untarredFiles).containsExactly(p1.get() + ".git");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.ChangeInput;
|
import com.google.gerrit.extensions.common.ChangeInput;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||||
import org.eclipse.jgit.junit.TestRepository;
|
import org.eclipse.jgit.junit.TestRepository;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -33,11 +35,12 @@ import org.junit.Test;
|
|||||||
public class WorkInProgressByDefaultIT extends AbstractDaemonTest {
|
public class WorkInProgressByDefaultIT extends AbstractDaemonTest {
|
||||||
private Project.NameKey project1;
|
private Project.NameKey project1;
|
||||||
private Project.NameKey project2;
|
private Project.NameKey project2;
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
project1 = createProject("project-1");
|
project1 = projectOperations.newProject().create();
|
||||||
project2 = createProject("project-2", project1);
|
project2 = projectOperations.newProject().parent(project1).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
|
|||||||
Project.NameKey child1_1 = createProject("p1.1", child1);
|
Project.NameKey child1_1 = createProject("p1.1", child1);
|
||||||
Project.NameKey child1_2 = createProject("p1.2", child1);
|
Project.NameKey child1_2 = createProject("p1.2", child1);
|
||||||
|
|
||||||
|
assertThatNameList(gApi.projects().name(child1.get()).children()).isOrdered();
|
||||||
assertThatNameList(gApi.projects().name(child1.get()).children())
|
assertThatNameList(gApi.projects().name(child1.get()).children())
|
||||||
.containsExactly(child1_1, child1_2)
|
.containsExactly(child1_1, child1_2);
|
||||||
.inOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
|||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.Sandboxed;
|
import com.google.gerrit.acceptance.Sandboxed;
|
||||||
import com.google.gerrit.acceptance.TestProjectInput;
|
import com.google.gerrit.acceptance.TestProjectInput;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.projects.ConfigInfo;
|
import com.google.gerrit.extensions.api.projects.ConfigInfo;
|
||||||
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
||||||
@@ -33,6 +34,7 @@ import com.google.gerrit.extensions.common.ProjectInfo;
|
|||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.project.testing.Util;
|
import com.google.gerrit.server.project.testing.Util;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -40,13 +42,14 @@ import org.junit.Test;
|
|||||||
@NoHttpd
|
@NoHttpd
|
||||||
@Sandboxed
|
@Sandboxed
|
||||||
public class ListProjectsIT extends AbstractDaemonTest {
|
public class ListProjectsIT extends AbstractDaemonTest {
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjects() throws Exception {
|
public void listProjects() throws Exception {
|
||||||
Project.NameKey someProject = createProject("some-project");
|
Project.NameKey someProject = createProject("some-project");
|
||||||
assertThatNameList(filter(gApi.projects().list().get()))
|
assertThatNameList(gApi.projects().list().get())
|
||||||
.containsExactly(allProjects, allUsers, project, someProject)
|
.containsExactly(allProjects, allUsers, project, someProject);
|
||||||
.inOrder();
|
assertThatNameList(gApi.projects().list().get()).isOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -59,7 +62,7 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
u.save();
|
u.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThatNameList(filter(gApi.projects().list().get())).doesNotContain(project);
|
assertThatNameList(gApi.projects().list().get()).doesNotContain(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,91 +90,97 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjectsWithLimit() throws Exception {
|
public void listProjectsWithLimit() throws Exception {
|
||||||
for (int i = 0; i < 5; i++) {
|
String pre = "lpwl-someProject";
|
||||||
createProject("someProject" + i);
|
int n = 6;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
projectOperations.newProject().name(pre + i).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
String p = name("");
|
|
||||||
// 5, plus p which was automatically created.
|
|
||||||
int n = 6;
|
|
||||||
for (int i = 1; i <= n + 2; i++) {
|
for (int i = 1; i <= n + 2; i++) {
|
||||||
assertThatNameList(gApi.projects().list().withPrefix(p).withLimit(i).get())
|
assertThatNameList(gApi.projects().list().withPrefix(pre).withLimit(i).get())
|
||||||
.hasSize(Math.min(i, n));
|
.hasSize(Math.min(i, n));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjectsWithPrefix() throws Exception {
|
public void listProjectsWithPrefix() throws Exception {
|
||||||
Project.NameKey someProject = createProject("some-project");
|
// Default for createEmptyCommit should match TestProjectConfig.
|
||||||
Project.NameKey someOtherProject = createProject("some-other-project");
|
Project.NameKey someProject = projectOperations.newProject().name("listtest-p1").create();
|
||||||
createProject("project-awesome");
|
Project.NameKey someOtherProject = projectOperations.newProject().name("listtest-p2").create();
|
||||||
|
projectOperations.newProject().name("other-prefix-project").create();
|
||||||
|
|
||||||
String p = name("some");
|
String p = "listtest";
|
||||||
assertBadRequest(gApi.projects().list().withPrefix(p).withRegex(".*"));
|
assertBadRequest(gApi.projects().list().withPrefix(p).withRegex(".*"));
|
||||||
assertBadRequest(gApi.projects().list().withPrefix(p).withSubstring(p));
|
assertBadRequest(gApi.projects().list().withPrefix(p).withSubstring(p));
|
||||||
assertThatNameList(filter(gApi.projects().list().withPrefix(p).get()))
|
assertThatNameList(gApi.projects().list().withPrefix(p).get())
|
||||||
.containsExactly(someOtherProject, someProject)
|
.containsExactly(someOtherProject, someProject);
|
||||||
.inOrder();
|
p = "notlisttest";
|
||||||
p = name("SOME");
|
assertThatNameList(gApi.projects().list().withPrefix(p).get()).isEmpty();
|
||||||
assertThatNameList(filter(gApi.projects().list().withPrefix(p).get())).isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjectsWithRegex() throws Exception {
|
public void listProjectsWithRegex() throws Exception {
|
||||||
Project.NameKey someProject = createProject("some-project");
|
Project.NameKey someProject = projectOperations.newProject().name("lpwr-some-project").create();
|
||||||
Project.NameKey someOtherProject = createProject("some-other-project");
|
Project.NameKey someOtherProject =
|
||||||
Project.NameKey projectAwesome = createProject("project-awesome");
|
projectOperations.newProject().name("lpwr-some-other-project").create();
|
||||||
|
Project.NameKey projectAwesome =
|
||||||
|
projectOperations.newProject().name("lpwr-project-awesome").create();
|
||||||
|
|
||||||
assertBadRequest(gApi.projects().list().withRegex("[.*"));
|
assertBadRequest(gApi.projects().list().withRegex("[.*"));
|
||||||
assertBadRequest(gApi.projects().list().withRegex(".*").withPrefix("p"));
|
assertBadRequest(gApi.projects().list().withRegex(".*").withPrefix("p"));
|
||||||
assertBadRequest(gApi.projects().list().withRegex(".*").withSubstring("p"));
|
assertBadRequest(gApi.projects().list().withRegex(".*").withSubstring("p"));
|
||||||
|
|
||||||
assertThatNameList(filter(gApi.projects().list().withRegex(".*some").get()))
|
assertThatNameList(gApi.projects().list().withRegex(".*some").get())
|
||||||
.containsExactly(projectAwesome);
|
.containsExactly(projectAwesome);
|
||||||
String r = name("some-project$").replace(".", "\\.");
|
String r = ("lpwr-some-project$").replace(".", "\\.");
|
||||||
assertThatNameList(filter(gApi.projects().list().withRegex(r).get()))
|
assertThatNameList(gApi.projects().list().withRegex(r).get()).containsExactly(someProject);
|
||||||
.containsExactly(someProject);
|
assertThatNameList(gApi.projects().list().withRegex(".*").get())
|
||||||
assertThatNameList(filter(gApi.projects().list().withRegex(".*").get()))
|
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
allProjects, allUsers, project, projectAwesome, someOtherProject, someProject)
|
allProjects, allUsers, project, projectAwesome, someOtherProject, someProject);
|
||||||
.inOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjectsWithStart() throws Exception {
|
public void listProjectsWithStart() throws Exception {
|
||||||
|
String pre = "lpws-";
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
createProject(new Project.NameKey("someProject" + i).get());
|
projectOperations.newProject().name(pre + i).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
String p = name("");
|
List<ProjectInfo> all = gApi.projects().list().withPrefix(pre).get();
|
||||||
List<ProjectInfo> all = gApi.projects().list().withPrefix(p).get();
|
int n = 5;
|
||||||
// 5, plus p which was automatically created.
|
|
||||||
int n = 6;
|
|
||||||
assertThat(all).hasSize(n);
|
assertThat(all).hasSize(n);
|
||||||
assertThatNameList(gApi.projects().list().withPrefix(p).withStart(n - 1).get())
|
assertThatNameList(gApi.projects().list().withPrefix(pre).withStart(n - 1).get())
|
||||||
.containsExactly(new Project.NameKey(Iterables.getLast(all).name));
|
.containsExactly(new Project.NameKey(Iterables.getLast(all).name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjectsWithSubstring() throws Exception {
|
public void listProjectsWithSubstring() throws Exception {
|
||||||
Project.NameKey someProject = createProject("some-project");
|
Project.NameKey someProject = projectOperations.newProject().name("some-project").create();
|
||||||
Project.NameKey someOtherProject = createProject("some-other-project");
|
Project.NameKey someOtherProject =
|
||||||
Project.NameKey projectAwesome = createProject("project-awesome");
|
projectOperations.newProject().name("some-other-project").create();
|
||||||
|
Project.NameKey projectAwesome =
|
||||||
|
projectOperations.newProject().name("project-awesome").create();
|
||||||
|
|
||||||
assertBadRequest(gApi.projects().list().withSubstring("some").withRegex(".*"));
|
assertBadRequest(gApi.projects().list().withSubstring("some").withRegex(".*"));
|
||||||
assertBadRequest(gApi.projects().list().withSubstring("some").withPrefix("some"));
|
assertBadRequest(gApi.projects().list().withSubstring("some").withPrefix("some"));
|
||||||
assertThatNameList(filter(gApi.projects().list().withSubstring("some").get()))
|
assertThatNameList(gApi.projects().list().withSubstring("some").get())
|
||||||
.containsExactly(projectAwesome, someOtherProject, someProject)
|
.containsExactly(projectAwesome, someOtherProject, someProject);
|
||||||
.inOrder();
|
assertThatNameList(gApi.projects().list().withSubstring("SOME").get())
|
||||||
assertThatNameList(filter(gApi.projects().list().withSubstring("SOME").get()))
|
.containsExactly(projectAwesome, someOtherProject, someProject);
|
||||||
.containsExactly(projectAwesome, someOtherProject, someProject)
|
|
||||||
.inOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listProjectsWithTree() throws Exception {
|
public void listProjectsWithTree() throws Exception {
|
||||||
Project.NameKey someParentProject = createProject("some-parent-project");
|
// Default for createEmptyCommit should match TestProjectConfig.
|
||||||
Project.NameKey someChildProject = createProject("some-child-project", someParentProject);
|
Project.NameKey someParentProject =
|
||||||
|
projectOperations.newProject().name("some-parent-project").create();
|
||||||
|
// Default for createEmptyCommit should match TestProjectConfig.
|
||||||
|
Project.NameKey someChildProject =
|
||||||
|
projectOperations
|
||||||
|
.newProject()
|
||||||
|
.name("some-child-project")
|
||||||
|
.parent(someParentProject)
|
||||||
|
.create();
|
||||||
|
|
||||||
Map<String, ProjectInfo> result = gApi.projects().list().withTree(true).getAsMap();
|
Map<String, ProjectInfo> result = gApi.projects().list().withTree(true).getAsMap();
|
||||||
assertThat(result).containsKey(someChildProject.get());
|
assertThat(result).containsKey(someChildProject.get());
|
||||||
@@ -184,9 +193,8 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
gApi.projects().list().withType(FilterType.PERMISSIONS).getAsMap();
|
gApi.projects().list().withType(FilterType.PERMISSIONS).getAsMap();
|
||||||
assertThat(result.keySet()).containsExactly(allProjects.get(), allUsers.get());
|
assertThat(result.keySet()).containsExactly(allProjects.get(), allUsers.get());
|
||||||
|
|
||||||
assertThatNameList(filter(gApi.projects().list().withType(FilterType.ALL).get()))
|
assertThatNameList(gApi.projects().list().withType(FilterType.ALL).get())
|
||||||
.containsExactly(allProjects, allUsers, project)
|
.containsExactly(allProjects, allUsers, project);
|
||||||
.inOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -203,8 +211,7 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
// The hidden project is included because it was not hidden yet.
|
// The hidden project is included because it was not hidden yet.
|
||||||
// The read-only project is included.
|
// The read-only project is included.
|
||||||
assertThatNameList(gApi.projects().list().get())
|
assertThatNameList(gApi.projects().list().get())
|
||||||
.containsExactly(allProjects, allUsers, project, hidden, readonly)
|
.containsExactly(allProjects, allUsers, project, hidden, readonly);
|
||||||
.inOrder();
|
|
||||||
|
|
||||||
// Hide the project
|
// Hide the project
|
||||||
input.state = ProjectState.HIDDEN;
|
input.state = ProjectState.HIDDEN;
|
||||||
@@ -216,18 +223,15 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
// Hidden project is not included in the list
|
// Hidden project is not included in the list
|
||||||
assertThatNameList(gApi.projects().list().get())
|
assertThatNameList(gApi.projects().list().get())
|
||||||
.containsExactly(allProjects, allUsers, project, readonly)
|
.containsExactly(allProjects, allUsers, project, readonly);
|
||||||
.inOrder();
|
|
||||||
|
|
||||||
// ALL filter applies to type, and doesn't include hidden state
|
// ALL filter applies to type, and doesn't include hidden state
|
||||||
assertThatNameList(gApi.projects().list().withType(FilterType.ALL).get())
|
assertThatNameList(gApi.projects().list().withType(FilterType.ALL).get())
|
||||||
.containsExactly(allProjects, allUsers, project, readonly)
|
.containsExactly(allProjects, allUsers, project, readonly);
|
||||||
.inOrder();
|
|
||||||
|
|
||||||
// "All" boolean option causes hidden projects to be included
|
// "All" boolean option causes hidden projects to be included
|
||||||
assertThatNameList(gApi.projects().list().withAll(true).get())
|
assertThatNameList(gApi.projects().list().withAll(true).get())
|
||||||
.containsExactly(allProjects, allUsers, project, hidden, readonly)
|
.containsExactly(allProjects, allUsers, project, hidden, readonly);
|
||||||
.inOrder();
|
|
||||||
|
|
||||||
// "State" option causes only the projects in that state to be included
|
// "State" option causes only the projects in that state to be included
|
||||||
assertThatNameList(gApi.projects().list().withState(ProjectState.HIDDEN).get())
|
assertThatNameList(gApi.projects().list().withState(ProjectState.HIDDEN).get())
|
||||||
@@ -235,8 +239,7 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
assertThatNameList(gApi.projects().list().withState(ProjectState.READ_ONLY).get())
|
assertThatNameList(gApi.projects().list().withState(ProjectState.READ_ONLY).get())
|
||||||
.containsExactly(readonly);
|
.containsExactly(readonly);
|
||||||
assertThatNameList(gApi.projects().list().withState(ProjectState.ACTIVE).get())
|
assertThatNameList(gApi.projects().list().withState(ProjectState.ACTIVE).get())
|
||||||
.containsExactly(allProjects, allUsers, project)
|
.containsExactly(allProjects, allUsers, project);
|
||||||
.inOrder();
|
|
||||||
|
|
||||||
// Cannot use "all" and "state" together
|
// Cannot use "all" and "state" together
|
||||||
assertBadRequest(gApi.projects().list().withAll(true).withState(ProjectState.ACTIVE));
|
assertBadRequest(gApi.projects().list().withAll(true).withState(ProjectState.ACTIVE));
|
||||||
@@ -250,16 +253,4 @@ public class ListProjectsIT extends AbstractDaemonTest {
|
|||||||
// Expected.
|
// Expected.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Iterable<ProjectInfo> filter(Iterable<ProjectInfo> infos) {
|
|
||||||
String prefix = name("");
|
|
||||||
return Iterables.filter(
|
|
||||||
infos,
|
|
||||||
p -> {
|
|
||||||
return p.name != null
|
|
||||||
&& (p.name.equals(allProjects.get())
|
|
||||||
|| p.name.equals(allUsers.get())
|
|
||||||
|| p.name.startsWith(prefix));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.extensions.conditions.BooleanCondition;
|
import com.google.gerrit.extensions.conditions.BooleanCondition;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
@@ -34,6 +35,7 @@ import org.junit.Test;
|
|||||||
public class PermissionBackendConditionIT extends AbstractDaemonTest {
|
public class PermissionBackendConditionIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Inject PermissionBackend pb;
|
@Inject PermissionBackend pb;
|
||||||
|
@Inject ProjectOperations projectOperations;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void globalPermissions_sameUserAndPermissionEquals() throws Exception {
|
public void globalPermissions_sameUserAndPermissionEquals() throws Exception {
|
||||||
@@ -110,7 +112,7 @@ public class PermissionBackendConditionIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void projectPermissions_differentResourceSameUserDoesNotEqual() throws Exception {
|
public void projectPermissions_differentResourceSameUserDoesNotEqual() throws Exception {
|
||||||
Project.NameKey project2 = createProject("p2");
|
Project.NameKey project2 = projectOperations.newProject().create();
|
||||||
BooleanCondition cond1 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
|
BooleanCondition cond1 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
|
||||||
BooleanCondition cond2 = pb.user(user()).project(project2).testCond(ProjectPermission.READ);
|
BooleanCondition cond2 = pb.user(user()).project(project2).testCond(ProjectPermission.READ);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
|||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.acceptance.TestAccount;
|
import com.google.gerrit.acceptance.TestAccount;
|
||||||
|
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.api.changes.StarsInput;
|
import com.google.gerrit.extensions.api.changes.StarsInput;
|
||||||
@@ -32,6 +33,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
|||||||
import com.google.gerrit.server.account.ProjectWatches.NotifyType;
|
import com.google.gerrit.server.account.ProjectWatches.NotifyType;
|
||||||
import com.google.gerrit.server.git.NotifyConfig;
|
import com.google.gerrit.server.git.NotifyConfig;
|
||||||
import com.google.gerrit.testing.FakeEmailSender.Message;
|
import com.google.gerrit.testing.FakeEmailSender.Message;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||||
@@ -40,6 +42,8 @@ import org.junit.Test;
|
|||||||
|
|
||||||
@NoHttpd
|
@NoHttpd
|
||||||
public class ProjectWatchIT extends AbstractDaemonTest {
|
public class ProjectWatchIT extends AbstractDaemonTest {
|
||||||
|
@Inject private ProjectOperations projectOperations;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void newPatchSetsNotifyConfig() throws Exception {
|
public void newPatchSetsNotifyConfig() throws Exception {
|
||||||
Address addr = new Address("Watcher", "watcher@example.com");
|
Address addr = new Address("Watcher", "watcher@example.com");
|
||||||
@@ -210,7 +214,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void watchProject() throws Exception {
|
public void watchProject() throws Exception {
|
||||||
// watch project
|
// watch project
|
||||||
String watchedProject = createProject("watchedProject").get();
|
String watchedProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
watch(watchedProject);
|
watch(watchedProject);
|
||||||
|
|
||||||
@@ -226,7 +230,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
// push a change to non-watched project -> should not trigger email
|
// push a change to non-watched project -> should not trigger email
|
||||||
// notification
|
// notification
|
||||||
String notWatchedProject = createProject("otherProject").get();
|
String notWatchedProject = projectOperations.newProject().create().get();
|
||||||
TestRepository<InMemoryRepository> notWatchedRepo =
|
TestRepository<InMemoryRepository> notWatchedRepo =
|
||||||
cloneProject(new Project.NameKey(notWatchedProject), admin);
|
cloneProject(new Project.NameKey(notWatchedProject), admin);
|
||||||
r =
|
r =
|
||||||
@@ -246,8 +250,8 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchFile() throws Exception {
|
public void watchFile() throws Exception {
|
||||||
String watchedProject = createProject("watchedProject").get();
|
String watchedProject = projectOperations.newProject().create().get();
|
||||||
String otherWatchedProject = createProject("otherWatchedProject").get();
|
String otherWatchedProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|
||||||
// watch file in project as user
|
// watch file in project as user
|
||||||
@@ -300,7 +304,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchKeyword() throws Exception {
|
public void watchKeyword() throws Exception {
|
||||||
String watchedProject = createProject("watchedProject").get();
|
String watchedProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|
||||||
// watch keyword in project as user
|
// watch keyword in project as user
|
||||||
@@ -339,7 +343,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchAllProjects() throws Exception {
|
public void watchAllProjects() throws Exception {
|
||||||
String anyProject = createProject("anyProject").get();
|
String anyProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|
||||||
// watch the All-Projects project to watch all projects
|
// watch the All-Projects project to watch all projects
|
||||||
@@ -366,7 +370,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchFileAllProjects() throws Exception {
|
public void watchFileAllProjects() throws Exception {
|
||||||
String anyProject = createProject("anyProject").get();
|
String anyProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|
||||||
// watch file in All-Projects project as user to watch the file in all
|
// watch file in All-Projects project as user to watch the file in all
|
||||||
@@ -417,7 +421,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchKeywordAllProjects() throws Exception {
|
public void watchKeywordAllProjects() throws Exception {
|
||||||
String anyProject = createProject("anyProject").get();
|
String anyProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|
||||||
// watch keyword in project as user
|
// watch keyword in project as user
|
||||||
@@ -458,7 +462,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void watchProjectNoNotificationForIgnoredChange() throws Exception {
|
public void watchProjectNoNotificationForIgnoredChange() throws Exception {
|
||||||
// watch project
|
// watch project
|
||||||
String watchedProject = createProject("watchedProject").get();
|
String watchedProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
watch(watchedProject);
|
watch(watchedProject);
|
||||||
|
|
||||||
@@ -491,7 +495,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void watchProjectNoNotificationForPrivateChange() throws Exception {
|
public void watchProjectNoNotificationForPrivateChange() throws Exception {
|
||||||
// watch project
|
// watch project
|
||||||
String watchedProject = createProject("watchedProject").get();
|
String watchedProject = projectOperations.newProject().create().get();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
watch(watchedProject);
|
watch(watchedProject);
|
||||||
|
|
||||||
@@ -511,7 +515,7 @@ public class ProjectWatchIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchProjectNotifyOnPrivateChange() throws Exception {
|
public void watchProjectNotifyOnPrivateChange() throws Exception {
|
||||||
String watchedProject = createProject("watchedProject").get();
|
String watchedProject = projectOperations.newProject().create().get();
|
||||||
|
|
||||||
// create group that can view all private changes
|
// create group that can view all private changes
|
||||||
GroupInfo groupThatCanViewPrivateChanges =
|
GroupInfo groupThatCanViewPrivateChanges =
|
||||||
|
|||||||
Reference in New Issue
Block a user