KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestChflags.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.test.OpenCmsTestCase;
35 import org.opencms.test.OpenCmsTestProperties;
36 import org.opencms.test.OpenCmsTestResourceFilter;
37
38 import junit.extensions.TestSetup;
39 import junit.framework.Test;
40 import junit.framework.TestSuite;
41
42 /**
43  * Unit test for the "chflags" method of the CmsObject.<p>
44  *
45  * @author Thomas Weckert
46  * @version $Revision: 1.7 $
47  * @since 6.0 alpha 2
48  */

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

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

66     public static Test suite() {
67
68         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
69
70         TestSuite suite = new TestSuite();
71         suite.setName(TestChflags.class.getName());
72
73         suite.addTest(new TestChflags("testAddFlagInternal"));
74
75         TestSetup wrapper = new TestSetup(suite) {
76
77             protected void setUp() {
78
79                 setupOpenCms("simpletest", "/sites/default/");
80             }
81
82             protected void tearDown() {
83
84                 removeOpenCms();
85             }
86         };
87
88         return wrapper;
89     }
90
91     /**
92      * Tests setting the "internal" flag on a resource.<p>
93      *
94      * @throws Throwable if something goes wrong
95      */

96     public void testAddFlagInternal() throws Throwable JavaDoc {
97
98         CmsObject cms = getCmsObject();
99
100         echo("Tests setting the \"internal\" flag on a resource");
101         addFlagInternal(this, cms);
102     }
103
104     /**
105      * Tests setting the "internal" flag on a resource.<p>
106      *
107      * @param tc the OpenCmsTestCase
108      * @param cms the CmsObject
109      * @throws Throwable if something goes wrong
110      */

111     public static void addFlagInternal(OpenCmsTestCase tc, CmsObject cms) throws Throwable JavaDoc {
112
113         String JavaDoc resource1 = "/index.html";
114
115         CmsResource resource = cms.readResource(resource1, CmsResourceFilter.ALL);
116         tc.storeResources(cms, resource1);
117         
118         int existingFlags = resource.getFlags();
119         int flags = existingFlags;
120         long timestamp = System.currentTimeMillis();
121
122         // the "internal" flag is not set
123
assertEquals((existingFlags & CmsResource.FLAG_INTERNAL), 0);
124
125         // add the "internal" flag
126
if ((flags & CmsResource.FLAG_INTERNAL) == 0) {
127             flags += CmsResource.FLAG_INTERNAL;
128         } else {
129             fail("Resource " + resource1 + " has the \"internal\" flag already set!");
130         }
131
132         // change the flag
133
cms.lockResource(resource1);
134         cms.chflags(resource1, flags);
135         cms.unlockResource(resource1);
136
137         // check the status of the changed file
138
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_CHFLAGS);
139         tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
140         tc.assertState(cms, resource1, CmsResource.STATE_CHANGED);
141         tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
142         tc.assertFlags(cms, resource1, CmsResource.FLAG_INTERNAL);
143         tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
144     }
145
146 }
Popular Tags