Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added integration test for FedoraLocks.
  - demonstrating that all mime types can be retrurned
  - demonstrating the need to read the whole response
    in order to have the session close.

Resolves: https://www.pivotaltracker.com/story/show/70597666
  • Loading branch information
mikedurbin authored and Andrew Woods committed May 8, 2014
1 parent fb7e86c commit 2afdcf0
Showing 1 changed file with 49 additions and 0 deletions.
Expand Up @@ -29,6 +29,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.junit.Assert;
import org.junit.Ignore;
Expand All @@ -41,11 +42,20 @@
import static com.hp.hpl.jena.graph.Node.ANY;
import static com.hp.hpl.jena.graph.NodeFactory.createLiteral;
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;

import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.fcrepo.kernel.RdfLexicon.HAS_LOCK;
import static org.fcrepo.kernel.RdfLexicon.HAS_LOCK_TOKEN;
import static org.fcrepo.kernel.RdfLexicon.IS_DEEP;
Expand Down Expand Up @@ -302,6 +312,45 @@ public void testLockLinkIsPresentOnChildrenOfDeepLockedNode() throws IOException
assertUnlockWithToken(pid, lockToken);
}

@Test
public void testResponseContentTypes() throws Exception {
String POSSIBLE_RDF_RESPONSE_VARIANTS_STRING[] = {
TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X };
final String pid = getRandomUniquePid();
createObject(pid);
final String lockToken = getLockToken(lockObject(pid));

for (final String type : POSSIBLE_RDF_RESPONSE_VARIANTS_STRING) {
final HttpGet method =
new HttpGet(serverAddress + pid + "/" + FCR_LOCK);

method.addHeader("Accept", type);
addLockToken(method, lockToken);
final HttpResponse response = execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());

// If you don't read the whole response, the session
// may not be closed (if it's mid-stream) and your
// next request will fail because the token is still
// attached to that session and cannot be attached
// again.
EntityUtils.consume(response.getEntity());

assertContentType(response, type);
}
}

private void assertContentType(final HttpResponse response, final String contentType) throws IOException {
final Header[] contentTypes = response.getHeaders("Content-Type");
for (Header ctHeader : contentTypes) {
if (ctHeader.getValue().startsWith(contentType)) {
return;
}
}
Assert.fail(contentType + " Content-Type header not found!");

}

/**
* Test that a transaction will fail on commit if a lock has been taken
* out on any touched resources between the completion of that operation
Expand Down

0 comments on commit 2afdcf0

Please sign in to comment.