Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Workaround problem with moving files on a federation losing properties
  • Loading branch information
escowles committed Jul 11, 2014
1 parent dd6050b commit 704fc8f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Expand Up @@ -1636,4 +1636,45 @@ public void testLinkedDeletion() throws Exception {
assertEquals("Linked to should still exist!", 200, getStatus(get));
}

/**
* I should be able to move a node within a federated filesystem with
* properties preserved.
**/
@Test
public void testFederatedMoveWithProperties() throws Exception {
// create object on federation
final String pid = getRandomUniquePid();
final String source = serverAddress + "files/" + pid + "/src";
createObject("files/" + pid + "/src");

// add properties
final HttpPatch patch = new HttpPatch(source);
patch.addHeader("Content-Type", "application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();
final String sparql = "insert { <> <http://purl.org/dc/elements/1.1/identifier> \"identifier.123\" . "
+ "<> <http://purl.org/dc/elements/1.1/title> \"title.123\" } where {}";
e.setContent(new ByteArrayInputStream(sparql.getBytes()));
patch.setEntity(e);
final HttpResponse response = client.execute(patch);
assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode());

// move object
final String destination = serverAddress + "files/" + pid + "/dst";
final HttpMove request = new HttpMove(source);
request.addHeader("Destination", destination);
final HttpResponse moveRequest = client.execute(request);
assertEquals(CREATED.getStatusCode(), moveRequest.getStatusLine().getStatusCode());

// check properties
final HttpGet get = new HttpGet(destination);
get.addHeader("Accept", "application/n-triples");
final GraphStore graphStore = getGraphStore(get);
assertTrue(graphStore.contains(Node.ANY, NodeFactory.createURI(destination),
NodeFactory.createURI("http://purl.org/dc/elements/1.1/identifier"),
NodeFactory.createLiteral("identifier.123")));
assertTrue(graphStore.contains(Node.ANY, NodeFactory.createURI(destination),
NodeFactory.createURI("http://purl.org/dc/elements/1.1/title"),
NodeFactory.createLiteral("title.123")));
}

}
Expand Up @@ -190,7 +190,8 @@ public void copyObject(final Session session, final String source, final String
@Override
public void moveObject(final Session session, final String source, final String destination)
throws RepositoryException {
session.getWorkspace().move(source, destination);
session.getWorkspace().copy(source, destination);
deleteObject(session, source);
}

/**
Expand Down
Expand Up @@ -130,8 +130,17 @@ public void testCopyObject() throws RepositoryException {
@Test
public void testMoveObject() throws RepositoryException {
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
final Node mockObjectsNode = mock(Node.class);
when(mockSession.getRootNode()).thenReturn(mockRoot);
when(mockRoot.getNode("objects")).thenReturn(mockObjectsNode);
when(mockSession.getNode("foo")).thenReturn(mockObjNode);
when(mockObjNode.getReferences()).thenReturn(mockEmptyIterator);
mockStatic(ServiceHelpers.class);

testObj.moveObject(mockSession, "foo", "bar");
verify(mockWorkspace).move("foo", "bar");
verify(mockWorkspace).copy("foo", "bar");
verify(mockSession).getNode("foo");
verify(mockObjNode).remove();
}

@Test
Expand Down

0 comments on commit 704fc8f

Please sign in to comment.