Navigation Menu

Skip to content

Commit

Permalink
Completed positive persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 25, 2013
1 parent eb488cf commit 6c5f91a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
Expand Up @@ -98,7 +98,7 @@ public boolean apply(final Triple t) {
// we knock out managed RDF and non-Fedora RDF
this.stream =
new RdfStream(filter(stream, and(not(isManagedTriple),
isFedoraSubjectTriple)));
isFedoraSubjectTriple))).addNamespaces(stream.namespaces());
this.session = session;
this.jcrRdfTools = JcrRdfTools.withContext(graphSubjects, session);
}
Expand Down
Expand Up @@ -16,11 +16,14 @@

package org.fcrepo.kernel.utils.iterators;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.fcrepo.kernel.utils.JcrRdfTools.getJcrNamespaceForRDFNamespace;
import static org.fcrepo.kernel.utils.NodePropertiesTools.appendOrReplaceNodeProperty;
import static org.fcrepo.kernel.utils.NodePropertiesTools.getPropertyType;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Map;

import javax.jcr.NamespaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -63,15 +66,19 @@ protected void operateOnMixin(final Resource mixinResource,
final Node subjectNode) throws RepositoryException {
final String namespace = getJcrNamespaceForRDFNamespace(mixinResource.getNameSpace());
String namespacePrefix = null;
LOGGER.debug(
"Checking for namespace: {} in stream namespace mapping: {}",
namespace, stream().namespaces());
if (stream().namespaces().containsValue(namespace)) {
final Map<String, String> streamNSMap =
checkNotNull(stream().namespaces(),
"Use an empty map of namespaces, not null!");
if (streamNSMap.containsValue(namespace)) {
LOGGER.debug("Found namespace: {} in stream namespace mapping.",
namespace);
for (final String prefix : stream().namespaces().keySet()) {
if (stream().namespaces().get(prefix) == namespace) {
namespacePrefix = stream().namespaces().get(prefix);
for (final String prefix : streamNSMap.keySet()) {
final String streamNamespace = streamNSMap.get(prefix);
if (namespace.equals(streamNamespace)) {
LOGGER.debug(
"Found namespace: {} in stream namespace mapping with prefix: {}.",
namespace, namespacePrefix);
namespacePrefix = prefix;
}
}
} else {
Expand Down
Expand Up @@ -16,6 +16,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Iterator;
import java.util.Map;
Expand All @@ -37,6 +38,7 @@
import org.junit.Test;
import org.mockito.Mock;
import org.modeshape.jcr.api.NamespaceRegistry;
import org.slf4j.Logger;

import com.google.common.collect.ImmutableMap;
import com.hp.hpl.jena.graph.Triple;
Expand Down Expand Up @@ -92,36 +94,55 @@ public class RdfAdderTest {


@Test
public void testAdding() throws Exception {
testAdder = new RdfAdder(mockGraphSubjects, mockSession, mockStream);
public void testAddingProperty() throws Exception {
testAdder = new RdfAdder(mockGraphSubjects, mockSession, testStream);
testAdder.operateOnProperty(descriptiveStmnt, mockNode);
verify(mockNode).setProperty(propertyShortName, mockValue, UNDEFINED);

}

@Test
public void testAddingModelWithStreamNamespace() throws Exception {
testAdder = new RdfAdder(mockGraphSubjects, mockSession, testStream);
testAdder.operateOnMixin(mixinStmnt.getObject().asResource(), mockNode);
verify(mockNode).addMixin(anyString());
}

@Test(expected = MalformedRdfException.class)
public void testAddingWithBadNamespace() throws Exception {

// we drop our stream namespace map
testStream = new RdfStream(mockTriples);
when(
mockSession
.getNamespacePrefix(getJcrNamespaceForRDFNamespace(type
.getNameSpace()))).thenThrow(new NamespaceException("Expected."));
testAdder = new RdfAdder(mockGraphSubjects, mockSession, mockStream);
testAdder = new RdfAdder(mockGraphSubjects, mockSession, testStream);
testAdder.operateOnMixin(mixinStmnt.getObject().asResource(), mockNode);
}

@Test
public void testAddingWithRepoNamespace() throws Exception {
// we drop our stream namespace map
testStream = new RdfStream(mockTriples);
when(
mockSession
.getNamespacePrefix(getJcrNamespaceForRDFNamespace(type
.getNameSpace()))).thenReturn("rdf");
testAdder = new RdfAdder(mockGraphSubjects, mockSession, testStream);
testAdder.operateOnMixin(mixinStmnt.getObject().asResource(), mockNode);
}

@Test(expected = MalformedRdfException.class)
public void testAddingWithBadMixinOnNode() throws Exception {
when(mockNode.canAddMixin(mixinShortName)).thenReturn(false);
testAdder = new RdfAdder(mockGraphSubjects, mockSession, mockStream);
testAdder = new RdfAdder(mockGraphSubjects, mockSession, testStream);
testAdder.operateOnMixin(mixinStmnt.getObject().asResource(), mockNode);
}

@Test(expected = MalformedRdfException.class)
public void testAddingWithBadMixinForRepo() throws Exception {
when(mockNodeTypeManager.hasNodeType(mixinShortName)).thenReturn(false);
testAdder = new RdfAdder(mockGraphSubjects, mockSession, mockStream);
testAdder = new RdfAdder(mockGraphSubjects, mockSession, testStream);
testAdder.operateOnMixin(mixinStmnt.getObject().asResource(), mockNode);
}

Expand Down Expand Up @@ -169,7 +190,8 @@ public void setUp() throws RepositoryException {
mockNodeSubject);
when(mockTriples.hasNext()).thenReturn(true, true, false);
when(mockTriples.next()).thenReturn(descriptiveTriple, mixinTriple);
mockStream.addNamespaces(mockNamespaceMap);
testStream = new RdfStream(mockTriples);
testStream.addNamespaces(mockNamespaceMap);
}


Expand Down Expand Up @@ -203,9 +225,11 @@ public void setUp() throws RepositoryException {
@Mock
private Iterator<Triple> mockTriples;

private RdfStream mockStream = new RdfStream(mockTriples);
private RdfStream testStream;

@Mock
private GraphSubjects mockGraphSubjects;

private static final Logger LOGGER = getLogger(RdfAdderTest.class);

}

0 comments on commit 6c5f91a

Please sign in to comment.