Skip to content

Commit

Permalink
Merge pull request #157 from futures/http-fixes
Browse files Browse the repository at this point in the history
Return a 404 Not Found when deleting a workspace that doesn't exist.
  • Loading branch information
Andrew Woods committed Nov 19, 2013
2 parents e5ba8d6 + 3f841c7 commit 9eaac0f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Expand Up @@ -49,6 +49,8 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.NotFoundException;
import org.fcrepo.http.api.FedoraNodes;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
Expand Down Expand Up @@ -162,6 +164,11 @@ public Response createWorkspace(@PathParam("path") final String path,
public Response deleteWorkspace(@PathParam("path") final String path) throws RepositoryException {
try {
final Workspace workspace = session.getWorkspace();

if (!ImmutableSet.copyOf(workspace.getAccessibleWorkspaceNames()).contains(path)) {
throw new NotFoundException();
}

workspace.deleteWorkspace(path);

return noContent().build();
Expand Down
Expand Up @@ -33,6 +33,7 @@
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import com.sun.jersey.api.NotFoundException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand Down Expand Up @@ -126,8 +127,16 @@ public void testCreateWorkspace() throws Exception {

@Test
public void testDeleteWorkspace() throws Exception {
when(mockWorkspace.getAccessibleWorkspaceNames()).thenReturn(new String[] { "xxx" });
final Response response = workspaces.deleteWorkspace("xxx");
verify(mockWorkspace).deleteWorkspace("xxx");
assertEquals(204, response.getStatus());
}

@Test(expected = NotFoundException.class)
public void testDeleteMissingWorkspace() throws Exception {
when(mockWorkspace.getAccessibleWorkspaceNames()).thenReturn(new String[] { "yyy" });
final Response response = workspaces.deleteWorkspace("xxx");
assertEquals(404, response.getStatus());
}
}
Expand Up @@ -34,6 +34,7 @@
import org.junit.Test;

import com.hp.hpl.jena.update.GraphStore;
import org.w3c.dom.ElementTraversal;

public class FedoraWorkspacesIT extends AbstractResourceIT {

Expand Down Expand Up @@ -100,4 +101,16 @@ public void shouldCreateAndDeleteWorkspace() throws IOException {
.getStatusCode());

}

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

final HttpResponse deleteWorkspaceResponse =
execute(httpDeleteWorkspace);

assertEquals(404, deleteWorkspaceResponse.getStatusLine()
.getStatusCode());

}
}

0 comments on commit 9eaac0f

Please sign in to comment.