Check preconditions when setting parent project through REST

Only update the parent project if the new parent project exists and if
setting this parent doesn't introduce a cycle in the line of projects.
Never set a parent project for the All-Projects root project.

Change-Id: I9caec6921d46f8205febdacb31f52bd6c21f28c8
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-10-17 13:49:32 +02:00
parent 0f07b86d75
commit 42f7bc3323
2 changed files with 82 additions and 7 deletions

View File

@@ -24,6 +24,8 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.acceptance.RestSession;
import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.acceptance.TestAccount;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.config.AllProjectsNameProvider;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
@@ -42,6 +44,9 @@ public class SetParentIT extends AbstractDaemonTest {
@Inject
private AccountCreator accounts;
@Inject
private AllProjectsNameProvider allProjects;
private RestSession adminSession;
private RestSession userSession;
private SshSession sshSession;
@@ -98,6 +103,47 @@ public class SetParentIT extends AbstractDaemonTest {
r.consume();
}
@Test
public void setParentForAllProjects_Conflict() throws IOException {
RestResponse r =
adminSession.put("/projects/" + allProjects.get() + "/parent",
new ParentInput(project));
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
r.consume();
}
@Test
public void setInvalidParent_Conflict() throws IOException, JSchException {
RestResponse r =
adminSession.put("/projects/" + project + "/parent",
new ParentInput(project));
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
r.consume();
String child = "child";
createProject(sshSession, child, new Project.NameKey(project), true);
r = adminSession.put("/projects/" + project + "/parent",
new ParentInput(child));
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
r.consume();
String grandchild = "grandchild";
createProject(sshSession, grandchild, new Project.NameKey(child), true);
r = adminSession.put("/projects/" + project + "/parent",
new ParentInput(grandchild));
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
r.consume();
}
@Test
public void setNonExistingParent_UnprocessibleEntity() throws IOException {
RestResponse r =
adminSession.put("/projects/" + project + "/parent",
new ParentInput("non-existing"));
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, r.getStatusCode());
r.consume();
}
@SuppressWarnings("unused")
private static class ParentInput {
String parent;