Skip to content
Permalink
Browse files

NonRDFSources now include rdf:type=ldp:NonRDFSource triple

  • Loading branch information...
escowles committed May 6, 2015
1 parent 87db499 commit 52b0d8a9683123f1382ce6a32687b7847caba60e
@@ -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
@@ -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);
@@ -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"))));

@@ -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;
@@ -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
@@ -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;
@@ -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());
@@ -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());
}
}
@@ -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;
@@ -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;
@@ -44,6 +46,9 @@
@Mock
private FedoraResource mockResource;

@Mock
private FedoraBinary mockBinary;

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

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

subjects = new DefaultIdentifierTranslator(mockSession);
@@ -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);
@@ -102,4 +115,4 @@ private Resource subject() {
return subjects.reverse().convert(mockResource);
}

}
}

0 comments on commit 52b0d8a

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