KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestReplace.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.CmsResourceTypePlain;
35 import org.opencms.lock.CmsLock;
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 tests for replace operation.<p>
46  *
47  * @author Carsten Weinholz
48  *
49  * @version $Revision: 1.9 $
50  */

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

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

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

94     public void testReplaceResourceContent() throws Throwable JavaDoc {
95
96         CmsObject cms = getCmsObject();
97         echo("Testing replacement of file content");
98         
99         String JavaDoc path = "/types/text.txt";
100         String JavaDoc contentStr = "Hello this is the new content";
101         
102         long timestamp = System.currentTimeMillis();
103         
104         storeResources(cms, path);
105         cms.lockResource(path);
106         cms.replaceResource(path, CmsResourceTypePlain.getStaticTypeId(), contentStr.getBytes(), null);
107         
108         // project must be current project
109
assertProject(cms, path, cms.getRequestContext().currentProject());
110         // state must be "new"
111
assertState(cms, path, CmsResource.STATE_CHANGED);
112         // date lastmodified must be new
113
assertDateLastModifiedAfter(cms, path, timestamp);
114         // user lastmodified must be current user
115
assertUserLastModified(cms, path, cms.getRequestContext().currentUser());
116         // assert lock state
117
assertLock(cms, path, CmsLock.TYPE_EXCLUSIVE);
118         // assert new content
119
assertContent(cms, path, contentStr.getBytes());
120         // now check the rest of the attributes
121
assertFilter(cms, path, OpenCmsTestResourceFilter.FILTER_REPLACERESOURCE);
122     }
123 }
124
Popular Tags