KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > moving > CopyNodeTest


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5
6 package org.exoplatform.services.jcr.api.moving;
7
8
9 import javax.jcr.*;
10 import javax.jcr.nodetype.ConstraintViolationException;
11 import org.exoplatform.services.jcr.BaseTest;
12
13 /**
14  * Created y the eXo platform team
15  * User: Benjamin Mestrallet
16  * Date: 8 ao�t 2004
17  */

18 public class CopyNodeTest extends BaseTest {
19
20   public void tearDown() throws RepositoryException {
21     Node root = ticket.getRootNode();
22     root.remove("childNode");
23     root.remove("existNode");
24     root.remove("test");
25     root.remove("test2");
26     root.remove("toCorrupt");
27     ticket.save();
28   }
29
30   public void testCopy() throws RepositoryException {
31     try {
32       workspace.copy("/dummyNode", "/test", false);
33       fail("exception should have been thrown");
34     } catch (RepositoryException e) {
35     }
36
37     Node root = ticket.getRootNode();
38     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
39     Node contentNode = file.getNode("jcr:content");
40     contentNode.setProperty("exo:content", new StringValue("this is the content"));
41     root.addNode("existNode", "nt:folder");
42     ticket.save();
43
44     try {
45       workspace.copy("/childNode", "/existNode", false);
46       fail("exception should have been throwned");
47     } catch (ItemExistsException e) {
48     }
49
50     workspace.copy("/childNode", "/test", false);
51     ticket = repository.login(credentials, WORKSPACE);
52     assertNotNull(ticket.getNodeByAbsPath("/test"));
53     assertNotNull(ticket.getNodeByAbsPath("/childNode"));
54     assertNotNull(ticket.getNodeByAbsPath("/test/childNode2"));
55     assertNotNull(ticket.getNodeByAbsPath("/test/childNode2").getNode("jcr:content").
56         getProperty("exo:content"));
57
58     workspace.copy("/childNode", "/test2", true);
59     ticket = repository.login(credentials, WORKSPACE);
60     assertNotNull(ticket.getNodeByAbsPath("/test2"));
61     assertNotNull(ticket.getNodeByAbsPath("/childNode"));
62     try {
63       ticket.getNodeByAbsPath("/test2/childNode2");
64       fail("exception should have been thrown");
65     } catch (RepositoryException e) {
66     }
67
68     ticket.getRootNode().addNode("toCorrupt", "nt:childNodeDef");
69     ticket.save();
70     try {
71       workspace.copy("/toCorrupt", "/childNode/corrupted", false);
72       fail("exception should have been thrown");
73     } catch (ConstraintViolationException e) {
74     }
75   }
76
77   public void testMove() throws RepositoryException {
78     Node root;
79     try {
80       workspace.move("/dummyNode", "/test");
81       fail("exception should have been thrown");
82     } catch (RepositoryException e) {
83     }
84
85     root = ticket.getRootNode();
86     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
87     Node contentNode = file.getNode("jcr:content");
88     contentNode.setProperty("exo:content", new StringValue("this is the content"));
89     root.addNode("existNode", "nt:folder");
90     ticket.save();
91
92     try {
93       workspace.move("/childNode", "/existNode");
94       fail("exception should have been thrown");
95     } catch (ItemExistsException e) {
96     }
97     assertNotNull(ticket.getNodeByAbsPath("/childNode/childNode2").getNode("jcr:content").getProperty("exo:content"));
98     workspace.move("/childNode", "/test");
99     ticket = repository.login(credentials, WORKSPACE);
100     assertNotNull(ticket.getNodeByAbsPath("/test"));
101     assertNotNull(ticket.getNodeByAbsPath("/test/childNode2").getNode("jcr:content").getProperty("exo:content"));
102
103     try {
104       ticket.getNodeByAbsPath("/childNode");
105       fail("exception should have been thrown");
106     } catch (RepositoryException e) {
107     }
108
109     ticket.getRootNode().addNode("toCorrupt", "nt:childNodeDef");
110     ticket.save();
111
112     try {
113       workspace.move("/toCorrupt", "/childNode/corrupted");
114       fail("exception should have been thrown");
115     } catch (PathNotFoundException e) {
116     }
117
118     try {
119       workspace.move("/toCorrupt", "/test/corrupted");
120       fail("exception should have been thrown");
121     } catch (ConstraintViolationException e) {
122     }
123
124
125   }
126
127
128   public void testClone() throws RepositoryException {
129
130
131     Node root;
132     String JavaDoc uuid = null;
133
134     try {
135       workspace.clone("/dummyNode", "/test", "ws2", false);
136       fail("exception should have been thrown");
137     } catch (RepositoryException e) {
138     }
139
140     root = ticket.getRootNode();
141     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
142
143     Node contentNode = file.getNode("jcr:content");
144     contentNode.setProperty("exo:content", new StringValue("this is the content"));
145     ticket.save();
146     uuid = contentNode.getUUID();
147
148
149     Ticket ticket2 = repository.login(null, "ws2");
150     root = ticket2.getRootNode();
151     root.addNode("existNode", "nt:folder").addNode("childNode", "nt:file");
152     root.addNode("test", "nt:folder");
153     ticket2.save();
154
155     try {
156       workspace.clone("/childNode", "/existNode", "ws2", false);
157       fail("exception should have been throwned");
158     } catch (ItemExistsException e) {
159     }
160
161     assertNotNull(ticket.getNodeByAbsPath("/childNode"));
162
163     try {
164       workspace.clone("/childNode", "/test1", "ws2", false);
165
166       fail("exception should have been throwned");
167     } catch (PathNotFoundException e) {
168     }
169
170     workspace.clone("/childNode", "/test", "ws2", false);
171
172     ticket2 = repository.login(null, "ws2");
173     assertNotNull(ticket2.getNodeByAbsPath("/test"));
174     assertNotNull(ticket.getNodeByAbsPath("/childNode"));
175
176     assertNotNull(ticket2.getNodeByAbsPath("/test/childNode/childNode2"));
177     assertNotNull(ticket2.getNodeByAbsPath("/test/childNode/childNode2").getNode("jcr:content").
178         getProperty("exo:content"));
179     assertEquals(uuid, ticket2.getNodeByAbsPath("/test/childNode/childNode2").getNode("jcr:content").getUUID());
180
181     assertNotNull(ticket.getNodeByUUID(uuid));
182     assertNotNull(ticket2.getNodeByUUID(uuid));
183     assertTrue(ticket.getNodeByUUID(uuid).isIdentical(ticket2.getNodeByUUID(uuid)));
184
185     ticket2 = repository.login(null, "ws2");
186     try {
187       ticket2.getNodeByAbsPath("/test/childNode2");
188       fail("exception should have been thrown");
189     } catch (RepositoryException e) {
190     }
191
192     ticket.getRootNode().addNode("toCorrupt", "nt:childNodeDef");
193     ticket.save();
194     try {
195       workspace.clone("/toCorrupt", "/test", "ws2", false);
196       fail("exception should have been thrown");
197     } catch (ConstraintViolationException e) {
198     }
199
200     ticket2 = repository.login(null, "ws2");
201     root = ticket2.getRootNode();
202     root.remove("existNode");
203     root.remove("test");
204 // root.remove("test2");
205
ticket2.save();
206
207
208   }
209 }
210
Popular Tags