Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #579 from fcrepo4/integration-rdf
Add integration tests for real-world RDF statements
- Loading branch information
Showing
15 changed files
with
694 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>fcrepo</artifactId> | ||
<groupId>org.fcrepo</groupId> | ||
<version>4.0.0-beta-04-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<name>Fedora Repository RDF integration tests Module</name> | ||
<description>Fedora RDF integration scenarios</description> | ||
<artifactId>fcrepo-integration-rdf</artifactId> | ||
|
||
|
||
<dependencies> | ||
<!-- test gear --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-configs</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-commons</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-auth-common</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-commons</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.grizzly</groupId> | ||
<artifactId>grizzly-http-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.grizzly</groupId> | ||
<artifactId>grizzly-http-servlet</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.ext</groupId> | ||
<artifactId>jersey-spring3</artifactId> | ||
<scope>test</scope> | ||
<version>${jersey.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-common</artifactId> | ||
<version>${jersey.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<configuration> | ||
<portNames> | ||
<portName>test.port</portName> | ||
<!-- reserves the stop port for jetty-maven-plugin --> | ||
<portName>jetty.port.stop</portName> | ||
<portName>jms.port</portName> | ||
<portName>stomp.port</portName> | ||
</portNames> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<test.port>${test.port}</test.port> | ||
<test.context.path>${test.context.path}</test.context.path> | ||
<jms.port>${jms.port}</jms.port> | ||
<stomp.port>${stomp.port}</stomp.port> | ||
<integration-test>true</integration-test> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
132 changes: 132 additions & 0 deletions
132
...po-integration-rdf/src/test/java/org/fcrepo/integration/rdf/AbstractIntegrationRdfIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.integration.rdf; | ||
|
||
import com.hp.hpl.jena.graph.Graph; | ||
import com.hp.hpl.jena.graph.Node; | ||
import com.hp.hpl.jena.graph.NodeFactory; | ||
import com.hp.hpl.jena.graph.Triple; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.ModelFactory; | ||
import com.hp.hpl.jena.sparql.graph.GraphFactory; | ||
import com.hp.hpl.jena.update.GraphStore; | ||
import com.hp.hpl.jena.util.iterator.ExtendedIterator; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.apache.http.entity.BasicHttpEntity; | ||
import org.fcrepo.integration.http.api.AbstractResourceIT; | ||
|
||
import javax.ws.rs.core.Response; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static javax.ws.rs.core.Response.Status.CREATED; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author cabeer | ||
*/ | ||
public abstract class AbstractIntegrationRdfIT extends AbstractResourceIT { | ||
|
||
protected HttpResponse createLDPRSAndCheckResponse(final String pid, final String body) { | ||
try { | ||
final HttpPut httpPut = new HttpPut(serverAddress + pid); | ||
httpPut.addHeader("Slug", pid); | ||
httpPut.addHeader("Content-Type", "text/turtle"); | ||
final BasicHttpEntity e = new BasicHttpEntity(); | ||
e.setContent(IOUtils.toInputStream(body)); | ||
httpPut.setEntity(e); | ||
final HttpResponse response = client.execute(httpPut); | ||
checkResponse(response, CREATED); | ||
|
||
final String location = response.getFirstHeader("Location").getValue(); | ||
|
||
final HttpGet httpGet = new HttpGet(location); | ||
httpGet.addHeader("Prefer", "return=representation; " + | ||
"include=\"http://www.w3.org/ns/ldp#PreferMinimalContainer\"; " + | ||
"omit=\"http://fedora.info/definitions/v4/repository#ServerManaged\""); | ||
final GraphStore graphStore = getGraphStore(httpGet); | ||
|
||
assertFalse(graphStore.isEmpty()); | ||
|
||
final Graph tidiedGraph = getTidiedGraph(graphStore); | ||
final Model expected = ModelFactory.createDefaultModel().read(IOUtils.toInputStream(body), location, "TTL"); | ||
|
||
assertTrue(tidiedGraph.isIsomorphicWith(expected.getGraph())); | ||
|
||
return response; | ||
} catch (final IOException e) { | ||
assertTrue("Got IOException " + e, false); | ||
return null; | ||
} | ||
} | ||
|
||
private Graph getTidiedGraph(final GraphStore graphStore) { | ||
final Graph betterGraph = GraphFactory.createDefaultGraph(); | ||
final ExtendedIterator<Triple> triples = graphStore.getDefaultGraph().find(Node.ANY, Node.ANY, Node.ANY); | ||
final Map<Node, Node> bnodeMap = new HashMap<>(); | ||
|
||
while (triples.hasNext()) { | ||
final Triple next = triples.next(); | ||
|
||
Triple replacement = next; | ||
|
||
if (replacement.getSubject().toString().contains(".well-known")) { | ||
if (!bnodeMap.containsKey(replacement.getSubject())) { | ||
bnodeMap.put(replacement.getSubject(), NodeFactory.createAnon()); | ||
} | ||
|
||
replacement = new Triple(bnodeMap.get(replacement.getSubject()), | ||
replacement.getPredicate(), | ||
replacement.getObject()); | ||
} | ||
|
||
if (replacement.getObject().toString().contains(".well-known")) { | ||
|
||
if (!bnodeMap.containsKey(replacement.getObject())) { | ||
bnodeMap.put(replacement.getObject(), NodeFactory.createAnon()); | ||
} | ||
|
||
replacement = new Triple(replacement.getSubject(), | ||
replacement.getPredicate(), | ||
bnodeMap.get(replacement.getObject())); | ||
} | ||
|
||
if (replacement.getObject().isLiteral() | ||
&& replacement.getObject().getLiteral().getDatatypeURI() | ||
.equals("http://www.w3.org/2001/XMLSchema#string")) { | ||
replacement = new Triple(replacement.getSubject(), | ||
replacement.getPredicate(), | ||
NodeFactory.createLiteral(replacement.getObject().getLiteral().getLexicalForm())); | ||
} | ||
|
||
betterGraph.add(replacement); | ||
} | ||
return betterGraph; | ||
} | ||
|
||
protected void checkResponse(final HttpResponse response, final Response.StatusType expected) { | ||
final int actual = response.getStatusLine().getStatusCode(); | ||
assertEquals("Didn't get a CREATED response!", expected.getStatusCode(), actual); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.