Skip to content
Permalink
Browse files

Fedora objects can be any type of LDP container

Objects may also choose not to be any formal type of LDP container, and just
have ldp:contains properties to its children.
  • Loading branch information...
cbeer committed Oct 27, 2014
1 parent d67b0fa commit 92733d103a02413c80fa0b85ff3a1b4dfd8376d3
@@ -13,5 +13,4 @@ ObjectStore/
*~
fcrepo4-data/
*.iml
fcrepo-integration-ldp/report
fcrepo-integration-ldp/test-output
fcrepo-integration-ldp/report-*
@@ -93,6 +93,14 @@
import static javax.ws.rs.core.Response.status;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.apache.jena.riot.RDFLanguages.contentTypeToLang;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_CONTAINER;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_BASIC_CONTAINER;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_DIRECT_CONTAINER;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_INDIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.BASIC_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.DIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.INDIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.isManagedNamespace;
import static org.slf4j.LoggerFactory.getLogger;
@@ -406,7 +414,16 @@ protected void addResourceHttpHeaders(final FedoraResource resource) {
} else if (resource instanceof FedoraBinary) {
servletResponse.addHeader("Link", "<" + LDP_NAMESPACE + "NonRDFSource>;rel=\"type\"");
} else if (resource instanceof FedoraObject) {
servletResponse.addHeader("Link", "<" + LDP_NAMESPACE + "DirectContainer>;rel=\"type\"");
servletResponse.addHeader("Link", "<" + CONTAINER.getURI() + ">;rel=\"type\"");
if (resource.hasType(LDP_BASIC_CONTAINER)) {
servletResponse.addHeader("Link", "<" + BASIC_CONTAINER.getURI() + ">;rel=\"type\"");
} else if (resource.hasType(LDP_DIRECT_CONTAINER)) {
servletResponse.addHeader("Link", "<" + DIRECT_CONTAINER.getURI() + ">;rel=\"type\"");
} else if (resource.hasType(LDP_INDIRECT_CONTAINER)) {
servletResponse.addHeader("Link", "<" + INDIRECT_CONTAINER.getURI() + ">;rel=\"type\"");
} else if (!resource.hasType(FEDORA_CONTAINER)) {
servletResponse.addHeader("Link", "<" + BASIC_CONTAINER.getURI() + ">;rel=\"type\"");
}
}

}
@@ -70,7 +70,13 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES_TYPE;
import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl;
import static org.fcrepo.http.commons.test.util.TestHelpers.mockSession;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_BASIC_CONTAINER;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_DIRECT_CONTAINER;
import static org.fcrepo.jcr.FedoraJcrTypes.LDP_INDIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.BASIC_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.DIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.INBOUND_REFERENCES;
import static org.fcrepo.kernel.RdfLexicon.INDIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -201,12 +207,50 @@ public void testHeadWithObject() throws Exception {
setResource(FedoraObject.class);
final Response actual = testObj.head();
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP DirectContainer",
mockResponse.getHeaders("Link").contains("<" + LDP_NAMESPACE + "DirectContainer>;rel=\"type\""));
assertTrue("Should advertise Accept-Post flavors", mockResponse.containsHeader("Accept-Post"));
assertTrue("Should advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
}

@Test
public void testHeadWithDefaultContainer() throws Exception {
setResource(FedoraObject.class);
final Response actual = testObj.head();
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP BasicContainer",
mockResponse.getHeaders("Link").contains("<" + BASIC_CONTAINER.getURI() + ">;rel=\"type\""));
}


@Test
public void testHeadWithBasicContainer() throws Exception {
final FedoraResource resource = setResource(FedoraObject.class);
when(resource.hasType(LDP_BASIC_CONTAINER)).thenReturn(true);
final Response actual = testObj.head();
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP BasicContainer",
mockResponse.getHeaders("Link").contains("<" + BASIC_CONTAINER.getURI() + ">;rel=\"type\""));
}

@Test
public void testHeadWithDirectContainer() throws Exception {
final FedoraResource resource = setResource(FedoraObject.class);
when(resource.hasType(LDP_DIRECT_CONTAINER)).thenReturn(true);
final Response actual = testObj.head();
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP DirectContainer",
mockResponse.getHeaders("Link").contains("<" + DIRECT_CONTAINER.getURI() + ">;rel=\"type\""));
}

@Test
public void testHeadWithIndirectContainer() throws Exception {
final FedoraResource resource = setResource(FedoraObject.class);
when(resource.hasType(LDP_INDIRECT_CONTAINER)).thenReturn(true);
final Response actual = testObj.head();
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP IndirectContainer",
mockResponse.getHeaders("Link").contains("<" + INDIRECT_CONTAINER.getURI() + ">;rel=\"type\""));
}

