Skip to content

Commit

Permalink
Merge pull request #789 from fcrepo4/fcrepo-1521
Browse files Browse the repository at this point in the history
NonRDFSources now include rdf:type=ldp:NonRDFSource triple
  • Loading branch information
Andrew Woods committed May 6, 2015
2 parents 87db499 + 52b0d8a commit 31e068b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
Expand Up @@ -259,6 +259,9 @@ public boolean apply(final Triple input) {
rdfStream.concat(filter(described.getTriples(translator(), ImmutableList.of(TypeRdfContext.class,
PropertiesRdfContext.class,
ContentRdfContext.class)), tripleFilter));
if (ldpPreferences.prefersServerManaged()) {
rdfStream.concat(getTriples(described,LdpRdfContext.class));
}
}

// Embed all hash and blank nodes
Expand Down
Expand Up @@ -594,6 +594,7 @@ public void testGetWithBinaryDescription() throws Exception {
final NonRdfSourceDescription mockResource
= (NonRdfSourceDescription)setResource(NonRdfSourceDescription.class);
when(mockResource.getDescribedResource()).thenReturn(mockBinary);
when(mockBinary.getTriples(eq(idTranslator), any(Class.class))).thenReturn(new RdfStream());
when(mockBinary.getTriples(eq(idTranslator), any(List.class))).thenReturn(new RdfStream(new Triple
(createURI("mockBinary"), createURI("called"), createURI("child:properties"))));
final Response actual = testObj.describe(null);
Expand Down Expand Up @@ -734,6 +735,7 @@ public void testPatchBinaryDescription() throws Exception {
final NonRdfSourceDescription mockObject = (NonRdfSourceDescription)setResource(NonRdfSourceDescription.class);
when(mockObject.getDescribedResource()).thenReturn(mockBinary);

when(mockBinary.getTriples(eq(idTranslator), any(Class.class))).thenReturn(new RdfStream());
when(mockBinary.getTriples(eq(idTranslator), any(List.class))).thenReturn(
new RdfStream(new Triple(createURI("mockBinary"), createURI("called"), createURI("child:properties"))));

Expand Down
Expand Up @@ -69,6 +69,7 @@
import static org.fcrepo.kernel.RdfLexicon.MEMBERSHIP_RESOURCE;
import static org.fcrepo.kernel.RdfLexicon.MIX_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.NEXT_PAGE;
import static org.fcrepo.kernel.RdfLexicon.NON_RDF_SOURCE;
import static org.fcrepo.kernel.RdfLexicon.RDF_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -456,18 +457,15 @@ public void testGetNonRDFSourceDescription() throws Exception {

final HttpGet httpGet = new HttpGet(serverAddress + pid + "/x/" + FCR_METADATA);
final HttpResponse response = execute(httpGet);
assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());

final HttpEntity entity = response.getEntity();
final String content = EntityUtils.toString(entity);

assertEquals(OK.getStatusCode(), response.getStatusLine()
.getStatusCode());

final MediaType mediaType = MediaType.valueOf(entity.getContentType().getValue());
final Lang lang = contentTypeToLang(mediaType.toString());
assertNotNull("Entity is not an RDF serialization", lang);
LOGGER.warn(content);

final GraphStore graphStore = getGraphStore(response);
final Node rdfType = createURI(RDF_NAMESPACE + "type");
assertTrue("Description should be a fedora:NonRdfSourceDescription",
graphStore.contains(ANY, createURI(serverAddress + pid + "/x/" + FCR_METADATA), rdfType,
createURI(REPOSITORY_NAMESPACE + "NonRdfSourceDescription")));
assertTrue("Binary should be a ldp:NonRDFSource",
graphStore.contains(ANY, createURI(serverAddress + pid + "/x"), rdfType, NON_RDF_SOURCE.asNode()));
}

@Test
Expand Down
Expand Up @@ -20,11 +20,13 @@
import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.BASIC_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.NON_RDF_SOURCE;
import static org.fcrepo.kernel.RdfLexicon.RDF_SOURCE;

import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.models.Container;
import org.fcrepo.kernel.models.FedoraResource;
import org.fcrepo.kernel.models.NonRdfSource;

import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Resource;
Expand All @@ -46,7 +48,12 @@ public LdpRdfContext(final FedoraResource resource,
final IdentifierConverter<Resource, FedoraResource> idTranslator) {
super(resource, idTranslator);

concat(typeContext());

if (resource instanceof NonRdfSource) {
concat(nonRdfSourceContext());
} else {
concat(typeContext());
}

if (resource instanceof Container) {
concat(containerContext());
Expand All @@ -69,4 +76,8 @@ private Triple containerContext() {
private Triple defaultContainerContext() {
return create(subject(), type.asNode(), BASIC_CONTAINER.asNode());
}

private Triple nonRdfSourceContext() {
return create(subject(), type.asNode(), NON_RDF_SOURCE.asNode());
}
}
Expand Up @@ -18,6 +18,7 @@
import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.BASIC_CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.CONTAINER;
import static org.fcrepo.kernel.RdfLexicon.NON_RDF_SOURCE;
import static org.fcrepo.kernel.RdfLexicon.RDF_SOURCE;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -27,6 +28,7 @@
import javax.jcr.Session;

import org.fcrepo.kernel.models.Container;
import org.fcrepo.kernel.models.FedoraBinary;
import org.fcrepo.kernel.models.FedoraResource;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,6 +46,9 @@ public class LdpRdfContextTest {
@Mock
private FedoraResource mockResource;

@Mock
private FedoraBinary mockBinary;

@Mock
private Container mockContainer;
@Mock
Expand All @@ -58,7 +63,7 @@ public class LdpRdfContextTest {
public void setUp() {
initMocks(this);
when(mockResource.getPath()).thenReturn("/a");

when(mockBinary.getPath()).thenReturn("/a");
when(mockContainer.getPath()).thenReturn("/a");

subjects = new DefaultIdentifierTranslator(mockSession);
Expand All @@ -72,6 +77,14 @@ public void shouldIncludeRdfTypeAssertions() {
assertTrue(model.contains(subject(), RDF.type, RDF_SOURCE));
}

@Test
public void shouldIncludeBinaryTypeAssertions() {
testObj = new LdpRdfContext(mockBinary, subjects);
final Model model = testObj.asModel();

assertTrue(model.contains(subject(), RDF.type, NON_RDF_SOURCE));
}

@Test
public void shouldIncludeRdfContainerAssertions() {
testObj = new LdpRdfContext(mockContainer, subjects);
Expand Down Expand Up @@ -102,4 +115,4 @@ private Resource subject() {
return subjects.reverse().convert(mockResource);
}

}
}

0 comments on commit 31e068b

Please sign in to comment.