@Test(expected = PathNotFoundException.class) public void shouldNotAllowHashUriSubjectsForResourcesThatDontExist() throws RepositoryException { final Model m = createDefaultModel(); final Statement x = m.createStatement( testSubjects.toDomain("/some/#/abc"), createProperty("info:x"), testSubjects.toDomain("/")); testObj.jcrTools = mock(JcrTools.class); when(mockNode.getParent()).thenReturn(mockHashNode); when(mockHashNode.getParent()).thenReturn(mockChildNode); when(mockSession.nodeExists("/some")).thenReturn(false); when(testObj.jcrTools.findOrCreateNode(mockSession, "/some/#/abc", NT_FOLDER)) .thenReturn(mockNode); testObj.skolemize(testSubjects, x); }
@Test public void shouldIgnoreHashUrisOutsideTheRepositoryDomain() throws RepositoryException { final Model m = createDefaultModel(); final Statement x = m.createStatement( testSubjects.toDomain("/"), createProperty("info:x"), createResource("info:x#abc")); final Statement statement = testObj.skolemize(testSubjects, x); assertEquals(x, statement); }
@Test public void shouldPassthroughValidStatements() throws RepositoryException { final Model m = createDefaultModel(); final Statement x = m.createStatement( testSubjects.toDomain("/"), createProperty("info:x"), createPlainLiteral("x")); final Statement statement = testObj.skolemize(testSubjects, x); assertEquals(x, statement); }
@Test public void shouldCreateHashUriObjects() throws RepositoryException { final Model m = createDefaultModel(); final Statement x = m.createStatement( testSubjects.toDomain("/"), createProperty("info:x"), testSubjects.toDomain("/some/#/abc")); testObj.jcrTools = mock(JcrTools.class); when(mockNode.getParent()).thenReturn(mockHashNode); when(mockHashNode.getParent()).thenReturn(mockChildNode); when(mockSession.nodeExists("/some")).thenReturn(true); when(mockSession.getNode("/some")).thenReturn(mockChildNode); when(testObj.jcrTools.findOrCreateNode(mockSession, "/some/#/abc", NT_FOLDER)) .thenReturn(mockNode); final Statement statement = testObj.skolemize(testSubjects, x); assertEquals(x, statement); verify(testObj.jcrTools).findOrCreateNode(mockSession, "/some/#/abc", NT_FOLDER); verify(mockNode).addMixin(FEDORA_RESOURCE); }
@Test public void shouldSkolemizeBlankNodeObjects() throws RepositoryException { final Model m = createDefaultModel(); final Statement x = m.createStatement(testSubjects.toDomain("/"), createProperty("info:x"), createResource()); testObj.jcrTools = mock(JcrTools.class); when(testObj.jcrTools.findOrCreateNode(eq(mockSession), anyString())).thenReturn(mockNode); when(mockNode.getPath()).thenReturn("/.well-known/x"); final Statement statement = testObj.skolemize(testSubjects, x); assertEquals("info:fedora/.well-known/x", statement.getObject().toString()); }
@Test public final void shouldMapReferenceValuesToJcrPropertyValues() throws RepositoryException { final RDFNode n = testSubjects.toDomain("/abc"); // node references when(mockSession.getNode("/abc")).thenReturn(mockNode); when(mockSession.nodeExists("/abc")).thenReturn(true); testObj.createValue(mockValueFactory, n, REFERENCE); verify(mockValueFactory).createValue(mockNode, false); testObj.createValue(mockValueFactory, n, WEAKREFERENCE); verify(mockValueFactory).createValue(mockNode, true); }
@Test public void shouldAddReferencePropertyForDomainObject() throws RepositoryException { when(mockNodeType.getPropertyDefinitions()).thenReturn(new PropertyDefinition[] {}); when(mockNode.getMixinNodeTypes()).thenReturn(new NodeType[] {}); when(mockValueFactory.createValue(anyString(), eq(STRING))).thenReturn(mockValue); when(mockValueFactory.createValue(mockNode, true)).thenReturn(mockReferenceValue); when(mockSession.getNode("/x")).thenReturn(mockNode); when(mockNode.setProperty(anyString(), any(Value[].class), anyInt())).thenReturn(mockProperty); testObj.addProperty( mockFedoraResource, createProperty("some:property"), testSubjects.toDomain("x"), Collections.<String, String>emptyMap()); verify(mockNode) .setProperty( "some:property_ref", new Value[] {mockReferenceValue}, mockReferenceValue.getType()); }