KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > notification > TestResponsibles


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/notification/TestResponsibles.java,v $
3  * Date : $Date: 2006/03/27 14:52:58 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31  
32 package org.opencms.notification;
33
34 import org.opencms.file.CmsGroup;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsUser;
37 import org.opencms.security.CmsAccessControlEntry;
38 import org.opencms.security.CmsPermissionSet;
39 import org.opencms.security.I_CmsPrincipal;
40 import org.opencms.test.OpenCmsTestCase;
41 import org.opencms.test.OpenCmsTestProperties;
42
43 import java.util.HashSet JavaDoc;
44 import java.util.Set JavaDoc;
45
46 import junit.extensions.TestSetup;
47 import junit.framework.Test;
48 import junit.framework.TestSuite;
49
50 /**
51  * Unit test for the "readResponsibleUsers" method of the CmsObject.<p>
52  *
53  * @author Jan Baudisch
54  * @version $Revision: 1.2 $
55  */

56 public class TestResponsibles extends OpenCmsTestCase {
57   
58     /**
59      * Default JUnit constructor.<p>
60      *
61      * @param arg0 JUnit parameters
62      */

63     public TestResponsibles(String JavaDoc arg0) {
64         super(arg0);
65     }
66     
67     /**
68      * Test suite for this test class.<p>
69      *
70      * @return the test suite
71      */

72     public static Test suite() {
73         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
74         
75         TestSuite suite = new TestSuite();
76         suite.setName(TestResponsibles.class.getName());
77                 
78         suite.addTest(new TestResponsibles("testResponsibles"));
79                
80         TestSetup wrapper = new TestSetup(suite) {
81             
82             protected void setUp() {
83                 setupOpenCms("simpletest", "/sites/default/");
84             }
85             
86             protected void tearDown() {
87                 removeOpenCms();
88             }
89         };
90         
91         return wrapper;
92     }
93     
94     
95     /**
96      * Sets responsibles to a file and then tests the readResponsibleUsers method of CmsObject .<p>
97      *
98      * @throws Throwable if something goes wrong
99      */

100     public void testResponsibles() throws Throwable JavaDoc {
101         
102         echo("Testing responsibles of resources");
103         
104         // create three users, two of them belonging to a group
105
CmsObject cms = getCmsObject();
106         CmsGroup tastycrats = cms.createGroup("tastycrats", "A test group", 0, null);
107         CmsUser fry = cms.createUser("fry", "password", "First test user", null);
108         CmsUser bender = cms.createUser("bender", "password", "Second test user, belonging to the tastycrats group.", null);
109         CmsUser leela = cms.createUser("leela", "password", "Third test user, belonging to the tastycrats group.", null);
110         CmsUser farnsworth = cms.createUser("farnsworth", "password", "Another test user, which is not responsible.", null);
111         cms.addUserToGroup("bender", "tastycrats");
112         cms.addUserToGroup("leela", "tastycrats");
113          
114         // make group and user responsible for the group
115
String JavaDoc resource1 = "/folder1/index.html";
116         CmsPermissionSet permissions = new CmsPermissionSet(CmsPermissionSet.PERMISSION_WRITE, CmsPermissionSet.PERMISSION_READ);
117         cms.lockResource(resource1);
118         cms.chacc(resource1, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), permissions.getAllowedPermissions(), permissions.getDeniedPermissions(), CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE);
119         cms.chacc(resource1, I_CmsPrincipal.PRINCIPAL_GROUP, tastycrats.getName(), permissions.getAllowedPermissions(), permissions.getDeniedPermissions(), CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE);
120         cms.chacc(resource1, I_CmsPrincipal.PRINCIPAL_USER, farnsworth.getName(), permissions.getAllowedPermissions(), permissions.getDeniedPermissions(), 0);
121         cms.unlockResource(resource1);
122         
123         // check, if the three users are indeed responsible for the resource.
124
Set responsibles = cms.readResponsibleUsers(cms.readResource(resource1));
125         Set expectedResponsibles = new HashSet JavaDoc();
126         expectedResponsibles.add(fry);
127         expectedResponsibles.add(leela);
128         expectedResponsibles.add(bender);
129         assertEquals(responsibles, expectedResponsibles);
130     }
131 }
Popular Tags