KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > security > TestRoles


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/security/TestRoles.java,v $
3  * Date : $Date: 2005/06/27 23:22:25 $
4  * Version: $Revision: 1.4 $
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.security;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.i18n.CmsMessages;
36 import org.opencms.main.OpenCms;
37 import org.opencms.test.OpenCmsTestCase;
38 import org.opencms.test.OpenCmsTestProperties;
39
40 import java.util.Iterator JavaDoc;
41
42 import junit.extensions.TestSetup;
43 import junit.framework.Test;
44 import junit.framework.TestSuite;
45
46 /**
47  * Tests the OpenCms system roles.<p>
48  */

49 public class TestRoles extends OpenCmsTestCase {
50
51     /**
52      * Default JUnit constructor.<p>
53      *
54      * @param arg0 JUnit parameters
55      */

56     public TestRoles(String JavaDoc arg0) {
57         super(arg0);
58     }
59     
60     /**
61      * Test suite for this test class.<p>
62      * Setup is done without importing vfs data.
63      *
64      * @return the test suite
65      */

66     public static Test suite() {
67         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
68         
69         TestSuite suite = new TestSuite();
70         suite.setName(TestRoles.class.getName());
71
72         suite.addTest(new TestRoles("testRoleExceptionMessages"));
73         
74         TestSetup wrapper = new TestSetup(suite) {
75             
76             protected void setUp() {
77                 setupOpenCms(null, null, false);
78             }
79             
80             protected void tearDown() {
81                 removeOpenCms();
82             }
83         };
84         
85         return wrapper;
86     }
87     
88     /**
89      * Tests if all keys in the system roles exception messages can be resolved.<p>
90      *
91      * @throws Exception if the test fails
92      */

93     public void testRoleExceptionMessages() throws Exception JavaDoc {
94         
95         echo("Testing role exception messages");
96         CmsObject cms = getCmsObject();
97         
98         String JavaDoc message;
99         
100         // check the system roles
101
Iterator JavaDoc i = CmsRole.getSystemRoles().iterator();
102         while (i.hasNext()) {
103             CmsRole role = (CmsRole)i.next();
104             CmsRoleViolationException ex = role.createRoleViolationException(cms.getRequestContext());
105             message = ex.getMessage();
106             System.out.println(message);
107             // check if a key could not be resolved
108
assertFalse(message.indexOf(CmsMessages.UNKNOWN_KEY_EXTENSION) >= 0);
109             // very simple check if message still containes unresolved '{n}'
110
assertFalse(message.indexOf('{') >= 0);
111         }
112         
113         // check a user defined role
114
String JavaDoc roleName = "MY_VERY_SPECIAL_ROLE";
115         CmsRole myRole = new CmsRole(roleName, OpenCms.getDefaultUsers().getGroupAdministrators(), new CmsRole[0]);
116         message = myRole.createRoleViolationException(cms.getRequestContext()).getMessage();
117         
118         System.out.println(message);
119         // check if a key could not be resolved
120
assertFalse(message.indexOf(CmsMessages.UNKNOWN_KEY_EXTENSION) >= 0);
121         // very simple check if message still containes unresolved '{n}'
122
assertFalse(message.indexOf('{') >= 0);
123     }
124 }
125
Popular Tags