KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestChtype.java,v $
3  * Date : $Date: 2005/06/27 23:22:09 $
4  * Version: $Revision: 1.9 $
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.file.types.CmsResourceTypeBinary;
35 import org.opencms.file.types.CmsResourceTypePlain;
36 import org.opencms.test.OpenCmsTestCase;
37 import org.opencms.test.OpenCmsTestProperties;
38 import org.opencms.test.OpenCmsTestResourceFilter;
39
40 import junit.extensions.TestSetup;
41 import junit.framework.Test;
42 import junit.framework.TestSuite;
43
44 /**
45  * Unit test for the "chtype" method of the CmsObject.<p>
46  *
47  * @author Michael Emmerich
48  * @version $Revision: 1.9 $
49  */

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

57     public TestChtype(String JavaDoc arg0) {
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         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
68         
69         TestSuite suite = new TestSuite();
70         suite.setName(TestChtype.class.getName());
71                 
72         suite.addTest(new TestChtype("testChtypNewFile"));
73                
74         TestSetup wrapper = new TestSetup(suite) {
75             
76             protected void setUp() {
77                 setupOpenCms("simpletest", "/sites/default/");
78             }
79             
80             protected void tearDown() {
81                 removeOpenCms();
82             }
83         };
84         
85         return wrapper;
86     }
87     
88     /**
89      * Test the chtype method on a new file.<p>
90      *
91      * @param tc the OpenCmsTestCase
92      * @param cms the CmsObject
93      * @param resource1 the resource to change permissions
94      * @param originalResType the original resource type
95      * @param newResType the new resource tpye
96      * @throws Throwable if something goes wrong
97      */

98     public static void chtypNewFile(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, int originalResType, int newResType) throws Throwable JavaDoc {
99       
100         // create a new resource
101
cms.createResource(resource1, originalResType);
102         tc.storeResources(cms, resource1);
103         
104         long timestamp = System.currentTimeMillis();
105         
106         cms.chtype(resource1, newResType);
107         
108         // now evaluate the result
109
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_CHTYPE);
110         // date lastmodified must be new
111
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
112         // the type must be the new type
113
}
114     
115
116     /**
117      * Test the chtype method on a new file.<p>
118      *
119      * @throws Throwable if something goes wrong
120      */

121     public void testChtypNewFile() throws Throwable JavaDoc {
122         CmsObject cms = getCmsObject();
123         echo("Testing chtype on a new file");
124         chtypNewFile(this, cms, "/chtype.txt", CmsResourceTypePlain.getStaticTypeId(), CmsResourceTypeBinary.getStaticTypeId());
125     }
126     
127 }
Popular Tags