@Test
public void testHeadWithBinary() throws Exception {
final FedoraBinary mockResource = (FedoraBinary)setResource(FedoraBinary.class);
@@ -321,8 +365,6 @@ public void testGetWithObject() throws Exception {
setResource(FedoraObject.class);
final Response actual = testObj.describe(null);
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP DirectContainer",
mockResponse.getHeaders("Link").contains("<" + LDP_NAMESPACE + "DirectContainer>;rel=\"type\""));
assertTrue("Should advertise Accept-Post flavors", mockResponse.containsHeader("Accept-Post"));
assertTrue("Should advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));

@@ -349,6 +391,37 @@ public String apply(final RDFNode input) {

}


@Test
public void testGetWithBasicContainer() throws Exception {
final FedoraResource resource = setResource(FedoraObject.class);
when(resource.hasType(LDP_BASIC_CONTAINER)).thenReturn(true);
final Response actual = testObj.describe(null);
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP BasicContainer",
mockResponse.getHeaders("Link").contains("<" + BASIC_CONTAINER.getURI() + ">;rel=\"type\""));
}

@Test
public void testGetWithDirectContainer() throws Exception {
final FedoraResource resource = setResource(FedoraObject.class);
when(resource.hasType(LDP_DIRECT_CONTAINER)).thenReturn(true);
final Response actual = testObj.describe(null);
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP DirectContainer",
mockResponse.getHeaders("Link").contains("<" + DIRECT_CONTAINER.getURI() + ">;rel=\"type\""));
}

@Test
public void testGetWithIndirectContainer() throws Exception {
final FedoraResource resource = setResource(FedoraObject.class);
when(resource.hasType(LDP_INDIRECT_CONTAINER)).thenReturn(true);
final Response actual = testObj.describe(null);
assertEquals(OK.getStatusCode(), actual.getStatus());
assertTrue("Should be an LDP IndirectContainer",
mockResponse.getHeaders("Link").contains("<" + INDIRECT_CONTAINER.getURI() + ">;rel=\"type\""));
}

