KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestChangeProperties.java,v $
3  * Date : $Date: 2005/06/25 12:02:09 $
4  * Version: $Revision: 1.1 $
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.test.OpenCmsTestCase;
35 import org.opencms.test.OpenCmsTestProperties;
36
37 import java.util.List JavaDoc;
38
39 import junit.extensions.TestSetup;
40 import junit.framework.Test;
41 import junit.framework.TestSuite;
42
43 /**
44  * Unit tests for the <code>{@link CmsObject#changeResourcesInFolderWithProperty(String, String, String, String, boolean)}</code>
45  * method.<p>
46  *
47  * @author Matthias Gafert
48  *
49  * @version $Revision: 1.1 $
50  */

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

58     public TestChangeProperties(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(TestChangeProperties.class.getName());
74
75         suite.addTest(new TestChangeProperties("testChangeResourcesRelativePath"));
76         suite.addTest(new TestChangeProperties("testChangeResourcesFullPath"));
77
78         TestSetup wrapper = new TestSetup(suite) {
79
80             protected void setUp() {
81
82                 setupOpenCms("simpletest", "/sites/default/");
83             }
84
85             protected void tearDown() {
86
87                 removeOpenCms();
88             }
89         };
90
91         return wrapper;
92     }
93
94     /**
95      * Tries to change the "Description" property of the two files
96      * "/folder1/index.html" and "/folder2/index.html" with the site-root
97      * "/sites/default".
98      *
99      * The test fails, if the <code>recursive</code> parameter of
100      * <code>changeResourcesInFolderWithProperty()</code> changes the
101      * semantics of the method call.<p>
102      *
103      * @throws Throwable if an error occurs while the test is running
104      */

105     public void testChangeResourcesRelativePath() throws Throwable JavaDoc {
106
107         CmsObject cms = getCmsObject();
108
109         // Init
110
String JavaDoc resource1 = "/folder1/subfolder11/index.html";
111         String JavaDoc resource2 = "/folder1/subfolder12/index.html";
112         cms.lockResource(resource1);
113         cms.lockResource(resource2);
114         assertLock(cms, resource1);
115         assertLock(cms, resource2);
116
117         // Recursive semantics
118
System.out.println("Changing property of \""
119             + resource1
120             + "\" in \""
121             + cms.getRequestContext().getSiteRoot()
122             + "\"");
123
124         List JavaDoc l1 = cms.changeResourcesInFolderWithProperty(
125             resource1,
126             CmsPropertyDefinition.PROPERTY_DESCRIPTION,
127             "This is the index page of subfolder11",
128             "Changed Value",
129             true);
130
131         // Non-recursive semantics
132
System.out.println("Changing property of \""
133             + resource2
134             + "\" in \""
135             + cms.getRequestContext().getSiteRoot()
136             + "\"");
137
138         List JavaDoc l2 = cms.changeResourcesInFolderWithProperty(
139             resource2,
140             CmsPropertyDefinition.PROPERTY_DESCRIPTION,
141             "This is the index in subfolder12",
142             "Changed value",
143             false);
144
145         // One resource should have been changed with each call
146
assertEquals(l1.size(), l2.size());
147     }
148
149     /**
150      * Tries to change the "Description" property of the two files
151      * "/sites/default/folder1/index.html" and
152      * "/sites/default/folder2/index.html" with the site-root "".
153      *
154      * The test fails, if the <code>recursive</code> parameter of
155      * <code>changeResourcesInFolderWithProperty()</code> changes the
156      * semantics of the method call.<p>
157      *
158      * @throws Throwable if an error occurs while the test is running
159      */

160     public void testChangeResourcesFullPath() throws Throwable JavaDoc {
161
162         CmsObject cms = getCmsObject();
163
164         // Init
165
String JavaDoc resource1 = cms.getRequestContext().getSiteRoot() + "/folder2/subfolder21/index.html";
166         String JavaDoc resource2 = cms.getRequestContext().getSiteRoot() + "/folder2/subfolder22/index.html";
167
168         cms.getRequestContext().setSiteRoot("");
169
170         cms.lockResource(resource1);
171         cms.lockResource(resource2);
172         assertLock(cms, resource1);
173         assertLock(cms, resource2);
174
175         // Recursive semantics
176
System.out.println("Changing property of \""
177             + resource1
178             + "\" in \""
179             + cms.getRequestContext().getSiteRoot()
180             + "\"");
181
182         List JavaDoc l1 = cms.changeResourcesInFolderWithProperty(
183             resource1,
184             CmsPropertyDefinition.PROPERTY_DESCRIPTION,
185             "This is the index page in subfolder21",
186             "Changed Value",
187             true);
188
189         // Non-recursive semantics
190
System.out.println("Changing property of \""
191             + resource2
192             + "\" in \""
193             + cms.getRequestContext().getSiteRoot()
194             + "\"");
195
196         List JavaDoc l2 = cms.changeResourcesInFolderWithProperty(
197             resource2,
198             CmsPropertyDefinition.PROPERTY_DESCRIPTION,
199             "This is the index page in subfolder22",
200             "Changed value",
201             false);
202
203         // One resource should have been changed with each call
204
assertEquals(l1.size(), l2.size());
205     }
206 }
207
Popular Tags