Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 25, 2013
1 parent 6c93d97 commit eb488cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Expand Up @@ -103,6 +103,11 @@ protected void operateOnMixin(final Resource mixinResource,
+ " because no such mixin/type can be added to this node: "
+ subjectNode.getPath() + "!");
}
} else {
throw new MalformedRdfException(
"Could not persist triple containing type assertion:"
+ mixinResource.toString()
+ " because no such mixin/type can be found in the repository!");
}
}

Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.Map;

import javax.jcr.NamespaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -30,6 +31,7 @@
import javax.jcr.nodetype.NodeTypeManager;
import javax.jcr.nodetype.PropertyDefinition;

import org.fcrepo.kernel.exception.MalformedRdfException;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -98,6 +100,31 @@ public void testAdding() throws Exception {
verify(mockNode).addMixin(anyString());
}

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

when(
mockSession
.getNamespacePrefix(getJcrNamespaceForRDFNamespace(type
.getNameSpace()))).thenThrow(new NamespaceException("Expected."));
testAdder = new RdfAdder(mockGraphSubjects, mockSession, mockStream);
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.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.operateOnMixin(mixinStmnt.getObject().asResource(), mockNode);
}

@Before
public void setUp() throws RepositoryException {
initMocks(this);
Expand Down

0 comments on commit eb488cf

Please sign in to comment.