KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > removing > RemoveTest


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.removing;
7
8
9 import javax.jcr.RepositoryException;
10 import javax.jcr.Node;
11 import javax.jcr.StringValue;
12 import javax.jcr.PathNotFoundException;
13 import org.exoplatform.services.jcr.BaseTest;
14
15 /**
16  * Created y the eXo platform team
17  * User: Benjamin Mestrallet
18  * Date: 2 ao�t 2004
19  */

20 public class RemoveTest extends BaseTest{
21
22   public void initRepository() throws RepositoryException {
23     Node root = ticket.getRootNode();
24     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
25     Node contentNode = file.getNode("jcr:content");
26     contentNode.setProperty("exo:content", new StringValue("this is the content"));
27     ticket.save();
28   }
29
30   public void tearDown() throws RepositoryException {
31     Node root = ticket.getRootNode();
32     root.remove("childNode");
33     ticket.save();
34   }
35
36   public void testRemove() throws RepositoryException {
37     Node root = ticket.getRootNode();
38     root.remove("childNode/childNode2");
39     ticket.save();
40
41     ticket = repository.login(credentials, WORKSPACE);
42     root = ticket.getRootNode();
43     try {
44       root.getNode("childNode/childNode2");
45       fail("exception should have been thrown");
46     } catch (PathNotFoundException e) {
47     }
48   }
49
50   public void testRecursiveRemove() throws RepositoryException {
51     Node root = ticket.getRootNode();
52     root.remove("childNode");
53     ticket.save();
54
55     ticket = repository.login(credentials, WORKSPACE);
56     root = ticket.getRootNode();
57     try {
58       root.getNode("childNode/childNode2");
59       fail("exception should have been thrown");
60     } catch (PathNotFoundException e) {
61     }
62   }
63
64   public void testRemoveProperty() throws RepositoryException {
65     Node root = ticket.getRootNode();
66     root.remove("childNode/childNode2/jcr:content/exo:content");
67     ticket.save();
68
69     ticket = repository.login(credentials, WORKSPACE);
70     root = ticket.getRootNode();
71     try {
72       root.getProperty("childNode/childNode2/jcr:content/exo:content");
73       fail("exception should have been thrown");
74     } catch (PathNotFoundException e) {
75     }
76
77   }
78
79 }
80
Popular Tags