Skip to content

Commit

Permalink
Also fixing COPY method
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed May 19, 2014
1 parent b7ebc7a commit ca593fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -767,8 +767,11 @@ public Response copyObject(@PathParam("path") final List<PathSegment> path,

if (destination == null) {
return status(SC_BAD_GATEWAY).entity("Destination was not a valid resource path").build();
} else if (nodeService.exists(session, destination)) {
return status(SC_PRECONDITION_FAILED).entity("Destination resource already exists").build();
}


nodeService.copyObject(session, toPath(path), destination);
session.save();
versionService.nodeUpdated(session, destination);
Expand Down Expand Up @@ -819,9 +822,7 @@ public Response moveObject(@PathParam("path") final List<PathSegment> pathList,

if (destination == null) {
return status(SC_BAD_GATEWAY).entity("Destination was not a valid resource path").build();
}

if (nodeService.exists(session, destination)) {
} else if (nodeService.exists(session, destination)) {
return status(SC_PRECONDITION_FAILED).entity("Destination resource already exists").build();
}

Expand Down
Expand Up @@ -1050,6 +1050,21 @@ public void testCopy() throws Exception {
assertEquals(OK.getStatusCode(), originalResult.getStatusLine().getStatusCode());
}

@Test
public void testCopyDestExists() throws Exception {

final HttpResponse response1 = createObject("");
final String location1 = response1.getFirstHeader("Location").getValue();
final HttpResponse response2 = createObject("");
final String location2 = response2.getFirstHeader("Location").getValue();

final HttpCopy request = new HttpCopy(location1);
request.addHeader("Destination", location2);
final HttpResponse result = client.execute(request);

assertEquals(PRECONDITION_FAILED.getStatusCode(), result.getStatusLine().getStatusCode());
}

@Test
public void testMove() throws Exception {

Expand Down

0 comments on commit ca593fe

Please sign in to comment.