Search in sources :

Example 1 with ProjectInput

use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.

the class ConfigChangeIT method onlyAdminMayUpdateProjectParent.

@Test
@TestProjectInput(cloneAs = "user")
public void onlyAdminMayUpdateProjectParent() throws Exception {
    setApiUser(admin);
    ProjectInput parent = new ProjectInput();
    parent.name = name("parent");
    parent.permissionsOnly = true;
    gApi.projects().create(parent);
    setApiUser(user);
    Config cfg = readProjectConfig();
    assertThat(cfg.getString("access", null, "inheritFrom")).isAnyOf(null, allProjects.get());
    cfg.setString("access", null, "inheritFrom", parent.name);
    PushOneCommit.Result r = createConfigChange(cfg);
    String id = r.getChangeId();
    gApi.changes().id(id).current().review(ReviewInput.approve());
    try {
        gApi.changes().id(id).current().submit();
        fail("expected submit to fail");
    } catch (ResourceConflictException e) {
        int n = gApi.changes().id(id).info()._number;
        assertThat(e).hasMessageThat().isEqualTo("Failed to submit 1 change due to the following problems:\n" + "Change " + n + ": Change contains a project configuration that" + " changes the parent project.\n" + "The change must be submitted by a Gerrit administrator.");
    }
    assertThat(gApi.projects().name(project.get()).get().parent).isEqualTo(allProjects.get());
    fetchRefsMetaConfig();
    assertThat(readProjectConfig().getString("access", null, "inheritFrom")).isAnyOf(null, allProjects.get());
    setApiUser(admin);
    gApi.changes().id(id).current().submit();
    assertThat(gApi.changes().id(id).info().status).isEqualTo(ChangeStatus.MERGED);
    assertThat(gApi.projects().name(project.get()).get().parent).isEqualTo(parent.name);
    fetchRefsMetaConfig();
    assertThat(readProjectConfig().getString("access", null, "inheritFrom")).isEqualTo(parent.name);
}
Also used : TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Config(org.eclipse.jgit.lib.Config) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with ProjectInput

use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.

the class ProjectIT method createProjectDuplicate.

@Test
public void createProjectDuplicate() throws Exception {
    ProjectInput in = new ProjectInput();
    in.name = name("baz");
    gApi.projects().create(in);
    exception.expect(ResourceConflictException.class);
    exception.expectMessage("Project already exists");
    gApi.projects().create(in);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with ProjectInput

use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.

the class ProjectIT method createProjectWithInitialCommit.

@Test
public void createProjectWithInitialCommit() throws Exception {
    String name = name("foo");
    ProjectInput input = new ProjectInput();
    input.name = name;
    input.createEmptyCommit = true;
    assertThat(name).isEqualTo(gApi.projects().create(input).get().name);
    RevCommit head = getRemoteHead(name, RefNames.REFS_CONFIG);
    eventRecorder.assertRefUpdatedEvents(name, RefNames.REFS_CONFIG, null, head);
    head = getRemoteHead(name, "refs/heads/master");
    eventRecorder.assertRefUpdatedEvents(name, "refs/heads/master", null, head);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with ProjectInput

use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.

the class CreateProjectIT method createChildProjectUnderNonExistingParent_UnprocessableEntity.

@Test
public void createChildProjectUnderNonExistingParent_UnprocessableEntity() throws Exception {
    ProjectInput in = new ProjectInput();
    in.name = name("newProjectName");
    in.parent = "non-existing-project";
    assertCreateFails(in, UnprocessableEntityException.class);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with ProjectInput

use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.

the class CreateProjectIT method createChildProject.

@Test
public void createChildProject() throws Exception {
    String parentName = name("parent");
    ProjectInput in = new ProjectInput();
    in.name = parentName;
    gApi.projects().create(in);
    String childName = name("child");
    in = new ProjectInput();
    in.name = childName;
    in.parent = parentName;
    gApi.projects().create(in);
    Project project = projectCache.get(new Project.NameKey(childName)).getProject();
    assertThat(project.getParentName()).isEqualTo(in.parent);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ProjectInput (com.google.gerrit.extensions.api.projects.ProjectInput)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 Test (org.junit.Test)19 Project (com.google.gerrit.reviewdb.client.Project)6 ProjectAssert.assertProjectInfo (com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo)3 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1