KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > moving > fs > TestCopyNode


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.fs;
7
8
9 import javax.jcr.ItemExistsException;
10 import javax.jcr.Node;
11 import javax.jcr.Repository;
12 import javax.jcr.RepositoryException;
13 import javax.jcr.StringValue;
14
15 import org.exoplatform.services.jcr.api.moving.CopyNodeTest;
16
17 /**
18  * Created y the eXo platform team
19  * User: Benjamin Mestrallet
20  * Date: 8 aout 2004
21  */

22 public class TestCopyNode extends CopyNodeTest{
23
24   public void setUp() throws Exception JavaDoc {
25     super.setUp();
26     repository = (Repository) repositoryService.getRepository("fs1");
27     ticket = repository.login(credentials, "ws");
28     workspace = ticket.getWorkspace();
29   }
30
31   public void testCopy() throws RepositoryException {
32     try {
33       workspace.copy("/dummyNode", "/test", false);
34       fail("exception should have been thrown");
35     } catch (RepositoryException e) {
36     }
37
38     Node root = ticket.getRootNode();
39     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
40     Node contentNode = file.getNode("jcr:content");
41     contentNode.setProperty("exo:content", new StringValue("this is the content"));
42     root.addNode("existNode", "nt:folder");
43     ticket.save();
44
45     try {
46       workspace.copy("/childNode", "/existNode", false);
47       fail("exception should have been throwned");
48     } catch (ItemExistsException e) {
49     }
50
51     workspace.copy("/childNode", "/test", false);
52     ticket = repository.login(credentials, WORKSPACE);
53     assertNotNull(ticket.getNodeByAbsPath("/test"));
54     assertNotNull(ticket.getNodeByAbsPath("/childNode"));
55     assertNotNull(ticket.getNodeByAbsPath("/test/childNode2"));
56     assertNotNull(ticket.getNodeByAbsPath("/test/childNode2").getNode("jcr:content").
57         getProperty("exo:content"));
58
59     workspace.copy("/childNode", "/test2", true);
60     ticket = repository.login(credentials, WORKSPACE);
61     assertNotNull(ticket.getNodeByAbsPath("/test2"));
62     assertNotNull(ticket.getNodeByAbsPath("/childNode"));
63     try {
64       ticket.getNodeByAbsPath("/test2/childNode2");
65       fail("exception should have been thrown");
66     } catch (RepositoryException e) {
67     }
68 /*
69     ticket.getRootNode().addNode("toCorrupt", "nt:childNodeDef");
70     ticket.save();
71     try {
72       workspace.copy("/toCorrupt", "/childNode/corrupted", false);
73       fail("exception should have been thrown");
74     } catch (ConstraintViolationException e) {
75     }
76 */

77   }
78
79   public void testClone() {
80
81   }
82
83   public void testMove() throws RepositoryException {
84     Node root;
85     try {
86       workspace.move("/dummyNode", "/test");
87       fail("exception should have been thrown");
88     } catch (RepositoryException e) {
89     }
90
91     root = ticket.getRootNode();
92     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
93     Node contentNode = file.getNode("jcr:content");
94     contentNode.setProperty("exo:content", new StringValue("this is the content"));
95     root.addNode("existNode", "nt:folder");
96     ticket.save();
97
98     try {
99       workspace.move("/childNode", "/existNode");
100       fail("exception should have been thrown");
101     } catch (ItemExistsException e) {
102     }
103     assertNotNull(ticket.getNodeByAbsPath("/childNode/childNode2").getNode("jcr:content").getProperty("exo:content"));
104     workspace.move("/childNode", "/test");
105     ticket = repository.login(credentials, WORKSPACE);
106     assertNotNull(ticket.getNodeByAbsPath("/test"));
107     assertNotNull(ticket.getNodeByAbsPath("/test/childNode2").getNode("jcr:content").getProperty("exo:content"));
108
109     try {
110       ticket.getNodeByAbsPath("/childNode");
111       fail("exception should have been thrown");
112     } catch (RepositoryException e) {
113     }
114 /*
115     ticket.getRootNode().addNode("toCorrupt", "nt:childNodeDef");
116     ticket.save();
117
118     try {
119       workspace.move("/toCorrupt", "/childNode/corrupted");
120       fail("exception should have been thrown");
121     } catch (PathNotFoundException e) {
122     }
123
124     try {
125       workspace.move("/toCorrupt", "/test/corrupted");
126       fail("exception should have been thrown");
127     } catch (ConstraintViolationException e) {
128     }
129 */

130
131   }
132
133
134 }
135
Popular Tags