Skip to content

Commit

Permalink
exclude BINARY properties from the graph serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 15, 2013
1 parent 0646968 commit 88fbd38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/utils/JcrRdfTools.java
Expand Up @@ -330,6 +330,11 @@ public static void addPropertyToModel(final Resource subject, final Model model,
*/
public static void addPropertyToModel(final Resource subject, final Model model, final Property property, Value v) throws RepositoryException {

if (v.getType() == PropertyType.BINARY) {
// exclude binary types from property serialization
return;
}

final com.hp.hpl.jena.rdf.model.Property predicate = FedoraTypesUtils.getPredicateForProperty.apply(property);

final String stringValue = v.getString();
Expand Down
32 changes: 32 additions & 0 deletions fcrepo-kernel/src/test/java/org/fcrepo/utils/JcrRdfToolsTest.java
Expand Up @@ -197,6 +197,38 @@ public void testGetPropertiesModel() throws RepositoryException {
//TODO exercise non-empty PropertyIterator
}


@Test
public void shouldExcludeBinaryProperties() throws RepositoryException {
String fakeInternalUri = "info:fedora/test/jcr";
Node mockParent = mock(Node.class);
when(mockParent.getPath()).thenReturn("/test");
when(mockNode.getPath()).thenReturn("/test/jcr");
when(mockNode.getParent()).thenReturn(mockParent);
javax.jcr.NodeIterator mockNodes = mock(javax.jcr.NodeIterator.class);
when(mockNode.getNodes()).thenReturn(mockNodes);
PowerMockito.mockStatic(NamespaceTools.class);
NamespaceRegistry mockNames = mock(NamespaceRegistry.class);
String[] testPrefixes = new String[]{"jcr"};
when(mockNames.getPrefixes()).thenReturn(testPrefixes);
when(mockNames.getURI("jcr")).thenReturn(fakeInternalUri);
when(NamespaceTools.getNamespaceRegistry(mockNode)).thenReturn(mockNames);
javax.jcr.PropertyIterator mockProperties = mock(PropertyIterator.class);
when(mockNode.getProperties()).thenReturn(mockProperties);
when(mockParent.getProperties()).thenReturn(mockProperties);
when(mockProperties.hasNext()).thenReturn(true, false);
javax.jcr.Property mockProperty = mock(javax.jcr.Property.class);
Value mockValue = mock(Value.class);
when(mockProperty.getValue()).thenReturn(mockValue);
when(mockValue.getType()).thenReturn(PropertyType.BINARY);
when(mockProperties.nextProperty()).thenReturn(mockProperty);

Model actual = JcrRdfTools.getJcrPropertiesModel(mockNode);

// we expect 2 statements, both auto-generated
assertEquals(2, actual.size());
}

@Test
public void shouldMapRdfValuesToJcrPropertyValues()
throws RepositoryException {
Expand Down

0 comments on commit 88fbd38

Please sign in to comment.