1 package org.exoplatform.services.jcr.api.multiparents; 2 3 4 import javax.jcr.*; 5 import org.exoplatform.services.jcr.BaseTest; 6 import org.exoplatform.services.jcr.impl.core.NodeImpl; 7 import org.exoplatform.services.jcr.impl.util.EntityCollection; 8 9 15 16 public class AddingExistingNodeTest extends BaseTest { 17 18 protected Node root; 19 20 21 public void testAddExistingNode() throws Exception { 22 23 24 Node node = ticket.getRootNode().addNode("testNode", "nt:default"); 25 Node child = ticket.getRootNode().addNode("childNode", "nt:default"); 26 child.addMixin("mix:referenceable"); 27 28 assertEquals("mix:referenceable", child.getProperty("jcr:mixinType").getString()); 29 assertTrue(child.hasProperty("jcr:uuid")); 30 31 ticket.save(); 32 33 assertTrue(ticket.getNodeByAbsPath("/childNode").isNodeType("mix:referenceable")); 34 35 Node child1 = node.addExistingNode("/childNode"); 38 assertNotNull(ticket.getNodeByAbsPath("/testNode/childNode")); 39 assertTrue("Not identical", ticket.getNodeByAbsPath("/childNode").isIdentical(ticket.getNodeByAbsPath("/testNode/childNode"))); 40 ticket.save(); 41 42 43 Ticket ticket1 = ticket.impersonate(ticket.getCredentials()); 45 assertNotNull(ticket1.getNodeByAbsPath("/testNode/childNode")); 46 assertTrue("Not identical", ticket1.getNodeByAbsPath("/childNode").isIdentical(ticket1.getNodeByAbsPath("/testNode/childNode"))); 47 48 assertEquals(ticket1.getNodeByAbsPath("/childNode").getUUID(), 49 ticket1.getNodeByAbsPath("/testNode/childNode").getUUID()); 50 51 assertEquals(2, child.getPaths().getSize()); 52 53 child1.setProperty("testProp", "testVal"); 55 assertNotNull(child.getProperty("testProp")); 56 assertEquals("testVal", child.getProperty("testProp").getString()); 57 assertEquals(2, child.getProperty("testProp").getParents().getSize()); 58 59 child.save(false); 61 Ticket ticket2 = ticket.impersonate(ticket.getCredentials()); 62 assertNotNull(ticket2.getNodeByAbsPath("/testNode/childNode").getProperty("testProp")); 63 64 65 ticket2.getRootNode().remove("/childNode"); 67 ticket2.save(); 68 try { 69 ticket2.getNodeByAbsPath("/testNode/childNode"); 70 fail("exception should have been throwned"); 71 } catch (PathNotFoundException e) { 72 } 73 74 75 76 77 } 78 79 80 } 81 | Popular Tags |