Skip to content

Commit

Permalink
Fix fcrepo-http-api integration tests for Mac builds
Browse files Browse the repository at this point in the history
Build issue resolved by using UUIDs instead of fixed names for test resources.
Fixed fcrepo-generator-dc integration tests for Mac builds by using UUIDs instead of fixed names for test resources.
Minor code cleanup, reducing compiler warnings.
  • Loading branch information
ajs6f authored and Andrew Woods committed Oct 8, 2013
1 parent 1d7d0d0 commit 172fe46
Show file tree
Hide file tree
Showing 91 changed files with 309 additions and 339 deletions.
Expand Up @@ -16,6 +16,8 @@

package org.fcrepo.integration.generator;

import static java.lang.System.err;
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.MediaType.TEXT_XML;
Expand All @@ -25,7 +27,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
Expand All @@ -42,8 +43,8 @@ public void testJcrPropertiesBasedOaiDc() throws Exception {
assertEquals(201, status);
final HttpPatch post = new HttpPatch(serverAddress + "DublinCoreTest1");
post.setHeader("Content-Type", "application/sparql-update");
BasicHttpEntity entity = new BasicHttpEntity();
String subjectURI = serverAddress + "DublinCoreTest1";
final BasicHttpEntity entity = new BasicHttpEntity();
final String subjectURI = serverAddress + "DublinCoreTest1";
entity.setContent(new ByteArrayInputStream(
("INSERT { <" + subjectURI + "> <http://purl.org/dc/terms/identifier> \"this is an identifier\" } WHERE {}")
.getBytes()));
Expand All @@ -67,20 +68,21 @@ public void testJcrPropertiesBasedOaiDc() throws Exception {

@Test
public void testWellKnownPathOaiDc() throws Exception {
HttpResponse response =
client.execute(postObjMethod("DublinCoreTest2"));

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

HttpResponse response = client.execute(postObjMethod(pid));
assertEquals(201, response.getStatusLine().getStatusCode());
response =
client.execute(postDSMethod("DublinCoreTest2", "DC",
"marbles for everyone"));
int status = response.getStatusLine().getStatusCode();
client.execute(postDSMethod(pid, "DC", "marbles for everyone"));
final int status = response.getStatusLine().getStatusCode();
if (status != 201) {
System.err.println(EntityUtils.toString(response.getEntity()));
err.println(EntityUtils.toString(response.getEntity()));
}
assertEquals(201, status);

final HttpGet getWorstCaseOaiMethod =
new HttpGet(serverOAIAddress + "DublinCoreTest2/oai:dc");
new HttpGet(serverOAIAddress + pid + "/oai:dc");
getWorstCaseOaiMethod.setHeader("Accept", TEXT_XML);
response = client.execute(getWorstCaseOaiMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
Expand Down
Expand Up @@ -19,6 +19,7 @@
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand Down Expand Up @@ -83,7 +84,7 @@ public class FedoraContent extends AbstractResource {
/**
* Create an anonymous DS with a newly minted name and content from request
* body
*
*
* @param pathList
* @throws RepositoryException
*/
Expand All @@ -108,7 +109,7 @@ public Response create(@PathParam("path")
}

logger.debug("create Datastream {}", path);
final Throwable exception = null;

try {
final URI checksumURI;

Expand All @@ -130,9 +131,8 @@ public Response create(@PathParam("path")
session.save();
return created(
new URI(subjects.getGraphSubject(
datastreamNode
.getNode(JcrConstants.JCR_CONTENT))
.getURI())).build();
datastreamNode.getNode(JCR_CONTENT)).getURI()))
.build();

} finally {
session.logout();
Expand All @@ -141,7 +141,7 @@ public Response create(@PathParam("path")

/**
* Modify an existing datastream's content
*
*
* @param pathList
* @param requestContentType Content-Type header
* @param requestBodyStream Binary blob
Expand Down Expand Up @@ -212,7 +212,7 @@ public Response modifyContent(@PathParam("path")

/**
* Get the binary content of a datastream
*
*
* @param pathList
* @return Binary blob
* @throws RepositoryException
Expand Down
Expand Up @@ -52,10 +52,10 @@
import javax.ws.rs.core.Response;

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.kernel.utils.ContentDigest;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
Expand Down
Expand Up @@ -35,9 +35,9 @@
import javax.ws.rs.core.StreamingOutput;

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.serialization.FedoraObjectSerializer;
import org.fcrepo.serialization.SerializerUtil;
import org.fcrepo.http.commons.session.InjectedSession;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
Expand Down
Expand Up @@ -21,6 +21,13 @@
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT1;
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_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
import static org.fcrepo.kernel.RdfLexicon.NEXT_PAGE;
import static org.fcrepo.kernel.RdfLexicon.PAGE;
Expand All @@ -30,13 +37,6 @@
import static org.fcrepo.kernel.RdfLexicon.SEARCH_OFFSET;
import static org.fcrepo.kernel.RdfLexicon.SEARCH_PAGE;
import static org.fcrepo.kernel.RdfLexicon.SEARCH_TERMS;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT1;
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_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.RepositoryException;
Expand Down
Expand Up @@ -39,9 +39,9 @@
import javax.ws.rs.core.UriInfo;

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.Datastream;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

Expand Down
Expand Up @@ -24,14 +24,14 @@
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.update.GraphStoreFactory.create;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static org.fcrepo.kernel.RdfLexicon.HAS_MEMBER_OF_RESULT;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT1;
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_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.kernel.RdfLexicon.HAS_MEMBER_OF_RESULT;

import java.util.Collection;
import java.util.List;
Expand Down
Expand Up @@ -37,9 +37,9 @@

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.serialization.SerializerUtil;
import org.fcrepo.http.commons.session.InjectedSession;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
Expand Down
41 changes: 19 additions & 22 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraNodes.java
Expand Up @@ -29,16 +29,16 @@
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate;
import static org.apache.jena.riot.WebContent.contentTypeToLang;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD_COUNT;
import static org.fcrepo.kernel.RdfLexicon.NEXT_PAGE;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT1;
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_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD_COUNT;
import static org.fcrepo.kernel.RdfLexicon.NEXT_PAGE;
import static org.fcrepo.kernel.rdf.GraphProperties.INLINED_RESOURCES_MODEL;
import static org.fcrepo.kernel.rdf.GraphProperties.PROBLEMS_MODEL_NAME;
import static org.slf4j.LoggerFactory.getLogger;
Expand All @@ -50,7 +50,6 @@
import java.util.Date;
import java.util.List;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -76,19 +75,17 @@
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import org.apache.commons.io.IOUtils;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.WebContent;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.http.commons.domain.PATCH;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.modeshape.jcr.api.JcrConstants;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
Expand All @@ -97,6 +94,8 @@
import com.codahale.metrics.annotation.Timed;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;

/**
* CRUD operations on Fedora Nodes
Expand All @@ -113,7 +112,7 @@ public class FedoraNodes extends AbstractResource {

/**
* Retrieve the node profile
*
*
* @param pathList
* @param offset with limit, control the pagination window of details for
* child nodes
Expand All @@ -133,7 +132,7 @@ public Dataset describe(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("limit") @DefaultValue("-1") final int limit,
@QueryParam("non-member-properties") final String nonMemberProperties,
@Context final Request request,
@Context HttpServletResponse servletResponse,
@Context final HttpServletResponse servletResponse,
@Context final UriInfo uriInfo) throws RepositoryException, IOException {
final String path = toPath(pathList);
logger.trace("Getting profile for {}", path);
Expand Down Expand Up @@ -179,7 +178,7 @@ public Dataset describe(@PathParam("path") final List<PathSegment> pathList,
.contains(subjects.getGraphSubject(resource.getNode()),
HAS_CHILD_COUNT)) {

Model requestModel = ModelFactory.createDefaultModel();
final Model requestModel = ModelFactory.createDefaultModel();

final long childCount = treeModel
.listObjectsOfProperty(subjects.getGraphSubject(resource.getNode()), HAS_CHILD_COUNT)
Expand Down Expand Up @@ -231,7 +230,7 @@ public Dataset describe(@PathParam("path") final List<PathSegment> pathList,

/**
* Update an object using SPARQL-UPDATE
*
*
* @param pathList
* @return 201
* @throws RepositoryException
Expand Down Expand Up @@ -275,10 +274,10 @@ public Response updateSparql(@PathParam("path")
throw new WebApplicationException(builder.build());
}

Dataset properties = resource.updatePropertiesDataset(new HttpGraphSubjects(
final Dataset properties = resource.updatePropertiesDataset(new HttpGraphSubjects(
session, FedoraNodes.class, uriInfo), IOUtils
.toString(requestBodyStream));
Model problems = properties.getNamedModel(PROBLEMS_MODEL_NAME);
final Model problems = properties.getNamedModel(PROBLEMS_MODEL_NAME);
if (problems.size() > 0) {
logger.info(
"Found these problems updating the properties for {}: {}",
Expand Down Expand Up @@ -369,7 +368,7 @@ public Response createOrReplaceObjectRdf(

/**
* Creates a new object.
*
*
* @param pathList
* @return 201
* @throws RepositoryException
Expand Down Expand Up @@ -487,11 +486,9 @@ public Response createObject(@PathParam("path")
result.replacePropertiesDataset(subjects, inputModel);
} else if (result instanceof Datastream) {

final Node node =
datastreamService.createDatastreamNode(session, newObjectPath,
contentTypeString, requestBodyStream,
checksumURI);

datastreamService.createDatastreamNode(session,
newObjectPath, contentTypeString,
requestBodyStream, checksumURI);

}
}
Expand All @@ -518,7 +515,7 @@ public Response createObject(@PathParam("path")

/**
* Deletes an object.
*
*
* @param path
* @return
* @throws RepositoryException
Expand Down
Expand Up @@ -47,10 +47,10 @@
import javax.ws.rs.core.Variant;

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.responses.GraphStoreStreamingOutput;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down
Expand Up @@ -33,12 +33,12 @@

import org.apache.commons.io.IOUtils;
import org.apache.jena.riot.WebContent;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.http.api.FedoraNodes;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.kernel.rdf.GraphProperties;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphProperties;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down

0 comments on commit 172fe46

Please sign in to comment.