Skip to content

Commit

Permalink
Disable automatic versioning by default
Browse files Browse the repository at this point in the history
- Remove mix:versionable from fedora:resource definition
- Add integration tests for copying between repo and federated filesystem
- Use FedoraFileSystemConnector instead of Modeshape's in HTTP API tests
- Remove HTTP API dependency from FedoraFileSsytemConnector to prevent circular dependency

Resolves both: https://www.pivotaltracker.com/story/show/67663658 , and
               https://www.pivotaltracker.com/story/show/65600152
  • Loading branch information
escowles authored and Andrew Woods committed Mar 19, 2014
1 parent 45a169f commit c2e8e5f
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 29 deletions.
7 changes: 0 additions & 7 deletions fcrepo-connector-file/pom.xml
Expand Up @@ -21,13 +21,6 @@
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions fcrepo-http-api/pom.xml
Expand Up @@ -30,6 +30,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-connector-file</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-serialization</artifactId>
Expand Down
Expand Up @@ -19,11 +19,13 @@
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import static org.fcrepo.http.commons.test.util.TestHelpers.parseTriples;
import static org.junit.Assert.assertEquals;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

Expand All @@ -35,6 +37,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -180,4 +183,20 @@ protected HttpResponse setProperty(final String pid, final String txId,
return dcResp;
}

protected static void addMixin(final String pid, final String mixinUrl) throws IOException {
final HttpPatch updateObjectGraphMethod =
new HttpPatch(serverAddress + pid);
updateObjectGraphMethod.addHeader("Content-Type",
"application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();

e.setContent(new ByteArrayInputStream(
("INSERT DATA { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + mixinUrl + "> . } ")
.getBytes()));
updateObjectGraphMethod.setEntity(e);
final HttpResponse response = client.execute(updateObjectGraphMethod);
assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine()
.getStatusCode());
}

}
Expand Up @@ -372,6 +372,7 @@ public void verifyFullSetOfRdfTypes() throws Exception {
logger.debug("Entering verifyFullSetOfRdfTypes()...");
final String pid = "FedoraGraphWithRdfTypes";
createObject(pid);
addMixin( "FedoraGraphWithRdfTypes", MIX_NAMESPACE + "versionable" );

final HttpGet getObjMethod =
new HttpGet(serverAddress + pid);
Expand Down Expand Up @@ -984,4 +985,86 @@ public String getMethod() {
}

}

/**
* I should be able to upload a file to a read/write federated filesystem.
**/
@Test
public void testUploadToProjection() throws IOException {
// upload file to federated filesystem using rest api
final String uploadLocation = serverAddress + "files/upload/ds1/fcr:content";
final String uploadContent = "abc123";
logger.debug("Uploading to federated filesystem via rest api: " + uploadLocation);
final HttpPost post = postDSMethod("files/upload", "ds1", uploadContent);
final HttpResponse response = client.execute(post);
assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode());
final String actualLocation = response.getFirstHeader("Location").getValue();
assertEquals("Wrong URI in Location header", uploadLocation, actualLocation);

// validate content
final HttpGet get = new HttpGet(uploadLocation);
final HttpResponse getResponse = client.execute(get);
final String actualContent = EntityUtils.toString( getResponse.getEntity() );
assertEquals(OK.getStatusCode(), getResponse.getStatusLine().getStatusCode());
assertEquals("Content doesn't match", actualContent, uploadContent);

// validate object profile
final HttpGet objGet = new HttpGet(serverAddress + "files/upload");
final HttpResponse objResponse = client.execute(objGet);
assertEquals(OK.getStatusCode(), objResponse.getStatusLine().getStatusCode());
}

/**
* I should be able to copy objects from the repository to a federated filesystem.
**/
@Test
public void testCopyToProjection() throws IOException {
// create object in the repository
final HttpPost post = postDSMethod("repoObject", "ds1", "abc123");
final HttpResponse response = client.execute(post);
assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode());

// copy to federated filesystem
final HttpCopy request = new HttpCopy(serverAddress + "repoObject");
request.addHeader("Destination", serverAddress + "files/projCopy");
final HttpResponse copyResponse = client.execute(request);
assertEquals(CREATED.getStatusCode(), copyResponse.getStatusLine().getStatusCode());

