Skip to content

Commit

Permalink
More cleanup in JcrRdfToolsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 11, 2013
1 parent 32b2c32 commit df5b5ca
Showing 1 changed file with 7 additions and 51 deletions.
Expand Up @@ -137,7 +137,6 @@
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.GraphStoreFactory;
import com.hp.hpl.jena.vocabulary.RDF;
Expand Down Expand Up @@ -199,6 +198,7 @@ private void addPropertiesToMockNodes() throws RepositoryException {
private void addContentNode() throws RepositoryException {
when(mockNode.hasNode(JCR_CONTENT)).thenReturn(true);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockNodeContent);
when(mockNodeContent.getSession()).thenReturn(mockSession);
when(mockNodeContent.getPath()).thenReturn("/test/jcr/jcr:content");
when(mockBinary.getKey()).thenReturn(new BinaryKey("abc"));
when(mockProperty.getBinary()).thenReturn(mockBinary);
Expand Down Expand Up @@ -314,7 +314,6 @@ public void shouldExcludeBinaryProperties() throws RepositoryException, IOExcept

@Test
public void shouldBeAbleToDisableResourceInlining() throws RepositoryException {
when(mockNode.getPath()).thenReturn("/test/jcr");

final Model actual = testObj.getJcrTreeModel(mockNode, 0, -2);
assertEquals(0, Iterators.size(actual.listObjectsOfProperty(actual.createProperty("http://www.w3.org/ns/ldp#inlinedResource"))));
Expand All @@ -324,17 +323,12 @@ public void shouldBeAbleToDisableResourceInlining() throws RepositoryException {

@Test
public void shouldIncludeLinkedDataPlatformContainerInformation() throws RepositoryException {
when(mockParent.getPath()).thenReturn("/test");
when(mockNode.getPath()).thenReturn("/test/jcr");
when(mockNode.getParent()).thenReturn(mockParent);

final NodeType mockPrimaryNodeType = mock(NodeType.class);
when(mockPrimaryNodeType.getChildNodeDefinitions()).thenReturn(
new NodeDefinition[] { mock(NodeDefinition.class) }
);
when(mockNode.getPrimaryNodeType()).thenReturn(mockPrimaryNodeType);

when(mockParent.getProperties()).thenReturn(mockProperties);
when(mockProperties.hasNext()).thenReturn(false);

when(mockNode.getDepth()).thenReturn(0);
Expand All @@ -355,9 +349,6 @@ public void shouldIncludeLinkedDataPlatformContainerInformation() throws Reposit

@Test
public void shouldIncludeContainerInfoWithMixinTypeContainer() throws RepositoryException {
when(mockParent.getPath()).thenReturn("/test");
when(mockNode.getPath()).thenReturn("/test/jcr");
when(mockNode.getParent()).thenReturn(mockParent);

final NodeType mockPrimaryNodeType = mock(NodeType.class);
final NodeType mockMixinNodeType = mock(NodeType.class);
Expand All @@ -371,12 +362,10 @@ public void shouldIncludeContainerInfoWithMixinTypeContainer() throws Repository
when(mockNode.getPrimaryNodeType()).thenReturn(mockPrimaryNodeType);
when(mockNode.getMixinNodeTypes()).thenReturn(new NodeType[] { mockMixinNodeType });

when(mockParent.getProperties()).thenReturn(mockProperties);
when(mockProperties.hasNext()).thenReturn(false);

when(mockNode.getDepth()).thenReturn(0);
when(mockNodes.hasNext()).thenReturn(false);
when(mockNode.getNodes()).thenReturn(mockNodes);
final Model actual = testObj.getJcrTreeModel(mockNode, 0, -1);
assertTrue(actual.contains(testSubjects.getContext(), RDF.type, actual.createProperty("http://www.w3.org/ns/ldp#Page")));
assertTrue(actual.contains(testSubjects.getContext(), actual.createProperty("http://www.w3.org/ns/ldp#membersInlined"), actual.createTypedLiteral(true)));
Expand Down Expand Up @@ -405,12 +394,10 @@ public void shouldNotIncludeContainerInfoIfItIsntContainer() throws RepositoryEx
when(mockNode.getPrimaryNodeType()).thenReturn(mockPrimaryNodeType);
when(mockNode.getMixinNodeTypes()).thenReturn(new NodeType[] { mockMixinNodeType });

when(mockParent.getProperties()).thenReturn(mockProperties);
when(mockProperties.hasNext()).thenReturn(false);

when(mockNode.getDepth()).thenReturn(0);
when(mockNodes.hasNext()).thenReturn(false);
when(mockNode.getNodes()).thenReturn(mockNodes);
final Model actual = testObj.getJcrTreeModel(mockNode, 0, -1);
assertTrue(actual.contains(testSubjects.getContext(), RDF.type, actual.createProperty("http://www.w3.org/ns/ldp#Page")));
assertFalse(actual.contains(testSubjects.getContext(), actual.createProperty("http://www.w3.org/ns/ldp#membersInlined"), actual.createTypedLiteral(true)));
Expand All @@ -426,39 +413,26 @@ public void shouldNotIncludeContainerInfoIfItIsntContainer() throws RepositoryEx

@Test
public void shouldIncludeParentNodeInformation() throws RepositoryException {
when(mockParent.getPath()).thenReturn("/test");
when(mockNode.getPath()).thenReturn("/test/jcr");
when(mockNode.getParent()).thenReturn(mockParent);

final NodeType mockPrimaryNodeType = mock(NodeType.class);
when(mockPrimaryNodeType.getChildNodeDefinitions()).thenReturn(
new NodeDefinition[] { mock(NodeDefinition.class) }
);
when(mockNode.getPrimaryNodeType()).thenReturn(mockPrimaryNodeType);

when(mockParent.getProperties()).thenReturn(mockProperties);
when(mockProperties.hasNext()).thenReturn(false);

when(mockNode.getDepth()).thenReturn(2);
when(mockNodes.hasNext()).thenReturn(false);
when(mockNode.getNodes()).thenReturn(mockNodes);
final Model actual = testObj.getJcrTreeModel(mockNode, 0, -1);
assertEquals(1, Iterators.size(actual.listObjectsOfProperty(HAS_CHILD)));
}

@Test
public void shouldIncludeChildNodeInformation() throws RepositoryException {
when(mockParent.getPath()).thenReturn("/test");
when(mockNode.getPath()).thenReturn("/test/jcr");
when(mockNode.getParent()).thenReturn(mockParent);

final NodeType mockPrimaryNodeType = mock(NodeType.class);
when(mockPrimaryNodeType.getChildNodeDefinitions()).thenReturn(
new NodeDefinition[] { mock(NodeDefinition.class) }
);
when(mockNode.getPrimaryNodeType()).thenReturn(mockPrimaryNodeType);

when(mockParent.getProperties()).thenReturn(mockProperties);
when(mockProperties.hasNext()).thenReturn(false);

when(mockNode.getDepth()).thenReturn(0);
Expand All @@ -469,21 +443,14 @@ public void shouldIncludeChildNodeInformation() throws RepositoryException {
false);
when(mockNode.hasNodes()).thenReturn(true);
when(mockNodes.nextNode()).thenReturn(mockChildNode);

when(mockNode.getNodes()).thenReturn(mockNodes);
final Model actual = testObj.getJcrTreeModel(mockNode, 0, 0);
assertEquals(5, Iterators.size(actual.listObjectsOfProperty(HAS_CHILD)));
}

@Test
public void shouldIncludeFullChildNodeInformationInsideWindow()
throws RepositoryException {
when(mockParent.getPath()).thenReturn("/test");
when(mockNode.getPath()).thenReturn("/test/jcr");
when(mockNode.getParent()).thenReturn(mockParent);
when(mockNode.getDepth()).thenReturn(0);


final NodeType mockPrimaryNodeType = mock(NodeType.class);
when(mockPrimaryNodeType.getChildNodeDefinitions()).thenReturn(
new NodeDefinition[] { mock(NodeDefinition.class) }
Expand All @@ -503,7 +470,6 @@ public void shouldIncludeFullChildNodeInformationInsideWindow()
when(mockNode.hasNodes()).thenReturn(true);
when(mockNodes.nextNode()).thenReturn(mockChildNode, mockFullChildNode,
mockFullChildNode, mockChildNode, mockChildNode);
when(mockNode.getNodes()).thenReturn(mockNodes);
final Model actual = testObj.getJcrTreeModel(mockNode, 1, 2);
assertEquals(2, Iterators.size(actual.listSubjectsWithProperty(RdfLexicon.HAS_PARENT)));
verify(mockChildNode, never()).getProperties();
Expand Down Expand Up @@ -749,19 +715,9 @@ public void shouldMapJcrTypesToRdfDataTypes() throws RepositoryException {
@Test
@Ignore
public void testJcrNodeContent() throws RepositoryException {

when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNode.getPrimaryNodeType().getName()).thenReturn("");
addContentNode();
when(mockProperties.hasNext()).thenReturn(false);
when(mockNode.getProperties()).thenReturn(mockProperties);
when(mockNode.getPath()).thenReturn("/path/to/node");
when(mockNodes.hasNext()).thenReturn(false);
when(mockNode.getNodes()).thenReturn(mockNodes);
when(mockContentNode.getPath()).thenReturn("/path/to/node/content");
when(mockContentNode.getProperties()).thenReturn(mockProperties);
when(mockContentNode.getSession()).thenReturn(mockSession);
when(mockNode.hasNode(JCR_CONTENT)).thenReturn(true);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContentNode);

final Model model = testObj.getJcrPropertiesModel(mockNode);

Expand Down Expand Up @@ -887,11 +843,11 @@ public void testGetJcrVersionsModel() throws Exception {

@Test
public void testIsInternalProperty() throws Exception {
assertTrue(testObj.isInternalProperty(mockNode, ResourceFactory.createProperty(REPOSITORY_NAMESPACE, "some-property")));
assertTrue(testObj.isInternalProperty(mockNode, ResourceFactory.createProperty("http://www.jcp.org/jcr/1.0", "some-property")));
assertTrue(testObj.isInternalProperty(mockNode, ResourceFactory.createProperty("http://www.w3.org/ns/ldp#some-property")));
assertFalse(testObj.isInternalProperty(mockNode, ResourceFactory.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#label")));
assertFalse(testObj.isInternalProperty(mockNode, ResourceFactory.createProperty("my-own-ns", "some-property")));
assertTrue(testObj.isInternalProperty(mockNode, createProperty(REPOSITORY_NAMESPACE, "some-property")));
assertTrue(testObj.isInternalProperty(mockNode, createProperty("http://www.jcp.org/jcr/1.0", "some-property")));
assertTrue(testObj.isInternalProperty(mockNode, createProperty("http://www.w3.org/ns/ldp#some-property")));
assertFalse(testObj.isInternalProperty(mockNode, createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#label")));
assertFalse(testObj.isInternalProperty(mockNode, createProperty("my-own-ns", "some-property")));
}

private void mockNamespaceRegistry() throws RepositoryException {
Expand Down

0 comments on commit df5b5ca

Please sign in to comment.