Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed fcrepo-http-api integration tests for Mac builds by using UUIDs…
… instead of fixed names for test resources
  • Loading branch information
ajs6f committed Oct 7, 2013
1 parent 1d7d0d0 commit 1b08474
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 52 deletions.
Expand Up @@ -16,14 +16,14 @@

package org.fcrepo.integration.http.api;

import static java.util.UUID.randomUUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
Expand Down Expand Up @@ -67,16 +67,19 @@ public void testAddDeepDatastream() throws Exception {

@Test
public void testPutDatastream() throws Exception {
final HttpPost objMethod = postObjMethod("FedoraDatastreamsTestPut");

final String pid = randomUUID().toString();

final HttpPost objMethod = postObjMethod(pid);
assertEquals(201, getStatus(objMethod));
final HttpPut method =
putDSMethod("FedoraDatastreamsTestPut", "zxc", "foo");
putDSMethod(pid, "zxc", "foo");
final HttpResponse response = client.execute(method);
final String location = response.getFirstHeader("Location").getValue();
assertEquals(201, response.getStatusLine().getStatusCode());
assertEquals(
"Got wrong URI in Location header for datastream creation!",
serverAddress + "FedoraDatastreamsTestPut/zxc/fcr:content", location);
serverAddress + pid + "/zxc/fcr:content", location);
}

