KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestVersioning.java,v $
3  * Date : $Date: 2006/03/27 14:52:46 $
4  * Version: $Revision: 1.6 $
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.main.OpenCms;
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 OpenCms versioning.<p>
44  *
45  * @author Michael Moossen
46  *
47  * @version $Revision: 1.6 $
48  */

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

56     public TestVersioning(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(TestVersioning.class.getName());
70         
71         suite.addTest(new TestVersioning("testVersioningLimit"));
72         
73         TestSetup wrapper = new TestSetup(suite) {
74             
75             protected void setUp() {
76                 setupOpenCms("simpletest", "/sites/default/");
77             }
78             
79             protected void tearDown() {
80                 removeOpenCms();
81             }
82         };
83         
84         return wrapper;
85     }
86      
87     /**
88      * Test that the versions are properly updated
89      * after reaching the limit of stored versions.<p>
90      *
91      * @throws Throwable if something goes wrong
92      */

93     public void testVersioningLimit() throws Throwable JavaDoc {
94         
95         CmsObject cms = getCmsObject();
96         echo("Testing versioning limit");
97         
98         String JavaDoc source = "/index.html";
99         cms.getRequestContext().setCurrentProject(cms.readProject("Offline"));
100
101         // set the versioning settings
102
OpenCms.getSystemInfo().setVersionHistorySettings(true, 3);
103         
104         // make 5 versions
105
for (int i = 0; i < 5; i++) {
106             if (i<3) {
107                 assertEquals(i+1, cms.readAllBackupFileHeaders(source).size());
108             } else {
109                 assertEquals(3, cms.readAllBackupFileHeaders(source).size());
110             }
111             cms.lockResource(source);
112             cms.setDateLastModified(source, System.currentTimeMillis(), false);
113             cms.setDateExpired(source, System.currentTimeMillis(), false);
114             cms.setDateReleased(source, System.currentTimeMillis(), false);
115             cms.unlockResource(source);
116             cms.publishResource(source);
117         }
118     }
119 }
120
Popular Tags