public void testGetLockOnNewChild() throws RepositoryException { Node newChild = lockedNode.addNode(nodeName3, testNodeType); if (isDeep()) { // get lock must succeed even if child is not lockable. Lock lock = newChild.getLock(); assertNotNull(lock); assertTrue( "Lock.getNode() must return the lock holding node", lockedNode.isSame(lock.getNode())); Lock lock2 = lockMgr.getLock(newChild.getPath()); assertNotNull(lock2); assertTrue( "Lock.getNode() must return the lock holding node", lockedNode.isSame(lock2.getNode())); } else { try { newChild.getLock(); fail("Node.getLock() must throw if node is not locked."); } catch (LockException e) { // success } try { lockMgr.getLock(newChild.getPath()); fail("LockManager.getLock(String) must throw if node is not locked."); } catch (LockException e) { // success } } }
@Test public void shouldReturnFalseFromIsSameIfTheRepositoryInstanceIsDifferent() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); Repository repository2 = mock(JcrRepository.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository2); when(workspace2.getName()).thenReturn("workspace1"); // Use the same id and location ... javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius")); assertThat(prius2.isSame(prius), is(false)); // Check the properties ... javax.jcr.Property model = prius.getProperty("vehix:model"); javax.jcr.Property model2 = prius2.getProperty("vehix:model"); assertThat(model.isSame(model2), is(false)); }
void recurse(Node node) throws RepositoryException { if (node instanceof HippoNode) { HippoNode hn = (HippoNode) node; Node canonicalNode = hn.getCanonicalNode(); if (canonicalNode == null) { return; } if (!canonicalNode.isSame(node)) { return; } } for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) { recurse(nodes.nextNode()); } }
/** * Tests that an XML document with an internal reference is correctly imported. This functionality * got broken by JCR-569. * * @throws Exception if an unexpected error occurs */ public void testReferenceImport() throws Exception { try { NodeId id = NodeId.randomId(); String xml = "<sv:node sv:name=\"a\"" + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"" + " xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"" + " xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:node sv:name=\"b\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:property sv:name=\"jcr:mixinTypes\" sv:type=\"Name\">" + "<sv:value>mix:referenceable</sv:value></sv:property>" + "<sv:property sv:name=\"jcr:uuid\" sv:type=\"String\">" + "<sv:value>" + id + "</sv:value></sv:property>" + "</sv:node>" + "<sv:node sv:name=\"c\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:property sv:name=\"ref\" sv:type=\"Reference\">" + "<sv:value>" + id + "</sv:value></sv:property>" + "</sv:node>" + "</sv:node>"; superuser .getWorkspace() .importXML( root.getPath(), new ByteArrayInputStream(xml.getBytes("UTF-8")), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); Node b = root.getNode("a/b"); Node c = root.getNode("a/c"); assertTrue( "Imported reference points to the correct node", b.isSame(c.getProperty("ref").getNode())); } catch (PathNotFoundException e) { fail("Imported node or property not found"); } catch (RepositoryException e) { fail("Failed to import an XML document with an internal reference"); } }
@Test public void shouldReturnTrueFromIsSameIfTheNodeUuidAndWorkspaceNameAndRepositoryInstanceAreSame() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository); when(workspace2.getName()).thenReturn("workspace1"); WorkspaceLockManager lockManager = new WorkspaceLockManager(context, repoLockManager, "workspace2", null); JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager); when(jcrSession2.lockManager()).thenReturn(jcrLockManager); // Use the same id and location ... javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius")); prius2.addMixin("mix:referenceable"); prius.addMixin("mix:referenceable"); String priusUuid = prius.getIdentifier(); String priusUuid2 = prius2.getIdentifier(); assertThat(priusUuid, is(priusUuid2)); assertThat(prius2.isSame(prius), is(true)); // Check the properties ... javax.jcr.Property model = prius.getProperty("vehix:model"); javax.jcr.Property model2 = prius2.getProperty("vehix:model"); javax.jcr.Property year2 = prius2.getProperty("vehix:year"); assertThat(model.isSame(model2), is(true)); assertThat(model.isSame(year2), is(false)); }
@Test public void shouldReturnFalseFromIsSameIfTheNodeUuidIsDifferent() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); JcrRepository repository2 = mock(JcrRepository.class); RepositoryLockManager repoLockManager2 = mock(RepositoryLockManager.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository2); when(workspace2.getName()).thenReturn("workspace1"); WorkspaceLockManager lockManager = new WorkspaceLockManager(context, repoLockManager2, "workspace2", null); JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager); when(jcrSession2.lockManager()).thenReturn(jcrLockManager); // Use the same id and location; use 'Nissan Altima' // since the UUIDs will be different (cars.xml doesn't define on this node) ... javax.jcr.Node altima2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima")); altima2.addMixin("mix:referenceable"); altima.addMixin("mix:referenceable"); String altimaUuid = altima.getIdentifier(); String altimaUuid2 = altima2.getIdentifier(); assertThat(altimaUuid, is(not(altimaUuid2))); assertThat(altima2.isSame(altima), is(false)); // Check the properties ... javax.jcr.Property model = altima.getProperty("vehix:model"); javax.jcr.Property model2 = altima2.getProperty("vehix:model"); assertThat(model.isSame(model2), is(false)); }