KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > accessing > WorkspaceTest


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.accessing;
7
8
9 import javax.jcr.*;
10 import javax.jcr.nodetype.ConstraintViolationException;
11 import javax.jcr.nodetype.NoSuchNodeTypeException;
12 import org.exoplatform.services.jcr.BaseTest;
13
14 /**
15  * Created y the eXo platform team
16  * User: Benjamin Mestrallet
17  * Date: 16 juil. 2004
18  */

19 public class WorkspaceTest extends BaseTest {
20
21   public void testGetTicket() {
22     assertEquals(workspace.getTicket(), ticket);
23   }
24
25   public void testMove() throws RepositoryException, ConstraintViolationException,
26       NoSuchNodeTypeException, ItemExistsException {
27     Node root;
28     try {
29       try {
30         workspace.move("/dummyNode", "/test");
31         fail("exception should have been thrown");
32       } catch (RepositoryException e) {
33       }
34
35       root = ticket.getRootNode();
36       Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
37       Node contentNode = file.getNode("jcr:content");
38       contentNode.setProperty("exo:content", new StringValue("this is the content"));
39       root.addNode("existNode", "nt:folder");
40       ticket.save();
41
42       try {
43         workspace.move("/childNode", "/existNode");
44         fail("exception should have been throwned");
45       } catch (RepositoryException e) {
46       }
47       assertNotNull(ticket.getNodeByAbsPath("/childNode/childNode2").getNode("jcr:content").getProperty("exo:content"));
48       workspace.move("/childNode", "/test");
49       ticket = repository.login(credentials, WORKSPACE);
50       assertNotNull(ticket.getNodeByAbsPath("/test"));
51       assertNotNull(ticket.getNodeByAbsPath("/test/childNode2").getNode("jcr:content").getProperty("exo:content"));
52
53       try {
54         ticket.getNodeByAbsPath("/childNode");
55         fail("exception should have been throwned");
56       } catch (RepositoryException e) {
57       }
58     } finally {
59       root = ticket.getRootNode();
60       root.remove("test");
61       root.remove("childNode");
62       root.remove("existNode");
63       ticket.save();
64     }
65   }
66 }
67
Popular Tags