Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…243236

Daylight is seen. FedoraVersions is now fully streaming, HTTP to JCR
Better i-test for FedoraVersions
Unit test for LogoutCallback
Added unit test for RdfStreamStreamingOutput
Licenses....
Last bit of unit testing
  • Loading branch information
ajs6f authored and Andrew Woods committed Nov 1, 2013
1 parent 5b6ef11 commit 0364678
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 42 deletions.
Expand Up @@ -16,7 +16,9 @@

package org.fcrepo.http.api;

import static com.google.common.util.concurrent.Futures.addCallback;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
Expand Down Expand Up @@ -49,15 +51,14 @@

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.http.commons.responses.GraphStoreStreamingOutput;
import org.fcrepo.http.commons.responses.RdfStreamStreamingOutput;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.utils.LogoutCallback;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.hp.hpl.jena.query.Dataset;

/**
* Endpoint for retrieving previous versions of nodes
*
Expand Down Expand Up @@ -97,21 +98,17 @@ public Response getVersionList(@PathParam("path")
final Variant bestPossibleResponse =
request.selectVariant(POSSIBLE_RDF_VARIANTS);

try {
final FedoraResource resource =
nodeService.getObject(session, path);
final FedoraResource resource = nodeService.getObject(session, path);

return Response.ok(
new GraphStoreStreamingOutput(resource
.getVersionTriples(new HttpGraphSubjects(session,
FedoraNodes.class,
uriInfo)),
bestPossibleResponse.getMediaType())).build();
final RdfStreamStreamingOutput streamOutput =
new RdfStreamStreamingOutput(resource
.getVersionTriples(new HttpGraphSubjects(session,
FedoraVersions.class, uriInfo)),
bestPossibleResponse.getMediaType());

} finally {
session.logout();
}
addCallback(streamOutput, new LogoutCallback(session));

return ok(streamOutput).build();
}

/**
Expand Down Expand Up @@ -153,31 +150,37 @@ public Response addVersionLabel(@PathParam("path")
@Path("/{versionLabel}")
@GET
@Produces({TURTLE, N3, N3_ALT1, N3_ALT2, RDF_XML, RDF_JSON, NTRIPLES})
public Dataset getVersion(@PathParam("path")
public Response getVersion(@PathParam("path")
final List<PathSegment> pathList,
@PathParam("versionLabel")
final String versionLabel,
@Context
final Request request,
@Context
final UriInfo uriInfo) throws RepositoryException, IOException {
final String path = toPath(pathList);
LOGGER.trace("getting version profile for {} at version {}", path,
versionLabel);

try {
final FedoraResource resource =
nodeService.getObject(session, path, versionLabel);
final FedoraResource resource =
nodeService.getObject(session, path, versionLabel);

if (resource == null) {
throw new WebApplicationException(status(NOT_FOUND).build());
} else {
if (resource == null) {
throw new WebApplicationException(status(NOT_FOUND).build());
} else {

return resource.getPropertiesDataset(new HttpGraphSubjects(
session, FedoraNodes.class, uriInfo), 0, -1);
}
final Variant bestPossibleResponse =
request.selectVariant(POSSIBLE_RDF_VARIANTS);

} finally {
session.logout();
}
final RdfStreamStreamingOutput streamOutput =
new RdfStreamStreamingOutput(resource
.getTriples(new HttpGraphSubjects(session,
FedoraVersions.class, uriInfo)),
bestPossibleResponse.getMediaType());

addCallback(streamOutput, new LogoutCallback(session));

return ok(streamOutput).build();
}
}
}
Expand Up @@ -24,7 +24,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -120,10 +119,13 @@ public void testGetVersion() throws RepositoryException, IOException {
when(
mockNodes.getObject(any(Session.class), any(String.class),
any(String.class))).thenReturn(mockResource);
testObj.getVersion(createPathList(pid), versionLabel, TestHelpers
when(mockRequest.selectVariant(POSSIBLE_RDF_VARIANTS)).thenReturn(
mockVariant);
when(mockVariant.getMediaType()).thenReturn(
new MediaType("text", "turtle"));
testObj.getVersion(createPathList(pid), versionLabel, mockRequest, TestHelpers
.getUriInfoImpl());
verify(mockResource).getPropertiesDataset(any(HttpGraphSubjects.class),
anyInt(), anyInt());
verify(mockResource).getTriples(any(HttpGraphSubjects.class));
}

}
Expand Up @@ -16,13 +16,18 @@

package org.fcrepo.integration.http.api;

import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
Expand All @@ -39,6 +44,8 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.hp.hpl.jena.rdf.model.Model;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring-test/test-container.xml")
public abstract class AbstractResourceIT {
Expand Down Expand Up @@ -118,4 +125,15 @@ protected int getStatus(final HttpUriRequest method)
return result;
}

protected Model extract(final String serialization) throws IOException {
logger.debug("Reading RDF:\n{}", serialization);
try (

final InputStream rdf =
new ByteArrayInputStream(serialization.getBytes(Charset
.forName("UTF8")))) {
return createDefaultModel().read(rdf, null);
}
}

}
Expand Up @@ -16,25 +16,45 @@

package org.fcrepo.integration.http.api;

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_TYPE;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

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.apache.http.util.EntityUtils;
import org.junit.Test;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;

public class FedoraVersionsIT extends AbstractResourceIT {

@Test
public void testGetObjectVersionProfile() throws Exception {
execute(postObjMethod("FedoraDatastreamsTest1"));
final String pid = "FedoraDatastreamsTest1";

execute(postObjMethod(pid));
final HttpGet method =
new HttpGet(serverAddress + "FedoraDatastreamsTest1/fcr:versions");
new HttpGet(serverAddress + pid + "/fcr:versions");
final HttpResponse resp = execute(method);
assertEquals(200, resp.getStatusLine().getStatusCode());
final String profile = EntityUtils.toString(resp.getEntity());
assertEquals("Failed to retrieve version profile!\n" + profile, 200,
resp.getStatusLine().getStatusCode());
logger.debug("Retrieved version profile:");
final Model results = extract(profile);
final Resource subject =
createResource(serverAddress + pid + "/fcr:versions");
assertTrue("Didn't find a version triple!", results.contains(subject,
HAS_VERSION, (RDFNode) null));
}



@Test
public void testAddVersion() throws Exception {
execute(postObjMethod("FedoraVersioningTest2"));
Expand All @@ -48,9 +68,13 @@ public void testAddVersion() throws Exception {
new HttpGet(serverAddress
+ "FedoraVersioningTest2/fcr:versions/v0.0.1");
final HttpResponse resp = execute(getVersion);
assertEquals(200, resp.getStatusLine().getStatusCode());
logger.info("Got version profile: {}", IOUtils.toString(resp
.getEntity().getContent()));
final String version = EntityUtils.toString(resp.getEntity());
assertEquals("Failed to retrieve new version!\n" + version, 200, resp
.getStatusLine().getStatusCode());
logger.info("Got version profile:");
final Model results = extract(version);
assertTrue("Found no version!", results.contains(null,
HAS_PRIMARY_TYPE, "nt:frozenNode"));
}

@Test
Expand Down
16 changes: 16 additions & 0 deletions fcrepo-http-commons/pom.xml
Expand Up @@ -215,6 +215,22 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-api</artifactId>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-ntriples</artifactId>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-rdfxml</artifactId>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-turtle</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -78,9 +78,8 @@ public abstract class RDFMediaType extends MediaType {
public static final MediaType NQUADS_TYPE = typeFromString(NQUADS);

public static final List<Variant> POSSIBLE_RDF_VARIANTS = mediaTypes(
N3_TYPE, N3_ALT1_TYPE, N3_ALT2_TYPE, TURTLE_TYPE, RDF_XML_TYPE,
RDF_JSON_TYPE, NTRIPLES_TYPE, TRI_G_TYPE, NQUADS_TYPE).add()
.build();
RDF_XML_TYPE, NTRIPLES_TYPE, TURTLE_TYPE, RDF_JSON_TYPE, N3_TYPE,
N3_ALT1_TYPE, N3_ALT2_TYPE, TRI_G_TYPE, NQUADS_TYPE).add().build();

private static MediaType typeFromString(final String type) {
return new MediaType(type.split("/")[0], type.split("/")[1]);
Expand Down

0 comments on commit 0364678

Please sign in to comment.