KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestReleaseExpire.java,v $
3  * Date : $Date: 2006/03/27 14:52:46 $
4  * Version: $Revision: 1.3 $
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.CmsException;
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 test for the "setDateExpired" and "setDateReleased" method of the CmsObject.<p>
44  *
45  * @author Jan Baudisch
46  * @version $Revision: 1.3 $
47  */

48 public class TestReleaseExpire extends OpenCmsTestCase {
49
50     private int m_msecPerDay = 1000 * 60 * 60 * 12;
51
52     private String JavaDoc m_resourceName = "/index.html";
53
54     /**
55      * Default JUnit constructor.<p>
56      *
57      * @param arg0 JUnit parameters
58      */

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

69     public static Test suite() {
70
71         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
72
73         TestSuite suite = new TestSuite();
74         suite.setName(TestReleaseExpire.class.getName());
75
76         suite.addTest(new TestReleaseExpire("testSetDateReleased"));
77         suite.addTest(new TestReleaseExpire("testSetDateExpired"));
78
79         TestSetup wrapper = new TestSetup(suite) {
80
81             protected void setUp() {
82
83                 setupOpenCms("simpletest", "/sites/default/");
84             }
85
86             protected void tearDown() {
87
88                 removeOpenCms();
89             }
90         };
91
92         return wrapper;
93     }
94
95     /**
96      * Test to set relase date on a resource.<p>
97      *
98      * The method reads the file, and tests if the file cannot be read with the CmsResourceFilter.DEFAULT
99      * @throws Throwable if something goes wrong
100      */

101     public void testSetDateExpired() throws Throwable JavaDoc {
102
103         CmsObject cms = getCmsObject();
104         echo("Testing to set expire date");
105
106         long yesterday = System.currentTimeMillis() - m_msecPerDay;
107         cms.lockResource(m_resourceName);
108         cms.setDateExpired(m_resourceName, yesterday, false);
109         cms.unlockResource(m_resourceName);
110
111         CmsResource resource = testOutsideTimeRange(cms);
112         assertEquals(resource.getDateExpired(), yesterday);
113     }
114
115     /**
116      * Test to set relase date on a resource.<p>
117      *
118      * @throws Throwable if something goes wrong
119      */

120     public void testSetDateReleased() throws Throwable JavaDoc {
121
122         CmsObject cms = getCmsObject();
123         echo("Testing to set relase date");
124
125         long tomorrow = System.currentTimeMillis() + m_msecPerDay;
126         cms.lockResource(m_resourceName);
127         cms.setDateReleased(m_resourceName, tomorrow, false);
128         cms.unlockResource(m_resourceName);
129
130         CmsResource resource = testOutsideTimeRange(cms);
131         assertEquals(resource.getDateReleased(), tomorrow);
132     }
133
134     private CmsResource testOutsideTimeRange(CmsObject cms) throws CmsException {
135
136         boolean coughtException = false;
137         // should throw exception
138
try {
139             cms.readResource(m_resourceName, CmsResourceFilter.DEFAULT);
140         } catch (CmsVfsResourceNotFoundException e) {
141             coughtException = true;
142         }
143         if (!coughtException) {
144             fail("Read invisible resource with filter CmsResourceFilter.ONLY_VISIBLE");
145         }
146
147         try {
148             return cms.readResource(m_resourceName, CmsResourceFilter.ALL);
149         } catch (CmsException e) {
150             fail("Unable to read invisible resource with filter CmsResourceFilter.ALL");
151         }
152         return null;
153     }
154 }
155
Popular Tags