Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add integration tests for real-world RDF statements
  • Loading branch information
cbeer committed Oct 23, 2014
1 parent 278d3a3 commit d64b1d5
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 0 deletions.
113 changes: 113 additions & 0 deletions fcrepo-integration-rdf/pom.xml
@@ -0,0 +1,113 @@
<?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>

<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>
</project>
@@ -0,0 +1,60 @@
/**
* 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 org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
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 static javax.ws.rs.core.Response.Status.CREATED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author cabeer
*/
public 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);
return response;
} catch (final IOException e) {
assertTrue("Got IOException " + e, false);
return null;
}
}

protected void checkResponse(HttpResponse response, final Response.StatusType expected) {
final int actual = response.getStatusLine().getStatusCode();
assertEquals("Didn't get a CREATED response!", expected.getStatusCode(), actual);
}


}
@@ -0,0 +1,71 @@
/**
* 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 org.junit.Test;

/**
* @author cabeer
*/
public class BibframeIT extends AbstractIntegrationRdfIT {

@Test
public void testBibframe() throws Exception {
final String bibframe = "@prefix bf: <http://bibframe.org/vocab/> .\n" +
"@prefix madsrdf: <http://www.loc.gov/mads/rdf/v1#> .\n" +
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
"@prefix relators: <http://id.loc.gov/vocabulary/relators/> .\n" +
"@prefix xml: <http://www.w3.org/XML/1998/namespace> .\n" +
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" +
"\n" +
"<> a bf:Work ;\n" +
" bf:hasInstance [ a bf:Electronic,\n" +
" bf:Instance ;\n" +
" bf:instanceOf <http://id.loc.gov/resources/bibs/15716616> ;\n" +
" bf:label \"Electronic Resource\" ;\n" +
" bf:uri <http://www.soaw.org/new/newsletter.php> ],\n" +
" [ a bf:Instance,\n" +
" bf:Serial ;\n" +
" bf:derivedFrom <http://id.loc.gov/resources/bibs/15716616.marcxml.xml> ;\n" +
" bf:instanceOf <http://id.loc.gov/resources/bibs/15716616> ;\n" +
" bf:instanceTitle [ a bf:Title ] ;\n" +
" bf:issn [ a bf:Identifier ;\n" +
" bf:identifierAssigner \"1\" ;\n" +
" bf:identifierScheme \"issn\" ;\n" +
" bf:identifierValue \"1949-3223\" ] ;\n" +
" bf:keyTitle [ a bf:Title ] ;\n" +
" bf:modeOfIssuance \"serial\" ;\n" +
" bf:note \"\\\"Newspaper of the movement to close the School of the Americas.\\\"\",\n" +
" \"Latest issue consulted: Vol. 14, no. 1 (winter/spring 2009).\",\n" +
" \"Title from caption.\" ;\n" +
" bf:otherPhysicalFormat [ a bf:Instance ;\n" +
" bf:title \"¡Presente!\" ] ;\n" +
" bf:publication [ a bf:Provider ;\n" +
" bf:providerDate \"[2006]-\" ;\n" +
" bf:providerName [ a bf:Organization ;\n" +
" bf:label \"SOA Watch\" ] ;\n" +
" bf:providerPlace [ a bf:Place ;\n" +
" bf:label \"Washington, D.C. \" ] ] ;\n" +
" bf:serialFirstIssue \"Vol. 11, issue 3 (fall 2006)\" ;\n" +
" bf:stockNumber [ a bf:Identifier ;\n" +
" bf:identifierAssigner \"SOA Watch, P.O. Box 4566, Washington, DC 20017\" ;\n" +
" bf:identifierScheme \"stockNumber\" ] ] .";

createLDPRSAndCheckResponse(getRandomUniquePid(), bibframe);
}

}
@@ -0,0 +1,67 @@
/**
* 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.update.GraphStore;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.junit.Test;

import java.io.IOException;

import static javax.ws.rs.core.Response.Status.CREATED;
import static org.junit.Assert.assertFalse;

public class LdpIT extends AbstractIntegrationRdfIT {
@Test
public void testExample10() throws IOException {
final String pid = getRandomUniquePid();
final HttpResponse response = createObject(pid);
final String location = response.getFirstHeader("Location").getValue();

final String body = "\n" +
"@prefix ldp: <http://www.w3.org/ns/ldp#>.\n" +
"@prefix dcterms: <http://purl.org/dc/terms/>.\n" +
"@prefix o: <http://example.org/ontology#>.\n" +
"<> dcterms:title \"The liabilities of JohnZSmith\";\n" +
" ldp:membershipResource <" + location + ">;\n" +
" ldp:hasMemberRelation o:liability;\n";

createLDPRSAndCheckResponse(pid + "/liabilities", body);

final HttpPost httpPost1 = new HttpPost(serverAddress + pid + "/liabilities");
httpPost1.setHeader("Slug", "l1");
checkResponse(execute(httpPost1), CREATED);

final HttpPost httpPost2 = new HttpPost(serverAddress + pid + "/liabilities");
httpPost2.setHeader("Slug", "l2");
checkResponse(execute(httpPost2), CREATED);

final HttpPost httpPost3 = new HttpPost(serverAddress + pid + "/liabilities");
httpPost3.setHeader("Slug", "l3");
checkResponse(execute(httpPost3), CREATED);

final HttpGet httpGet = new HttpGet(location);
httpGet.addHeader("Prefer", "return=representation; " +
"include=\"http://www.w3.org/ns/ldp#PreferMembership http://www.w3.org/ns/ldp#PreferMinimalContainer\"; " +
"omit=\"http://fedora.info/definitions/v4/repository#ServerManaged\"");
final GraphStore graphStore = getGraphStore(httpGet);

logger.error(graphStore.toString());
assertFalse(graphStore.isEmpty());
}
}
@@ -0,0 +1,50 @@
/**
* 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 org.junit.Test;

public class OpenAnnotationIT extends AbstractIntegrationRdfIT {
@Test
public void testOpenAnnotationChoice() {
final String s = "@prefix content: <http://www.w3.org/2011/content#> .\n" +
"@prefix dc11: <http://purl.org/dc/elements/1.1/> .\n" +
"@prefix dcmitype: <http://purl.org/dc/dcmitype/> .\n" +
"@prefix openannotation: <http://www.w3.org/ns/oa#> .\n" +
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" +
"\n" +
"<> a openannotation:Annotation;\n" +
" openannotation:hasBody [\n" +
" a openannotation:Choice;\n" +
" openannotation:default [\n" +
" a content:ContentAsText,\n" +
" dcmitype:Text;\n" +
" dc11:language \"en\";\n" +
" content:chars \"I love this English!\"\n" +
" ];\n" +
" openannotation:item [\n" +
" a content:ContentAsText,\n" +
" dcmitype:Text;\n" +
" dc11:language \"fr\";\n" +
" content:chars \"Je l'aime en Francais!\"\n" +
" ]\n" +
" ];\n" +
" openannotation:hasTarget <http://purl.stanford.edu/kq131cs7229>;\n" +
" openannotation:motivatedBy openannotation:commenting .";
createLDPRSAndCheckResponse(getRandomUniquePid(), s);
}
}

0 comments on commit d64b1d5

Please sign in to comment.