// federated copy should now exist
final HttpGet copyGet = new HttpGet(serverAddress + "files/projCopy");
final HttpResponse copiedResult = client.execute(copyGet);
assertEquals(OK.getStatusCode(), copiedResult.getStatusLine().getStatusCode());

// repository copy should still exist
final HttpGet originalGet = new HttpGet(serverAddress + "repoObject");
final HttpResponse originalResult = client.execute(originalGet);
assertEquals(OK.getStatusCode(), originalResult.getStatusLine().getStatusCode());
}

/**
* I should be able to copy objects from a federated filesystem to the repository.
**/
@Test
public void testCopyFromProjection() throws IOException {
// create object in federated filesystem
final HttpPost post = postDSMethod("files/projObject", "ds1", "abc123");
final HttpResponse response = client.execute(post);
assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode());

// copy to repository
final HttpCopy request = new HttpCopy(serverAddress + "files/projObject");
request.addHeader("Destination", serverAddress + "repoCopy");
client.execute(request);

// repository copy should now exist
final HttpGet copyGet = new HttpGet(serverAddress + "repoCopy");
final HttpResponse copiedResult = client.execute(copyGet);
assertEquals(OK.getStatusCode(), copiedResult.getStatusLine().getStatusCode());

// federated filesystem copy should still exist
final HttpGet originalGet = new HttpGet(serverAddress + "files/projObject");
final HttpResponse originalResult = client.execute(originalGet);
assertEquals(OK.getStatusCode(), originalResult.getStatusLine().getStatusCode());
}

}
Expand Up @@ -49,6 +49,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION;
import static org.fcrepo.kernel.RdfLexicon.VERSIONING_POLICY;
import static org.fcrepo.kernel.RdfLexicon.MIX_NAMESPACE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -61,6 +62,7 @@ public void testGetObjectVersionProfile() throws Exception {
final String pid = UUID.randomUUID().toString();

createObject(pid);
addMixin( pid, MIX_NAMESPACE + "versionable" );
final HttpGet getVersion =
new HttpGet(serverAddress + pid + "/fcr:versions");
logger.debug("Retrieved version profile:");
Expand All @@ -74,6 +76,7 @@ public void testGetObjectVersionProfile() throws Exception {
public void testAddAndRetrieveVersion() throws Exception {
final String pid = UUID.randomUUID().toString();
createObject(pid);
addMixin( pid, MIX_NAMESPACE + "versionable" );

logger.info("Setting a title");
patchLiteralProperty(serverAddress + pid, "http://purl.org/dc/elements/1.1/title", "First Title");
Expand Down Expand Up @@ -102,6 +105,7 @@ public void testAddAndRetrieveVersion() throws Exception {
public void testVersioningANodeWithAVersionableChild() throws Exception {
final String pid = UUID.randomUUID().toString();
createObject(pid);
addMixin( pid, MIX_NAMESPACE + "versionable" );

logger.info("Adding a child");
createDatastream(pid, "ds", "This DS will not be versioned");
Expand Down Expand Up @@ -132,6 +136,7 @@ public void testCreateUnlabeledVersion() throws Exception {
logger.info("Creating an object");
final String objId = UUID.randomUUID().toString();
createObject(objId);
addMixin( objId, MIX_NAMESPACE + "versionable" );

logger.info("Setting a title");
patchLiteralProperty(serverAddress + objId, "http://purl.org/dc/elements/1.1/title", "Example Title");
Expand All @@ -145,6 +150,7 @@ public void testCreateTwoVersionsWithSameLabel() throws Exception {
logger.info("creating an object");
final String objId = UUID.randomUUID().toString();
createObject(objId);
addMixin( objId, MIX_NAMESPACE + "versionable" );

logger.info("Setting a title");
patchLiteralProperty(serverAddress + objId, "http://purl.org/dc/elements/1.1/title", "First title");
Expand Down Expand Up @@ -174,7 +180,9 @@ public void testGetDatastreamVersionNotFound() throws Exception {
final String pid = randomUUID().toString();

createObject(pid);
addMixin( pid, MIX_NAMESPACE + "versionable" );
createDatastream(pid, "ds1", "foo");
addMixin( pid + "/ds1", MIX_NAMESPACE + "versionable" );

final HttpGet getVersion =
new HttpGet(serverAddress
Expand Down Expand Up @@ -205,6 +213,7 @@ public void isAutoVersionedContentStillAccessible() throws Exception {

createObject(objName);
createDatastream(objName, dsName, firstVersionText);
addMixin( objName + "/" + dsName, MIX_NAMESPACE + "versionable" );

setAutoVersioning(serverAddress + objName + "/" + dsName);

Expand Down Expand Up @@ -238,7 +247,7 @@ public void testAddMixinAutoVersioning() throws IOException {
final String objName = UUID.randomUUID().toString();

createObject(objName);
addMixin(serverAddress + objName, "http://fedora.info/definitions/v4/rest-api#autoVersioned");
addMixin(objName, "http://fedora.info/definitions/v4/rest-api#autoVersioned");

final GraphStore initialVersion = getContent(serverAddress + objName);
assertTrue("Should find auto-created versioning policy", initialVersion
Expand Down Expand Up @@ -349,22 +358,6 @@ private static void patchLiteralProperty(final String url, final String predicat
.getStatusCode());
}

private static void addMixin(final String url, final String mixinUrl) throws IOException {
final HttpPatch updateObjectGraphMethod =
new HttpPatch(url);
updateObjectGraphMethod.addHeader("Content-Type",
"application/sparql-update");
final BasicHttpEntity e = new BasicHttpEntity();

e.setContent(new ByteArrayInputStream(
("INSERT DATA { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + mixinUrl + "> . } ")
.getBytes()));
updateObjectGraphMethod.setEntity(e);
final HttpResponse response = client.execute(updateObjectGraphMethod);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatusLine()
.getStatusCode());
}

private GraphStore getContent(final String url) throws IOException {
final HttpGet getVersion = new HttpGet(url);
return getGraphStore(getVersion);
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-http-api/src/test/resources/test_repository.json
Expand Up @@ -17,7 +17,7 @@
},
"externalSources" : {
"fileSystem" : {
"classname" : "org.modeshape.connector.filesystem.FileSystemConnector",
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "target/test-classes/test-objects",
"readonly" : false,
"extraPropertiesStorage": "json",
Expand All @@ -35,4 +35,4 @@
]
},
"node-types" : ["fedora-node-types.cnd"]
}
}
4 changes: 2 additions & 2 deletions fcrepo-http-api/src/test/resources/test_repository_fs.json
Expand Up @@ -17,7 +17,7 @@
},
"externalSources" : {
"fileSystem" : {
"classname" : "org.modeshape.connector.filesystem.FileSystemConnector",
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "target/test-classes/test-objects",
"readonly" : false,
"extraPropertiesStorage": "json",
Expand All @@ -35,4 +35,4 @@
]
},
"node-types" : ["fedora-node-types.cnd"]
}
}
2 changes: 1 addition & 1 deletion fcrepo-kernel/src/main/resources/fedora-node-types.cnd
Expand Up @@ -88,7 +88,7 @@
/*
* Any Fedora resource.
*/
[fedora:resource] > fedora:relations, mix:created, mix:lastModified, mix:lockable, mix:versionable, dc:describable mixin
[fedora:resource] > fedora:relations, mix:created, mix:lastModified, mix:lockable, mix:referenceable, dc:describable mixin
- rdf:type (URI) multiple
- * (undefined) multiple
- * (undefined)
Expand Down
Expand Up @@ -422,6 +422,8 @@ public void testAddVersionLabel() throws RepositoryException {
final FedoraResource object =
objectService.createObject(session, "/testObjectVersionLabel");

object.getNode().addMixin("mix:versionable");

session.save();

object.addVersionLabel("v0.0.1");
Expand All @@ -439,6 +441,8 @@ public void testGetObjectVersionGraph() throws RepositoryException {
final FedoraResource object =
objectService.createObject(session, "/testObjectVersionGraph");

object.getNode().addMixin("mix:versionable");

session.save();

object.addVersionLabel("v0.0.1");
Expand Down

0 comments on commit c2e8e5f

Please sign in to comment.