Skip to content
Permalink
Browse files

Fixing versioning check when reverting versions of non-RDF resources

  • Loading branch information...
escowles committed Oct 28, 2014
1 parent 9b27b81 commit 171840199dc425fe3a1a31625b3015a772fbd8a9
@@ -18,6 +18,7 @@
import com.google.common.annotations.VisibleForTesting;
import org.fcrepo.http.commons.domain.PATCH;
import org.fcrepo.http.commons.domain.Prefer;
import org.fcrepo.kernel.FedoraBinary;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
@@ -109,7 +110,7 @@ private void postConstruct() {
public Response revertToVersion() throws RepositoryException {
LOGGER.info("Reverting {} to version {}.", path,
label);
versionService.revertToVersion(session, unversionedResource().getPath(), label);
versionService.revertToVersion(session, unversionedResourcePath(), label);
return noContent().build();
}

@@ -121,7 +122,7 @@ public Response revertToVersion() throws RepositoryException {
@DELETE
public Response removeVersion() throws RepositoryException {
LOGGER.info("Removing {} version {}.", path, label);
versionService.removeVersion(session, unversionedResource().getPath(), label);
versionService.removeVersion(session, unversionedResourcePath(), label);
return noContent().build();
}

@@ -146,13 +147,16 @@ public Response getVersion(@HeaderParam("Prefer") final Prefer prefer,
return getContent(prefer, rangeValue, rdfStream);
}

protected FedoraResource unversionedResource() {
protected String unversionedResourcePath() throws RepositoryException {

if (baseResource == null) {
baseResource = getResourceFromPath(externalPath);
if ( baseResource instanceof FedoraBinary ) {
return baseResource.getNode().getParent().getPath();
}
}

return baseResource;
return baseResource.getPath();
}

@Override
@@ -99,29 +99,29 @@ public void setUp() throws Exception {

@Test
public void testRevertToVersion() throws RepositoryException {
doReturn(mockResource).when(testObj).unversionedResource();
doReturn(path).when(testObj).unversionedResourcePath();
final Response response = testObj.revertToVersion();
verify(mockVersions).revertToVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

@Test (expected = PathNotFoundException.class)
public void testRevertToVersionFailure() throws RepositoryException {
doThrow(PathNotFoundException.class).when(testObj).unversionedResource();
doThrow(PathNotFoundException.class).when(testObj).unversionedResourcePath();
testObj.revertToVersion();
}

@Test
public void testRemoveVersion() throws RepositoryException {
doReturn(mockResource).when(testObj).unversionedResource();
doReturn(path).when(testObj).unversionedResourcePath();
final Response response = testObj.removeVersion();
verify(mockVersions).removeVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

@Test (expected = PathNotFoundException.class)
public void testRemoveVersionFailure() throws RepositoryException {
doThrow(PathNotFoundException.class).when(testObj).unversionedResource();
doThrow(PathNotFoundException.class).when(testObj).unversionedResourcePath();
testObj.removeVersion();
}

@@ -394,34 +394,47 @@ public void testVersionOperationAddsVersionableMixin() throws Exception {
}

@Test
public void testDatastreamAutoMixin() throws IOException {
public void testDatastreamAutoMixinAndRevert() throws IOException {
final String pid = getRandomUniquePid();
final String dsid = "ds1";
createObject(pid);

createDatastream(pid, "ds1", "This is some datastream content");
final String originalContent = "This is the original content";
final String versionLabel = "ver1";
createDatastream(pid, dsid, originalContent);

// datastream should not have fcr:versions endpoint
assertEquals(404, getStatus(new HttpGet(serverAddress + pid + "/ds1/fcr:versions")));
assertEquals(404, getStatus(new HttpGet(serverAddress + pid + "/" + dsid + "/fcr:versions")));

// datastream should not be versionable
final GraphStore originalObjectProperties = getContent(serverAddress + pid + "/ds1/fcr:metadata");
final GraphStore originalObjectProperties = getContent(serverAddress + pid + "/" + dsid + "/fcr:metadata");
assertFalse("Node must not have versionable mixin.",
originalObjectProperties.contains(ANY, createResource(serverAddress + pid + "/ds1").asNode(),
originalObjectProperties.contains(ANY, createResource(serverAddress + pid + "/" + dsid).asNode(),
createURI(RDF_TYPE), createURI(MIX_NAMESPACE + "versionable")));

// creating a version should succeed
final HttpPost httpPost = new HttpPost(serverAddress + pid + "/ds1/fcr:versions");
httpPost.setHeader("Slug", "label");
final HttpPost httpPost = new HttpPost(serverAddress + pid + "/" + dsid + "/fcr:versions");
httpPost.setHeader("Slug", versionLabel);
assertEquals( 204, getStatus(httpPost));

// datastream should then have versions endpoint
assertEquals( 200, getStatus(new HttpGet(serverAddress + pid + "/ds1/fcr:versions")) );
assertEquals( 200, getStatus(new HttpGet(serverAddress + pid + "/" + dsid + "/fcr:versions")) );

// datastream should then be versionable
final GraphStore updatedDSProperties = getContent(serverAddress + pid + "/ds1/fcr:metadata");
final GraphStore updatedDSProperties = getContent(serverAddress + pid + "/" + dsid + "/fcr:metadata");
assertTrue("Node must have versionable mixin.",
updatedDSProperties.contains(ANY, createResource(serverAddress + pid + "/ds1/fcr:metadata").asNode(),
createURI(RDF_TYPE), createURI(MIX_NAMESPACE + "versionable")));
updatedDSProperties.contains(ANY,
createResource(serverAddress + pid + "/" + dsid + "/fcr:metadata").asNode(),
createURI(RDF_TYPE), createURI(MIX_NAMESPACE + "versionable")));

// update the content
final String updatedContent = "This is the updated content";
execute(putDSMethod(pid,dsid,updatedContent));
assertEquals( updatedContent, EntityUtils.toString(execute(getDSMethod(pid, dsid)).getEntity()) );

// revert to the original content
revertToVersion(pid + "/" + dsid, versionLabel);
assertEquals( originalContent, EntityUtils.toString(execute(getDSMethod(pid, dsid)).getEntity()) );
}


0 comments on commit 1718401

Please sign in to comment.
You can’t perform that action at this time.