@Test
Expand All @@ -95,7 +98,7 @@ public void testMutateDatastream() throws Exception {
putDSMethod("FedoraDatastreamsTest3", "ds1", "bar");
mutateDataStreamMethod.setEntity(new StringEntity(faulkner1, "UTF-8"));
final HttpResponse response = client.execute(mutateDataStreamMethod);
int status = response.getStatusLine().getStatusCode();
final int status = response.getStatusLine().getStatusCode();
if (status != 204) {
logger.error(EntityUtils.toString(response.getEntity()));
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
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 java.util.UUID.randomUUID;
import static java.util.regex.Pattern.DOTALL;
import static java.util.regex.Pattern.compile;
import static javax.ws.rs.core.Response.Status.CREATED;
Expand Down Expand Up @@ -46,6 +47,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.UUID;

import javax.jcr.RepositoryException;

Expand All @@ -62,7 +64,6 @@
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.client.cache.CachingHttpClient;
import org.apache.http.util.EntityUtils;
import org.fcrepo.kernel.RdfLexicon;
import org.fcrepo.http.commons.test.util.TestHelpers;
import org.junit.Ignore;
import org.junit.Test;
Expand All @@ -81,16 +82,19 @@ public class FedoraNodesIT extends AbstractResourceIT {

@Test
public void testIngest() throws Exception {
final HttpPost method = postObjMethod("FedoraObjectsTest1");

final String pid = randomUUID().toString();

final HttpPost method = postObjMethod(pid);
final HttpResponse response = client.execute(method);
assertEquals(CREATED.getStatusCode(), response.getStatusLine()
.getStatusCode());
final String content = EntityUtils.toString(response.getEntity());
assertTrue("Response wasn't a PID", compile("[a-z]+").matcher(content)
.find());
final String location = response.getFirstHeader("Location").getValue();
assertEquals("Got wrong Location header for ingest!", serverAddress +
"FedoraObjectsTest1", location);
assertEquals("Got wrong Location header for ingest!", serverAddress
+ pid, location);
}

@Test
Expand All @@ -116,7 +120,7 @@ public void testIngestWithNew() throws Exception {
public void testIngestWithNewAndSparqlQuery() throws Exception {
final HttpPost method = postObjMethod("");
method.addHeader("Content-Type", "application/sparql-update");
BasicHttpEntity entity = new BasicHttpEntity();
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(
("INSERT { <> <http://purl.org/dc/terms/title> \"this is a title\" } WHERE {}")
.getBytes()));
Expand Down Expand Up @@ -144,7 +148,7 @@ public void testIngestWithNewAndSparqlQuery() throws Exception {
public void testIngestWithNewAndGraph() throws Exception {
final HttpPost method = postObjMethod("");
method.addHeader("Content-Type", "application/n3");
BasicHttpEntity entity = new BasicHttpEntity();
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream("<> <http://purl.org/dc/terms/title> \"this is a title\"".getBytes()));
method.setEntity(entity);
final HttpResponse response = client.execute(method);
Expand All @@ -171,7 +175,7 @@ public void testIngestWithNewAndGraph() throws Exception {
@Test
public void testIngestWithSlug() throws Exception {
final HttpPost method = postObjMethod("");
method.addHeader("Slug", "xyz");
method.addHeader("Slug", randomUUID().toString());
final HttpResponse response = client.execute(method);
final String content = EntityUtils.toString(response.getEntity());
final int status = response.getStatusLine().getStatusCode();
Expand All @@ -190,7 +194,7 @@ public void testIngestWithSlug() throws Exception {
public void testIngestWithBinary() throws Exception {
final HttpPost method = postObjMethod("");
method.addHeader("Content-Type", "application/octet-stream");
BasicHttpEntity entity = new BasicHttpEntity();
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream("xyz".getBytes()));
method.setEntity(entity);
final HttpResponse response = client.execute(method);
Expand Down Expand Up @@ -220,18 +224,19 @@ public void testDeleteObject() throws Exception {

@Test
public void testGetDatastream() throws Exception {
execute(postObjMethod("FedoraDatastreamsTest4"));

assertEquals(404, getStatus(new HttpGet(serverAddress +
"FedoraDatastreamsTest4/ds1")));
assertEquals(CREATED.getStatusCode(), getStatus(postDSMethod(
"FedoraDatastreamsTest4", "ds1", "foo")));
final String pid = UUID.randomUUID().toString();

execute(postObjMethod(pid));

assertEquals(404, getStatus(new HttpGet(serverAddress + pid + "/ds1")));
assertEquals(CREATED.getStatusCode(), getStatus(postDSMethod(pid,
"ds1", "foo")));
final HttpResponse response =
execute(new HttpGet(serverAddress +
"FedoraDatastreamsTest4/ds1"));
execute(new HttpGet(serverAddress + pid + "/ds1"));
assertEquals(EntityUtils.toString(response.getEntity()), 200, response
.getStatusLine().getStatusCode());
assertEquals(TURTLE, response.getFirstHeader("Content-Type").getValue() );
assertEquals(TURTLE, response.getFirstHeader("Content-Type").getValue());
}

@Test
Expand Down Expand Up @@ -548,6 +553,9 @@ public void testRoundTripReplaceGraph() throws Exception {

@Test
public void testDescribeSize() throws Exception {

final String sizeNode = randomUUID().toString();

final HttpGet describeMethod = new HttpGet(serverAddress + "");
describeMethod.addHeader("Accept", "text/n3");
HttpResponse response = client.execute(describeMethod);
Expand All @@ -558,16 +566,16 @@ public void testDescribeSize() throws Exception {
graphStore.toString());

Iterator<Triple> iterator =
graphStore.getDefaultGraph().find(Node.ANY,
HAS_OBJECT_SIZE.asNode(), Node.ANY);
graphStore.getDefaultGraph().find(ANY, HAS_OBJECT_SIZE.asNode(),
ANY);

final Integer oldSize =
(Integer) iterator.next().getObject().getLiteralValue();

assertEquals(CREATED.getStatusCode(),
getStatus(postObjMethod("sizeNode")));
assertEquals(CREATED.getStatusCode(), getStatus(postDSMethod(
"sizeNode", "asdf", "1234")));
getStatus(postObjMethod(sizeNode)));
assertEquals(CREATED.getStatusCode(), getStatus(postDSMethod(sizeNode,
"asdf", "1234")));

response = client.execute(describeMethod);
assertEquals(OK.getStatusCode(), response.getStatusLine()
Expand Down
Expand Up @@ -16,7 +16,11 @@

package org.fcrepo.integration.http.api;

import static com.hp.hpl.jena.graph.Node.ANY;
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static java.util.UUID.randomUUID;
import static java.util.regex.Pattern.compile;
import static org.fcrepo.http.commons.test.util.TestHelpers.parseTriples;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand All @@ -39,7 +43,7 @@ public class FedoraTransactionsIT extends AbstractResourceIT {
public void testCreateTransaction() throws Exception {
/* create a tx */
final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");
HttpResponse response = execute(createTx);
final HttpResponse response = execute(createTx);
assertEquals(201, response.getStatusLine().getStatusCode());

final String location = response.getFirstHeader("Location").getValue();
Expand All @@ -56,7 +60,7 @@ public void testRequestsInTransactionThatDoestExist() throws Exception {
/* create a tx */
final HttpPost createTx =
new HttpPost(serverAddress + "tx:123/objects");
HttpResponse response = execute(createTx);
final HttpResponse response = execute(createTx);
assertEquals(410, response.getStatusLine().getStatusCode());

}
Expand All @@ -72,7 +76,7 @@ public void testCreateAndTimeoutTransaction() throws Exception {

/* create a tx */
final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");
HttpResponse response = execute(createTx);
final HttpResponse response = execute(createTx);
assertEquals(201, response.getStatusLine().getStatusCode());

final String location = response.getFirstHeader("Location").getValue();
Expand Down Expand Up @@ -104,7 +108,7 @@ public void testCreateDoStuffAndRollbackTransaction() throws Exception {
/* create a tx */
final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");

HttpResponse response = execute(createTx);
final HttpResponse response = execute(createTx);
assertEquals(201, response.getStatusLine().getStatusCode());

final String txLocation =
Expand Down Expand Up @@ -153,39 +157,41 @@ public void testCreateDoStuffAndRollbackTransaction() throws Exception {
@Test
public void testCreateDoStuffAndCommitTransaction() throws Exception {
/* create a tx */

final String objectInTxCommit = randomUUID().toString();

final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");

HttpResponse response = execute(createTx);
final HttpResponse response = execute(createTx);
assertEquals(201, response.getStatusLine().getStatusCode());

final String txLocation =
response.getFirstHeader("Location").getValue();

/* create a new object inside the tx */
final HttpPost postNew =
new HttpPost(txLocation + "/object-in-tx-commit");
new HttpPost(txLocation + "/" + objectInTxCommit);
HttpResponse resp = execute(postNew);
assertEquals(201, resp.getStatusLine().getStatusCode());

/* fetch the created tx from the endpoint */
final HttpGet getTx = new HttpGet(txLocation + "/object-in-tx-commit");
final HttpGet getTx = new HttpGet(txLocation + "/" + objectInTxCommit);
getTx.setHeader("Accept", "application/n3");
resp = execute(getTx);
assertEquals(
"Expected to find our object within the scope of the transaction",
200, resp.getStatusLine().getStatusCode());

final GraphStore graphStore =
TestHelpers.parseTriples(resp.getEntity().getContent());
parseTriples(resp.getEntity().getContent());
logger.debug(graphStore.toString());

assertTrue(graphStore.toDataset().asDatasetGraph().contains(Node.ANY,
NodeFactory.createURI(txLocation + "/object-in-tx-commit"),
Node.ANY, Node.ANY));
assertTrue(graphStore.toDataset().asDatasetGraph().contains(ANY,
createURI(txLocation + "/" + objectInTxCommit), ANY, ANY));

/* fetch the object-in-tx outside of the tx */
final HttpGet getObj =
new HttpGet(serverAddress + "/object-in-tx-commit");
new HttpGet(serverAddress + "/" + objectInTxCommit);
resp = execute(getObj);
assertEquals(
"Expected to not find our object within the scope of the transaction",
Expand All @@ -200,7 +206,7 @@ public void testCreateDoStuffAndCommitTransaction() throws Exception {

/* fetch the object-in-tx outside of the tx after it has been committed */
final HttpGet getObjCommitted =
new HttpGet(serverAddress + "/object-in-tx-commit");
new HttpGet(serverAddress + "/" + objectInTxCommit);
resp = execute(getObjCommitted);
assertEquals(
"Expected to find our object after the transaction was committed",
Expand Down
Expand Up @@ -16,21 +16,20 @@

package org.fcrepo.integration.http.api;

import static java.util.UUID.randomUUID;
import static org.fcrepo.http.commons.test.util.TestHelpers.parseTriples;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.jcr.RepositoryException;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.fcrepo.http.commons.test.util.TestHelpers;
import org.junit.Test;

import com.hp.hpl.jena.update.GraphStore;
Expand All @@ -44,10 +43,10 @@ public void testGetWorkspaces() throws Exception {
final HttpResponse response = execute(httpGet);
assertEquals(200, response.getStatusLine().getStatusCode());

InputStream in = response.getEntity().getContent();
List<String> lines = IOUtils.readLines(in);
final InputStream in = response.getEntity().getContent();
final List<String> lines = IOUtils.readLines(in);
boolean found = false;
for (String line : lines) {
for (final String line : lines) {
if (line.contains(serverAddress + "workspace:default")) {
found = true;
break;
Expand All @@ -59,28 +58,29 @@ public void testGetWorkspaces() throws Exception {
@Test
public void shouldDemonstratePathsAndWorkspaces() throws IOException,
RepositoryException {

final String workspace = randomUUID().toString();
final String pid = randomUUID().toString();

final HttpPost httpCreateWorkspace =
new HttpPost(serverAddress + "fcr:workspaces/some-workspace");
new HttpPost(serverAddress + "fcr:workspaces/" + workspace);
final HttpResponse createWorkspaceResponse =
execute(httpCreateWorkspace);
assertEquals(201, createWorkspaceResponse.getStatusLine()
.getStatusCode());

final HttpPost httpPost =
new HttpPost(serverAddress +
"workspace:some-workspace/FedoraWorkspacesTest");
new HttpPost(serverAddress + "workspace:" + workspace + "/" + pid);
final HttpResponse response = execute(httpPost);
assertEquals(201, response.getStatusLine().getStatusCode());

final HttpGet httpGet =
new HttpGet(serverAddress +
"workspace:some-workspace/FedoraWorkspacesTest");
new HttpGet(serverAddress + "workspace:" + workspace + "/" + pid);
httpGet.setHeader("Accept", "application/n3");
final HttpResponse profileResponse = execute(httpGet);
assertEquals(200, profileResponse.getStatusLine().getStatusCode());
final GraphStore graphStore =
TestHelpers.parseTriples(profileResponse.getEntity()
.getContent());
parseTriples(profileResponse.getEntity().getContent());
logger.info(graphStore.toString());
}
}

0 comments on commit 1b08474

Please sign in to comment.