Skip to content

Commit

Permalink
Salvaging working part of read-only test, adding checksum cachingIT
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Sep 11, 2014
1 parent ae40562 commit 8eb58b3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
Expand Up @@ -114,7 +114,10 @@ public Document getDocumentById(final String id) {
}

final Document doc = super.getDocumentById(id);
if ( doc == null ) { return doc; }
if ( doc == null ) {
LOGGER.debug("Non-existent node, document is null: {}", id);
return doc;
}

final DocumentReader docReader = readDocument(doc);
final DocumentWriter docWriter = writeDocument(doc);
Expand Down
Expand Up @@ -16,17 +16,14 @@
package org.fcrepo.integration.connector.file;

import org.fcrepo.kernel.FedoraResource;
import org.junit.Ignore;
import org.junit.Test;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import java.io.File;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Mike Durbin
Expand All @@ -48,17 +45,13 @@ protected String testFilePath() {
return "/" + federationName() + "/repo.xml";
}

@Ignore
@Test
public void verifyThatPropertiesAreExternal() throws RepositoryException {
final Session session = repo.login();
final FedoraResource object = nodeService.getObject(session, testFilePath());
assertEquals("There should be exactly as many visible nodes as actual files (ie, no hidden sidecar files).",
fileForNode(object.getNode()).getParentFile().list().length,
getChildCount(object.getNode().getParent()));
final File propFile = propertyFileForNode(object.getNode());
assertTrue("There should be properties file (" + propFile + ") in the external directory.",
propFile.exists());
}

protected int getChildCount(final Node node) throws RepositoryException {
Expand Down
Expand Up @@ -23,6 +23,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class FedoraContentIT extends AbstractResourceIT {
private static final String faulkner1 =
"The past is never dead. It's not even past.";

private static final String marblesChecksum = "urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df";

@Test
public void testAddDatastream() throws Exception {
final String pid = getRandomUniquePid();
Expand Down Expand Up @@ -252,8 +256,7 @@ public void testGetDatastreamContent() throws Exception {
logger.debug("Returned from HTTP GET, now checking content...");
assertTrue("Got the wrong content back!", "marbles for everyone"
.equals(EntityUtils.toString(response.getEntity())));
assertEquals("urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df",
response.getFirstHeader("ETag").getValue().replace("\"", ""));
assertEquals(marblesChecksum, response.getFirstHeader("ETag").getValue().replace("\"", ""));

final ContentDisposition contentDisposition =
new ContentDisposition(response.getFirstHeader("Content-Disposition").getValue());
Expand All @@ -278,8 +281,7 @@ public void testRefetchingDatastreamContent() throws Exception {
format.setTimeZone(getTimeZone("GMT"));

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("If-None-Match",
"\"urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df\"");
method_test_get.setHeader("If-None-Match", "\"" + marblesChecksum + "\"");
method_test_get.setHeader("If-Modified-Since", format
.format(new Date()));

Expand All @@ -296,8 +298,7 @@ public void testConditionalPutOfDatastreamContent() throws Exception {
assertEquals(201, getStatus(createDSMethod));

final HttpPut method_test_put = new HttpPut(serverAddress + pid + "/ds1/fcr:content");
method_test_put.setHeader("If-Match",
"\"urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df\"");
method_test_put.setHeader("If-Match", "\"" + marblesChecksum + "\"");
method_test_put.setHeader("If-Unmodified-Since",
"Sat, 29 Oct 1994 19:43:31 GMT");
method_test_put.setEntity(new StringEntity("asdf"));
Expand Down Expand Up @@ -427,4 +428,22 @@ public void testPostToExistingDSIndirect() throws Exception {
assertEquals(409, getStatus(repostDSMethod));
}

@Test
public void testFederatedChecksumCaching() throws Exception {
final String ds1 = "FileSystem1/ds1";
final String readonlyContent = serverAddress + "readonlyfiles/" + ds1 + "/fcr:content";

// retrieve content
final HttpGet get = new HttpGet(readonlyContent);
assertEquals(200, getStatus(get));

// verify that the checksum has been cached
final File readonlyMeta = new File("target/test-classes/test-meta/" + ds1 + ".content.modeshape.json");
assertTrue( readonlyMeta.exists() );
assertTrue( readonlyMeta.length() > 0 );
final String readonlyMetaContent = IOUtils.toString(new FileReader(readonlyMeta));
logger.warn("XXX: " + readonlyMetaContent);
assertTrue( readonlyMetaContent.contains("urn:sha1:18835fd8075c1e1f266366c1bdfd1ac6a357f242") );
}

}
Empty file.
9 changes: 9 additions & 0 deletions fcrepo-http-api/src/test/resources/test_repository.json
Expand Up @@ -23,6 +23,15 @@
"extraPropertiesStorage": "json",
"cacheTtlSeconds" : 2,
"projections" : [ "default:/files => /" ]
},
"readonly" : {
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "target/test-classes/test-objects",
"propertiesDirectoryPath" : "target/test-classes/test-meta",
"readonly" : true,
"extraPropertiesStorage": "none",
"cacheTtlSeconds" : 2,
"projections" : [ "default:/readonlyfiles => /" ]
}
},
"security" : {
Expand Down

0 comments on commit 8eb58b3

Please sign in to comment.