Skip to content

Commit

Permalink
Merge pull request #369 from fcrepo4/workspace-existing-conflict
Browse files Browse the repository at this point in the history
Trying to create an existing workspace now results in 409 Conflict
  • Loading branch information
Andrew Woods committed May 20, 2014
2 parents b53b4dd + 1d80c62 commit 64ec11f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -22,6 +22,8 @@
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES;
Expand Down Expand Up @@ -117,6 +119,12 @@ public Response createWorkspace(@PathParam("path") final String path,
.build());
}

final String[] workspaceNames = workspace.getAccessibleWorkspaceNames();
if ( workspaceNames != null && ImmutableSet.copyOf(workspaceNames).contains(path)) {
throw new WebApplicationException(
status(CONFLICT).entity("Workspace already exists").build());
}

workspace.createWorkspace(path);

final IdentifierTranslator subjects =
Expand Down
Expand Up @@ -95,6 +95,17 @@ public void shouldCreateAndDeleteWorkspace() throws IOException {

}

@Test
public void shouldConflictWhenCreatingExisting() throws IOException {
final String workspace = randomUUID().toString();

final HttpPost httpCreateWorkspace =
new HttpPost(serverAddress + "fcr:workspaces/" + workspace);
assertEquals(201, getStatus(httpCreateWorkspace));

assertEquals(409, getStatus(httpCreateWorkspace));
}

@Test
public void shouldBe404WhenDeletingJunkWorkspace() throws IOException {
final HttpDelete httpDeleteWorkspace = new HttpDelete(serverAddress + "fcr:workspaces/junk");
Expand Down

0 comments on commit 64ec11f

Please sign in to comment.