Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add fixity IT for the previous version of binary content.
  • Loading branch information
lsitu authored and Andrew Woods committed Dec 6, 2014
1 parent ef5cc86 commit cf8cd25
Showing 1 changed file with 41 additions and 0 deletions.
Expand Up @@ -19,17 +19,25 @@
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createPlainLiteral;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createTypedLiteral;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static org.fcrepo.kernel.RdfLexicon.HAS_FIXITY_RESULT;
import static org.fcrepo.kernel.RdfLexicon.HAS_FIXITY_STATE;
import static org.fcrepo.kernel.RdfLexicon.HAS_MESSAGE_DIGEST;
import static org.fcrepo.kernel.RdfLexicon.HAS_SIZE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Iterator;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.fcrepo.http.commons.domain.RDFMediaType;
import org.junit.Test;

import com.hp.hpl.jena.sparql.core.Quad;
import com.hp.hpl.jena.update.GraphStore;

/**
Expand Down Expand Up @@ -80,4 +88,37 @@ public void testResponseContentTypes() throws Exception {
assertEquals(type, getContentType(method));
}
}

@Test
public void testBinaryVersionFixity() throws Exception {
final String pid = getRandomUniquePid();

createObject(pid);
createDatastream(pid, "dsid", "foo");

logger.debug("Creating binary content version v0 ...");
postVersion(pid + "/dsid", "v0");

final HttpGet method = new HttpGet(serverAddress + pid + "/dsid/fcr%3aversions/v0/fcr:fixity");
final GraphStore graphStore = getGraphStore(method);
logger.debug("Got binary content versioned fixity triples {}", graphStore);
final Iterator<Quad> stmtIt = graphStore.find(ANY, ANY, HAS_FIXITY_RESULT.asNode(), ANY);
assertTrue(stmtIt.hasNext());
assertTrue(graphStore.contains(ANY, ANY, HAS_FIXITY_STATE.asNode(),
createPlainLiteral("SUCCESS").asNode()));

assertTrue(graphStore.contains(ANY, ANY, HAS_MESSAGE_DIGEST.asNode(), ANY));
assertTrue(graphStore.contains(ANY, ANY, HAS_SIZE.asNode(),
createTypedLiteral(3).asNode()));
}

private void postVersion(final String path, final String label) throws IOException {
logger.debug("Posting version");
final HttpPost postVersion = postObjMethod(path + "/fcr:versions");
postVersion.addHeader("Slug", label);
final HttpResponse response = execute(postVersion);
assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode() );
final String locationHeader = response.getFirstHeader("Location").getValue();
assertNotNull( "No version location header found", locationHeader );
}
}

0 comments on commit cf8cd25

Please sign in to comment.