KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > file > TestExists


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestExists.java,v $
3  * Date : $Date: 2005/06/27 23:22:09 $
4  * Version: $Revision: 1.7 $
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.file;
33
34 import org.opencms.security.I_CmsPrincipal;
35 import org.opencms.test.OpenCmsTestCase;
36 import org.opencms.test.OpenCmsTestProperties;
37
38 import junit.extensions.TestSetup;
39 import junit.framework.Test;
40 import junit.framework.TestSuite;
41
42 /**
43  * Unit tests for resource availability operations.<p>
44  *
45  * @author Michael Moossen
46  *
47  * @version $Revision: 1.7 $
48  */

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

56     public TestExists(String JavaDoc arg0) {
57         super(arg0);
58     }
59     
60     /**
61      * Test suite for this test class.<p>
62      *
63      * @return the test suite
64      */

65     public static Test suite() {
66         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
67         
68         TestSuite suite = new TestSuite();
69         suite.setName(TestExists.class.getName());
70                 
71         suite.addTest(new TestExists("testExistsForExistingFile"));
72         suite.addTest(new TestExists("testExistsForUnexistingFile"));
73         suite.addTest(new TestExists("testExistsForUnauthorizedFile"));
74         
75         TestSetup wrapper = new TestSetup(suite) {
76             
77             protected void setUp() {
78                 setupOpenCms("simpletest", "/sites/default/");
79             }
80             
81             protected void tearDown() {
82                 removeOpenCms();
83             }
84         };
85         
86         return wrapper;
87     }
88     
89     /**
90      * Tests the availability of a file that exists and with proper permissions.<p>
91      *
92      * @throws Throwable if something goes wrong
93      */

94     public void testExistsForExistingFile() throws Throwable JavaDoc {
95
96         CmsObject cms = getCmsObject();
97         echo("Testing the availability of a file that exists and with proper permissions");
98         String JavaDoc filename = "index.html";
99         
100         assertEquals(true, cms.existsResource(filename));
101     }
102     
103     /**
104      * Tests the availability of a file that does not exist.<p>
105      *
106      * @throws Throwable if something goes wrong
107      */

108     public void testExistsForUnexistingFile() throws Throwable JavaDoc {
109
110         CmsObject cms = getCmsObject();
111         echo("Testing the availability of a file that does not exist");
112         String JavaDoc filename = "xxx.yyy";
113         
114         assertEquals(false, cms.existsResource(filename));
115     }
116     
117     /**
118      * Tests the availability of a file that exists but with not enough permissions.<p>
119      *
120      * @throws Throwable if something goes wrong
121      */

122     public void testExistsForUnauthorizedFile() throws Throwable JavaDoc {
123
124         CmsObject cms = getCmsObject();
125
126         echo("Testing the availability of a file that exists but with not enough permissions");
127
128         cms.createGroup("Testgroup", "A test group", 0, null);
129         CmsGroup testGroup = cms.readGroup("Testgroup");
130         cms.createUser("testuser", "test", "A test user", null);
131         CmsUser testUser = cms.readUser("testuser");
132
133         String JavaDoc resName = "index.html";
134
135         cms.lockResource(resName);
136         cms.chacc(resName, I_CmsPrincipal.PRINCIPAL_GROUP, testGroup.getName(), "-r-w-v-c-i");
137         cms.chacc(resName, I_CmsPrincipal.PRINCIPAL_USER, testUser.getName(), "-r-w-v-c-i");
138         cms.unlockResource(resName);
139         cms.publishProject();
140         
141         cms.loginUser("testuser", "test");
142         assertEquals(false, cms.existsResource(resName));
143     }
144     
145 }
146
Popular Tags