KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > cache > TestCache


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/cache/TestCache.java,v $
3  * Date : $Date: 2006/03/27 14:52:59 $
4  * Version: $Revision: 1.2 $
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.cache;
33
34 import org.opencms.file.CmsResource;
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  * Tests for the decoration postprocessor.<p>
44  *
45  * @author Michael Emmerich
46  *
47  * @version $Revision: 1.2 $
48  *
49  * @since 6.1.3
50  */

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

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

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

98     public void testVfsMemoryObjectCache() throws Exception JavaDoc {
99         
100         // get the cache
101
CmsVfsMemoryObjectCache cache = CmsVfsMemoryObjectCache.getVfsMemoryObjectCache();
102
103         
104         String JavaDoc res1RootPath ="/sites/default/index.html";
105         String JavaDoc res1Path ="/index.html";
106         CmsResource res1;
107         
108         // try to read from cache
109
Object JavaDoc o = cache.getCachedObject(getCmsObject(), res1RootPath);
110         // must be empty
111
assertNull(o);
112         
113         // read resource and put it in cache
114
res1 = getCmsObject().readResource(res1Path);
115         cache.putCachedObject(getCmsObject(), res1RootPath, res1);
116         
117         // try to read from cache
118
o = cache.getCachedObject(getCmsObject(), res1RootPath);
119         // must be the same as res1
120
assertEquals(o, res1);
121         
122         // now modify the resource
123
getCmsObject().lockResource(res1Path);
124         getCmsObject().setDateLastModified(res1Path, 12345, false);
125         getCmsObject().unlockResource(res1Path);
126         
127         // read it and compare it with the cached resourced
128
res1 = getCmsObject().readResource(res1Path);
129         o = cache.getCachedObject(getCmsObject(), res1RootPath);
130         // must be empty
131
assertNull(o);
132
133     }
134     
135  
136     
137     
138 }
139
Popular Tags