KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > file > types > TestConfigurationOptions


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/types/TestConfigurationOptions.java,v $
3  * Date : $Date: 2005/06/27 23:22:30 $
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.types;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsProperty;
36 import org.opencms.file.CmsPropertyDefinition;
37 import org.opencms.file.CmsResource;
38 import org.opencms.file.CmsResourceFilter;
39 import org.opencms.test.OpenCmsTestCase;
40 import org.opencms.test.OpenCmsTestProperties;
41
42 import java.util.List JavaDoc;
43
44 import junit.extensions.TestSetup;
45 import junit.framework.Test;
46 import junit.framework.TestSuite;
47
48 /**
49  * Unit tests for the resource type configuration options.<p>
50  *
51  * @author Alexander Kandzior
52  * @version $Revision: 1.6 $
53  */

54 public class TestConfigurationOptions extends OpenCmsTestCase {
55
56     /**
57      * Default JUnit constructor.<p>
58      *
59      * @param arg0 JUnit parameters
60      */

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

71     public static Test suite() {
72
73         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
74
75         TestSuite suite = new TestSuite();
76         suite.setName(TestConfigurationOptions.class.getName());
77
78         suite.addTest(new TestConfigurationOptions("testDefaultPropertyCreation"));
79         suite.addTest(new TestConfigurationOptions("testCopyResourcesOnCreation"));
80
81         TestSetup wrapper = new TestSetup(suite) {
82
83             protected void setUp() {
84
85                 setupOpenCms("simpletest", "/sites/default/");
86             }
87
88             protected void tearDown() {
89
90                 removeOpenCms();
91             }
92         };
93
94         return wrapper;
95     }
96
97     /**
98      * Test copy resources on resource creation .<p>
99      *
100      * @throws Throwable if something goes wrong
101      */

102     public void testCopyResourcesOnCreation() throws Throwable JavaDoc {
103
104         CmsObject cms = getCmsObject();
105         echo("Testing 'copy resources' on resource creation");
106
107         // create a new type "11", default tests have this configured as "link gallery" folder
108
String JavaDoc resourcename = "/newlinkgallery/";
109
110         cms.createResource(resourcename, 11);
111
112         List JavaDoc subResources = cms.readResources(resourcename, CmsResourceFilter.ALL);
113         assertTrue(subResources.size() > 15);
114
115         // read some of the newly created copy resources to make sure they exist
116
CmsResource res;
117
118         res = cms.readResource(resourcename + "newname.html");
119         // must have 1 additional sibling
120
assertTrue(res.getSiblingCount() == 2);
121
122         cms.readResource(resourcename + "mytypes");
123         res = cms.readResource(resourcename + "mytypes/text.txt");
124         // should have no sibling
125
assertTrue(res.getSiblingCount() == 1);
126
127         cms.readResource(resourcename + "subfolder11");
128         cms.readResource(resourcename + "subfolder11/subsubfolder111");
129     }
130
131     /**
132      * Test default property creation (from resource type configuration).<p>
133      *
134      * @throws Throwable if something goes wrong
135      */

136     public void testDefaultPropertyCreation() throws Throwable JavaDoc {
137
138         CmsObject cms = getCmsObject();
139         echo("Testing default property creation");
140
141         String JavaDoc resourcename = "/folder1/article_test.html";
142         byte[] content = new byte[0];
143
144         // resource 12 is article (xml content) with default properties
145
cms.createResource(resourcename, 12, content, null);
146
147         // ensure created resource type
148
assertResourceType(cms, resourcename, 12);
149         // project must be current project
150
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
151         // state must be "new"
152
assertState(cms, resourcename, CmsResource.STATE_NEW);
153         // the user last modified must be the current user
154
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
155
156         CmsProperty property1, property2;
157         property1 = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "Test title", null);
158         property2 = cms.readPropertyObject(resourcename, CmsPropertyDefinition.PROPERTY_TITLE, false);
159         assertTrue(property1.isIdentical(property2));
160
161         property1 = new CmsProperty(
162             "template-elements",
163             "/system/modules/org.opencms.frontend.templateone.form/pages/form.html",
164             null);
165         property2 = cms.readPropertyObject(resourcename, "template-elements", false);
166         assertTrue(property1.isIdentical(property2));
167
168         property1 = new CmsProperty(
169             CmsPropertyDefinition.PROPERTY_DESCRIPTION,
170             null,
171             "Admin_/folder1/article_test.html_/sites/default/folder1/article_test.html");
172         property2 = cms.readPropertyObject(resourcename, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
173         assertTrue(property1.isIdentical(property2));
174
175         // publish the project
176
cms.unlockProject(cms.getRequestContext().currentProject().getId());
177         cms.publishProject();
178
179         assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
180     }
181 }
182
Popular Tags