@Test
public void testGetWithObjectPreferMinimal() throws Exception {
setResource(FedoraObject.class);
@@ -49,8 +49,10 @@
import static org.apache.jena.riot.WebContent.contentTypeTurtle;
import static org.fcrepo.jcr.FedoraJcrTypes.FCR_METADATA;
import static org.fcrepo.jcr.FedoraJcrTypes.ROOT;
import static org.fcrepo.kernel.RdfLexicon.BASIC_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.CONTAINS;
import static org.fcrepo.kernel.RdfLexicon.DC_TITLE;
import static org.fcrepo.kernel.RdfLexicon.DIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD;
import static org.fcrepo.kernel.RdfLexicon.HAS_MEMBER_RELATION;
@@ -59,6 +61,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_IDENTIFIER;
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_TYPE;
import static org.fcrepo.kernel.RdfLexicon.INBOUND_REFERENCES;
import static org.fcrepo.kernel.RdfLexicon.INDIRECT_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.JCR_NT_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.LDP_MEMBER;
import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
@@ -181,6 +184,72 @@ public void testHeadObject() throws Exception {
assertEquals(200, getStatus(headObjMethod));
}

@Test
public void testHeadDefaultContainer() throws Exception {
final String pid = getRandomUniquePid();

createObject(pid);

final String location = serverAddress + pid;
final HttpHead headObjMethod = new HttpHead(location);
final HttpResponse response = client.execute(headObjMethod);

final Collection<String> links = getLinkHeaders(response);
assertTrue("Didn't find LDP container link header!", links.contains("<" + BASIC_CONTAINER.getURI() + ">;" +
"rel=\"type\""));
}

@Test
public void testHeadBasicContainer() throws Exception {
final String pid = getRandomUniquePid();

createObject(pid);
addMixin(pid, BASIC_CONTAINER.getURI());

final String location = serverAddress + pid;
final HttpHead headObjMethod = new HttpHead(location);
final HttpResponse response = client.execute(headObjMethod);

final Collection<String> links = getLinkHeaders(response);
assertTrue("Didn't find LDP container link header!", links.contains("<" + BASIC_CONTAINER.getURI() + ">;" +
"rel=\"type\""));
}


@Test
public void testHeadDirectContainer() throws Exception {
final String pid = getRandomUniquePid();

createObject(pid);
addMixin(pid, DIRECT_CONTAINER.getURI());

final String location = serverAddress + pid;
final HttpHead headObjMethod = new HttpHead(location);
final HttpResponse response = client.execute(headObjMethod);

final Collection<String> links = getLinkHeaders(response);
assertTrue("Didn't find LDP container link header!", links.contains("<" + DIRECT_CONTAINER.getURI() + ">;" +
"rel=\"type\""));
}

@Test
public void testHeadIndirectContainer() throws Exception {
final String pid = getRandomUniquePid();

createObject(pid);
addMixin(pid, INDIRECT_CONTAINER.getURI());

final String location = serverAddress + pid;
final HttpHead headObjMethod = new HttpHead(location);
final HttpResponse response = client.execute(headObjMethod);

final Collection<String> links = getLinkHeaders(response);
assertTrue("Didn't find LDP container link header!", links.contains("<" + INDIRECT_CONTAINER.getURI() + ">;" +
"rel=\"type\""));
}



@Test
public void testHeadDatastream() throws Exception {
final String pid = getRandomUniquePid();
@@ -1126,7 +1195,6 @@ public void verifyFullSetOfRdfTypes() throws Exception {

verifyResource(model, nodeUri, rdfType, RESTAPI_NAMESPACE, "object");
verifyResource(model, nodeUri, rdfType, RESTAPI_NAMESPACE, "resource");
verifyResource(model, nodeUri, rdfType, LDP_NAMESPACE, "DirectContainer");
verifyResource(model, nodeUri, rdfType, MIX_NAMESPACE, "created");
verifyResource(model, nodeUri, rdfType, MIX_NAMESPACE, "lastModified");
verifyResource(model, nodeUri, rdfType, MIX_NAMESPACE, "referenceable");
@@ -1182,14 +1250,13 @@ public void testGetObjectGraphWithChildren() throws Exception {
final Collection<String> links = getLinkHeaders(response);
assertTrue("Didn't find LDP resource link header!",
links.contains("<" + LDP_NAMESPACE + "Resource>;rel=\"type\""));
assertTrue("Didn't find LDP container link header!",
links.contains("<" + LDP_NAMESPACE + "DirectContainer>;rel=\"type\""));
}

@Test
public void testGetObjectGraphMinimal() throws Exception {
final String pid = getRandomUniquePid();
createObject(pid);
addMixin(pid, BASIC_CONTAINER.getURI());
createObject(pid + "/a");
final HttpGet getObjMethod =
new HttpGet(serverAddress + pid);
@@ -1222,6 +1289,7 @@ public void testGetObjectGraphMinimal() throws Exception {
public void testGetObjectOmitMembership() throws Exception {
final String pid = getRandomUniquePid();
createObject(pid);
addMixin(pid, BASIC_CONTAINER.getURI());
createObject(pid + "/a");
final HttpGet getObjMethod =
new HttpGet(serverAddress + pid);
@@ -1251,12 +1319,24 @@ public void testGetObjectOmitMembership() throws Exception {
public void testGetObjectOmitContainment() throws Exception {
final String pid = getRandomUniquePid();
createObject(pid);
final HttpPatch patch = new HttpPatch(serverAddress + pid);

patch.setHeader("Content-Type", "application/sparql-update");
final String updateString =
"INSERT DATA { <> a <" + DIRECT_CONTAINER.getURI() + "> ;" +
" <" + MEMBERSHIP_RESOURCE.getURI() + "> <> ;" +
" <" + HAS_MEMBER_RELATION + "> <" + LDP_NAMESPACE + "member> ." +
"}";
patch.setEntity(new StringEntity(updateString));
assertEquals(204, getStatus(patch));

createObject(pid + "/a");
final HttpGet getObjMethod =
new HttpGet(serverAddress + pid);
getObjMethod.addHeader("Prefer", "return=representation; omit=\"http://www.w3.org/ns/ldp#PreferContainment\"");
getObjMethod.addHeader("Accept", "application/n-triples");
final HttpResponse response = client.execute(getObjMethod);

assertEquals(OK.getStatusCode(), response.getStatusLine()
.getStatusCode());
final String content = EntityUtils.toString(response.getEntity());
@@ -1954,6 +2034,7 @@ public void testLdpContainerInteraction() throws Exception {
final HttpResponse object = createObject(id);
final String location = object.getFirstHeader("Location").getValue();
createObject(id + "/t");
addMixin(id + "/t", DIRECT_CONTAINER.getURI());

final HttpPatch patch = new HttpPatch(location + "/t");
final String sparql = "INSERT DATA { "
@@ -1967,8 +2048,8 @@ public void testLdpContainerInteraction() throws Exception {

assertEquals("Expected patch to succeed", 204, getStatus(patch));


createObject(id + "/b");
addMixin(id + "/b", DIRECT_CONTAINER.getURI());

final HttpPatch bPatch = new HttpPatch(location + "/b");
final String bSparql = "INSERT DATA { "
Oops, something went wrong.

0 comments on commit 92733d1

Please sign in to comment.
You can’t perform that action at this time.