KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.exoplatform.services.jcr.BaseTest;
11
12 /**
13  * Created y the eXo platform team
14  * User: Benjamin Mestrallet
15  * Date: 15 juil. 2004
16  */

17 public class AccessRepositoryTest extends BaseTest{
18
19   public void testLogin() throws NoSuchWorkspaceException, LoginException {
20     Credentials cred = new SimpleCredentials("exo", "exo".toCharArray());
21     repository.login(cred, WORKSPACE);
22   }
23
24   public void testGetAnonymousTicket() throws NoSuchWorkspaceException, LoginException {
25     Ticket ticket = repository.login(null, WORKSPACE) ;
26     assertNotNull(ticket);
27     assertEquals("anonymous", ticket.getCredentials().getUserId());
28   }
29
30   public void testGetDefaultWorkspace() throws NoSuchWorkspaceException, LoginException {
31     Credentials cred = new SimpleCredentials("exo", "exo".toCharArray());
32     Ticket ticket = repository.login(cred, null);
33     assertNotNull(ticket);
34   }
35
36   public void testWrongLogin() throws NoSuchWorkspaceException {
37     Credentials cred = new SimpleCredentials("benj", "psw".toCharArray());
38     try {
39       repository.login(cred, WORKSPACE);
40       fail("Exception should have been thrown");
41     } catch (LoginException e) {
42     }
43   }
44
45   public void testWrongWorkspace() throws LoginException {
46     Credentials cred = new SimpleCredentials("exo", "exo".toCharArray());
47     try {
48       repository.login(cred, "wrong_workspace");
49       fail("Exception should have been thrown");
50     } catch (NoSuchWorkspaceException e) {
51     }
52   }
53
54   public void testWorkspaceSplit() throws RepositoryException{
55     Ticket ticket1 = repository.login(null, WORKSPACE) ;
56     Node root = ticket1.getRootNode();
57 System.out.println("WS ------------------- "+root);
58
59     Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file");
60     Node contentNode = file.getNode("jcr:content");
61     root.getNode("childNode");
62     contentNode.setProperty("exo:content", new StringValue("this is the content"));
63     ticket1.save();
64
65     Ticket ticket2 = repository.login(null, "ws2");
66     root = ticket2.getRootNode();
67 System.out.println("WS2 ------------------- "+root);
68
69     root.addNode("child1");
70     try {
71       root.getNode("childNode");
72       fail("exception should have been thrown");
73     } catch (RepositoryException e) {
74     }
75     root.addNode("childNodeinWS2", "nt:folder");
76     ticket2.save();
77
78     root = ticket1.getRootNode();
79     try {
80       root.getNode("childNodeinWS2");
81       fail("exception should have been thrown");
82     } catch (RepositoryException e) {
83     }
84
85     root = ticket1.getRootNode();
86     root.remove("childNode");
87     ticket1.save();
88
89     root = ticket2.getRootNode();
90     root.remove("childNodeinWS2");
91     ticket2.save();
92   }
93
94 }
95
Popular Tags