KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > multiparents > AddingExistingNodeTest


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 /**
10  * Created by The eXo Platform SARL .
11  *
12  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
13  * @version $Id: AddingExistingNodeTest.java,v 1.3 2004/09/16 15:26:54 geaz Exp $
14  */

15
16 public class AddingExistingNodeTest extends BaseTest {
17
18   protected Node root;
19
20
21   public void testAddExistingNode() throws Exception JavaDoc {
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     // /test/childNode if reference to /childNode
36
// Test if the nodes are identical
37
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     // Test if the nodes are identical after save
44
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     // Test if property will be assigned to the linked node as well
54
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     // Test if linked node will be saved as well
60
child.save(false);
61     Ticket ticket2 = ticket.impersonate(ticket.getCredentials());
62     assertNotNull(ticket2.getNodeByAbsPath("/testNode/childNode").getProperty("testProp"));
63
64
65     // Test if linked node will be removed as well
66
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