diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/project/ProjectIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/project/ProjectIT.java index d3187fc9a2..9b24922cbb 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/project/ProjectIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/project/ProjectIT.java @@ -20,6 +20,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.extensions.api.projects.BranchInput; import com.google.gerrit.extensions.api.projects.ProjectInput; +import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestApiException; import org.eclipse.jgit.api.errors.GitAPIException; @@ -50,6 +51,18 @@ public class ProjectIT extends AbstractDaemonTest { .create(in); } + @Test(expected = ResourceConflictException.class) + public void createProjectDuplicate() throws RestApiException { + ProjectInput in = new ProjectInput(); + in.name = "baz"; + gApi.projects() + .name("baz") + .create(in); + gApi.projects() + .name("baz") + .create(in); + } + @Test public void createBranch() throws GitAPIException, IOException, RestApiException { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java index 4086011824..b2a1244367 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java @@ -96,6 +96,9 @@ public class ProjectApiImpl implements ProjectApi { @Override public ProjectApi create(ProjectInput in) throws RestApiException { try { + if (name == null) { + throw new ResourceConflictException("Project already exists"); + } if (in.name != null && !name.equals(in.name)) { throw new RestApiException("name must match input.name"); } @@ -103,8 +106,8 @@ public class ProjectApiImpl implements ProjectApi { .apply(TopLevelResource.INSTANCE, in); return projectApi.create(projects.parse(name)); } catch (BadRequestException | UnprocessableEntityException - | ResourceConflictException | ResourceNotFoundException - | ProjectCreationFailedException | IOException e) { + | ResourceNotFoundException | ProjectCreationFailedException + | IOException e) { throw new RestApiException("Cannot create project", e); } }