KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestProperty.java,v $
3  * Date : $Date: 2006/07/20 09:53:57 $
4  * Version: $Revision: 1.24 $
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.main.CmsRuntimeException;
36 import org.opencms.report.CmsShellReport;
37 import org.opencms.test.OpenCmsTestCase;
38 import org.opencms.test.OpenCmsTestProperties;
39 import org.opencms.test.OpenCmsTestResourceFilter;
40
41 import java.util.ArrayList JavaDoc;
42 import java.util.Collections JavaDoc;
43 import java.util.List JavaDoc;
44 import java.util.Locale JavaDoc;
45
46 import junit.extensions.TestSetup;
47 import junit.framework.Test;
48 import junit.framework.TestSuite;
49
50 /**
51  * Unit test for the "writeProperty" method of the CmsObject.<p>
52  *
53  * @author Michael Emmerich
54  * @version $Revision: 1.24 $
55  */

56 public class TestProperty extends OpenCmsTestCase {
57             
58     /**
59      * Default JUnit constructor.<p>
60      *
61      * @param arg0 JUnit parameters
62      */

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

72     public static Test suite() {
73
74         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
75
76         TestSuite suite = new TestSuite();
77         suite.setName(TestProperty.class.getName());
78
79         suite.addTest(new TestProperty("testFrozenProperty"));
80         suite.addTest(new TestProperty("testNullProperty"));
81         suite.addTest(new TestProperty("testSharedPropertyIssue1"));
82         suite.addTest(new TestProperty("testPropertyLists"));
83         suite.addTest(new TestProperty("testWriteProperty"));
84         suite.addTest(new TestProperty("testWriteProperties"));
85         suite.addTest(new TestProperty("testRemoveProperty"));
86         suite.addTest(new TestProperty("testRemoveProperties"));
87         suite.addTest(new TestProperty("testCreateProperty"));
88         suite.addTest(new TestProperty("testCreateProperties"));
89         suite.addTest(new TestProperty("testWritePropertyOnFolder"));
90         suite.addTest(new TestProperty("testDefaultPropertyCreation"));
91         suite.addTest(new TestProperty("testCaseSensitiveProperties"));
92         suite.addTest(new TestProperty("testReadResourcesWithProperty"));
93
94         TestSetup wrapper = new TestSetup(suite) {
95
96             protected void setUp() {
97
98                 setupOpenCms("simpletest", "/sites/default/");
99             }
100
101             protected void tearDown() {
102
103                 removeOpenCms();
104             }
105         };
106
107         return wrapper;
108     }
109         
110     /**
111      * Tests reading and writing property lists.<p>
112      *
113      * @throws Exception if the test fails
114      */

115     public void testPropertyLists() throws Exception JavaDoc {
116         
117         CmsObject cms = getCmsObject();
118         echo("Testing reading and writing property lists");
119         
120         String JavaDoc source = "/xmlcontent/article_0001.html";
121         cms.lockResource(source);
122         
123         CmsProperty prop;
124         prop = cms.readPropertyObject(source, CmsPropertyDefinition.PROPERTY_TITLE, false);
125         
126         // basic asserts so we know for shure where we start
127
assertEquals("Sample Article 1", prop.getValue());
128         assertEquals("Sample Article 1", prop.getStructureValue());
129         assertNull(prop.getResourceValue());
130         
131         // simple list asserts
132
assertEquals(1, prop.getValueList().size());
133         assertEquals(1, prop.getStructureValueList().size());
134         assertNull(prop.getResourceValueList());
135         
136         // now set the title as a list
137
List JavaDoc list = new ArrayList JavaDoc();
138         String JavaDoc value = "";
139         for (int i=1; i<=10; i++) {
140             String JavaDoc s = "Title " + i;
141             list.add(s);
142             value += s;
143             if (i<10) {
144                 value += CmsProperty.VALUE_LIST_DELIMITER;
145             }
146         }
147         prop.setStructureValueList(list);
148         
149         // asserts on non-written property
150
assertEquals(value, prop.getValue());
151         assertEquals(value, prop.getStructureValue());
152         assertNull(prop.getResourceValue());
153         assertEquals(10, prop.getValueList().size());
154         assertEquals(10, prop.getStructureValueList().size());
155         assertNull(prop.getResourceValueList());
156         list = prop.getValueList();
157         for (int i=1; i<=10; i++) {
158             String JavaDoc s = "Title " + i;
159             assertEquals(s, list.get(i-1).toString());
160         }
161         
162         // write the property object
163
cms.writePropertyObject(source, prop);
164         
165         // read and check the property
166
CmsProperty prop2 = cms.readPropertyObject(source, CmsPropertyDefinition.PROPERTY_TITLE, false);
167         
168         // asserts on written property
169
assertEquals(value, prop2.getValue());
170         assertEquals(value, prop2.getStructureValue());
171         assertNull(prop2.getResourceValue());
172         assertEquals(10, prop2.getValueList().size());
173         assertEquals(10, prop2.getStructureValueList().size());
174         assertNull(prop2.getResourceValueList());
175         list = prop2.getValueList();
176         for (int i=1; i<=10; i++) {
177             String JavaDoc s = "Title " + i;
178             assertEquals(s, list.get(i-1).toString());
179         }
180         
181         // setting a list via the single string value
182
prop.setStructureValue(null);
183         value = "Test|Toast|Hi|Ho";
184         prop.setValue(value, CmsProperty.TYPE_SHARED);
185         
186         assertEquals(value, prop.getValue());
187         assertEquals(value, prop.getResourceValue());
188         assertNull(prop.getStructureValue());
189         assertEquals(4, prop.getValueList().size());
190         assertEquals(4, prop.getResourceValueList().size());
191         assertNull(prop.getStructureValueList());
192         assertEquals("Test", prop.getResourceValueList().get(0));
193         assertEquals("Toast", prop.getResourceValueList().get(1));
194         assertEquals("Hi", prop.getResourceValueList().get(2));
195         assertEquals("Ho", prop.getResourceValueList().get(3));
196     }
197     
198     /**
199      * Test the writeProperty method to create a list of properties.<p>
200      * @param tc the OpenCmsTestCase
201      * @param cms the CmsObject
202      * @param resource1 the resource to create the properies
203      * @param propertyList1 the properties to create
204      * @throws Throwable if something goes wrong
205      */

206     public static void createProperties(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, List JavaDoc propertyList1) throws Throwable JavaDoc {
207
208          tc.storeResources(cms, resource1);
209
210          long timestamp = System.currentTimeMillis();
211                    
212          cms.lockResource(resource1);
213          cms.writePropertyObjects(resource1, propertyList1);
214          cms.unlockResource(resource1);
215          
216          // now evaluate the result
217
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
218          // project must be current project
219
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
220          // state must be "changed"
221
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
222          // date last modified must be after the test timestamp
223
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
224          // the user last modified must be the current user
225
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
226          // the properties must be new
227
tc.assertPropertyNew(cms, resource1, propertyList1);
228     }
229     
230     /**
231      * Test the writeProperty method to create one property.<p>
232      * @param tc the OpenCmsTestCase
233      * @param cms the CmsObject
234      * @param resource1 the resource to add a propery
235      * @param property1 the property to create
236      * @throws Throwable if something goes wrong
237      */

238     public static void createProperty(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, CmsProperty property1) throws Throwable JavaDoc {
239
240          tc.storeResources(cms, resource1);
241
242          long timestamp = System.currentTimeMillis();
243
244          cms.lockResource(resource1);
245          cms.writePropertyObject(resource1, property1);
246          cms.unlockResource(resource1);
247          
248          // now evaluate the result
249
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
250          // project must be current project
251
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
252          // state must be "changed"
253
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
254          // date last modified must be after the test timestamp
255
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
256          // the user last modified must be the current user
257
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
258          // the property must be new
259
tc.assertPropertyNew(cms, resource1, property1);
260     }
261     
262     /**
263      * Test the writeProperty method to remove a list of properties.<p>
264      * @param tc the OpenCmsTestCase
265      * @param cms the CmsObject
266      * @param resource1 the resource to remove the properies
267      * @param propertyList1 the properties to remove
268      * @throws Throwable if something goes wrong
269      */

270     public static void removeProperties(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, List JavaDoc propertyList1) throws Throwable JavaDoc {
271
272         tc.storeResources(cms, resource1);
273
274         long timestamp = System.currentTimeMillis();
275         
276         cms.lockResource(resource1);
277         cms.writePropertyObjects(resource1, propertyList1);
278         cms.unlockResource(resource1);
279         
280         // now evaluate the result
281
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
282         // project must be current project
283
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
284         // state must be "changed"
285
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
286         // date last modified must be after the test timestamp
287
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
288         // the user last modified must be the current user
289
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
290         // the properties must have been removed
291
tc.assertPropertyRemoved(cms, resource1, propertyList1);
292     }
293     
294     /**
295      * Test the writeProperty method to remove one property.<p>
296      * @param tc the OpenCmsTestCase
297      * @param cms the CmsObject
298      * @param resource1 the resource to remove a propery
299      * @param property1 the property to remove
300      * @throws Throwable if something goes wrong
301      */

302     public static void removeProperty(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, CmsProperty property1) throws Throwable JavaDoc {
303
304         tc.storeResources(cms, resource1);
305   
306          long timestamp = System.currentTimeMillis();
307          
308          cms.lockResource(resource1);
309          cms.writePropertyObject(resource1, property1);
310          cms.unlockResource(resource1);
311          
312          // now evaluate the result
313
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
314          // project must be current project
315
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
316          // state must be "changed"
317
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
318          // date last modified must be after the test timestamp
319
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
320          // the user last modified must be the current user
321
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
322          // the property must be removed
323
tc.assertPropertyRemoved(cms, resource1, property1);
324     }
325     
326     /**
327      * Test the writeProperty method with a list of properties.<p>
328      * @param tc the OpenCmsTestCase
329      * @param cms the CmsObject
330      * @param resource1 the resource to write the properies
331      * @param propertyList1 the properties to write
332      * @throws Throwable if something goes wrong
333      */

334     public static void writeProperties(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, List JavaDoc propertyList1) throws Throwable JavaDoc {
335
336          tc.storeResources(cms, resource1);
337   
338          long timestamp = System.currentTimeMillis();
339          
340          cms.lockResource(resource1);
341          cms.writePropertyObjects(resource1, propertyList1);
342          cms.unlockResource(resource1);
343          
344          // now evaluate the result
345
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
346          // project must be current project
347
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
348          // state must be "changed"
349
tc.assertState(cms, resource1, CmsResource.STATE_CHANGED);
350          // date last modified must be after the test timestamp
351
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
352          // the user last modified must be the current user
353
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
354          // the property must have the new value
355
tc.assertPropertyChanged(cms, resource1, propertyList1);
356     }
357     
358     /**
359      * Test the writeProperty method with one property.<p>
360      * @param tc the OpenCmsTestCase
361      * @param cms the CmsObject
362      * @param resource1 the resource to write a propery
363      * @param property1 the property to write
364      * @throws Throwable if something goes wrong
365      */

366     public static void writeProperty(OpenCmsTestCase tc, CmsObject cms, String JavaDoc resource1, CmsProperty property1) throws Throwable JavaDoc {
367           
368         tc.storeResources(cms, resource1);
369   
370          long timestamp = System.currentTimeMillis();
371                   
372          cms.lockResource(resource1);
373          cms.writePropertyObject(resource1, property1);
374          cms.unlockResource(resource1);
375          
376          // now evaluate the result
377
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
378          // project must be current project
379
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
380          // state must be "changed"
381
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
382          // date last modified must be after the test timestamp
383
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
384          // the user last modified must be the current user
385
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
386          // the property must have the new value
387
tc.assertPropertyChanged(cms, resource1, property1);
388     }
389     
390     /**
391      * Tests the writePropertyObjects method for removing of properties.<p>
392      *
393      * @throws Throwable if something goes wrong
394      */

395     public void testCreateProperties() throws Throwable JavaDoc {
396         
397         CmsObject cms = getCmsObject();
398         echo("Testing creating multiple properties on a resource");
399         CmsProperty property8 = new CmsProperty("Newproperty", "testvalue1", "testvalue2");
400         CmsProperty property9 = new CmsProperty("AnotherNewproperty", "anothervalue", null);
401         List JavaDoc propertyList3 = new ArrayList JavaDoc();
402         propertyList3.add(property8);
403         propertyList3.add(property9);
404         createProperties(this, cms, "/index.html", propertyList3);
405     }
406         
407     /**
408      * Tests the proper behaviour for case sensitiveness in property definition names.<p>
409      *
410      * @throws Throwable if something goes wrong
411      */

412     public void testCaseSensitiveProperties() throws Throwable JavaDoc {
413         
414         CmsObject cms = getCmsObject();
415         echo("Testing proper behaviour for case sensitiveness in property definition names");
416         CmsProperty myProperty = new CmsProperty("myProperty", "myValue", "myValue");
417         CmsProperty myproperty = new CmsProperty("myproperty", "myvalue", "myvalue");
418         cms.lockResource("/index.html");
419         cms.writePropertyObject("/index.html", myProperty);
420         cms.writePropertyObject("/index.html", myproperty);
421         cms.unlockResource("/index.html");
422         assertEquals("myValue", cms.readPropertyObject("/index.html", "myProperty", false).getResourceValue());
423         assertEquals("myvalue", cms.readPropertyObject("/index.html", "myproperty", false).getResourceValue());
424     }
425         
426     /**
427      * Tests the writePropertyObject method for removing of properties.<p>
428      *
429      * @throws Throwable if something goes wrong
430      */

431     public void testCreateProperty() throws Throwable JavaDoc {
432         
433         CmsObject cms = getCmsObject();
434         echo("Testing creating one property on a resource");
435         CmsProperty property7 = new CmsProperty("Newproperty", "testvalue1", "testvalue2");
436         createProperty(this, cms, "/folder1/index.html", property7);
437     }
438     
439     /**
440      * Tests the writePropertyObjects method for removing of multiple properties.<p>
441      *
442      * @throws Throwable if something goes wrong
443      */

444     public void testRemoveProperties() throws Throwable JavaDoc {
445             
446         CmsObject cms = getCmsObject();
447         echo("Testing removing multiple properties on a resource");
448         CmsProperty property5 = new CmsProperty("Title", CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE);
449         CmsProperty property6 = new CmsProperty("NavPos", CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE);
450         List JavaDoc propertyList2 = new ArrayList JavaDoc();
451         propertyList2.add(property5);
452         propertyList2.add(property6);
453         removeProperties(this, cms, "/folder1/page1.html", propertyList2);
454     }
455     
456     /**
457      * Tests the writePropertyObject method for removing of a single property.<p>
458      *
459      * @throws Throwable if something goes wrong
460      */

461     public void testRemoveProperty() throws Throwable JavaDoc {
462         
463         CmsObject cms = getCmsObject();
464         echo("Testing removing one property on a resource");
465         CmsProperty property4 = new CmsProperty("Title", CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE);
466         removeProperty(this, cms, "/folder1/page2.html", property4);
467     }
468         
469     /**
470      * Tests the writeProperties method.<p>
471      *
472      * @throws Throwable if something goes wrong
473      */

474     public void testWriteProperties() throws Throwable JavaDoc {
475                 
476         CmsObject cms = getCmsObject();
477         echo("Testing writing multiple properties on a resource");
478         CmsProperty property2 = new CmsProperty("Title", "OpenCms", null);
479         CmsProperty property3 = new CmsProperty("NavPos", "1", null);
480         List JavaDoc propertyList1 = new ArrayList JavaDoc();
481         propertyList1.add(property2);
482         propertyList1.add(property3);
483         writeProperties(this, cms, "/folder1/page3.html", propertyList1);
484     }
485     
486     /**
487      * Tests the writePropertyObject method.<p>
488      *
489      * @throws Throwable if something goes wrong
490      */

491     public void testWriteProperty() throws Throwable JavaDoc {
492         
493         CmsObject cms = getCmsObject();
494         echo("Testing writing one property on a resource");
495         CmsProperty property1 = new CmsProperty("Title", "OpenCms", null);
496         writeProperty(this, cms, "/folder1/image1.gif", property1);
497     }
498     
499     /**
500      * Tests the writePropertyObject method for writing of a property on a folder.<p>
501      *
502      * @throws Throwable if something goes wrong
503      */

504     public void testWritePropertyOnFolder() throws Throwable JavaDoc {
505         
506         CmsObject cms = getCmsObject();
507         echo("Testing writing one property on a folder");
508         CmsProperty property10 = new CmsProperty("Title", "OpenCms", null);
509         writeProperty(this, cms, "/folder2/", property10);
510     }
511
512     /**
513      * Tests the writePropertyObject method for writing of a property on a folder.<p>
514      *
515      * @throws Throwable if something goes wrong
516      */

517     public void testReadResourcesWithProperty() throws Throwable JavaDoc {
518         
519         CmsObject cms = getCmsObject();
520         echo("Testing reading resources with property");
521         
522         String JavaDoc typesUri = "/types";
523         CmsResource res = cms.readResource(typesUri);
524         // now set "exportname" property and try again
525
cms.lockResource(typesUri);
526         cms.writePropertyObject(typesUri, new CmsProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME, "myfolder", null));
527         // publish the changes
528
cms.publishProject();
529         
530         List JavaDoc result = cms.readResourcesWithProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME);
531         assertTrue(result.contains(res));
532     }
533     
534     /**
535      * Test default property creation (from resource type configuration).<p>
536      *
537      * @throws Throwable if something goes wrong
538      */

539     public void testDefaultPropertyCreation() throws Throwable JavaDoc {
540         
541         CmsObject cms = getCmsObject();
542         echo("Testing default property creation");
543         
544         String JavaDoc resourcename = "/folder1/article_test.html";
545         byte[] content = new byte[0];
546         
547         // resource 12 is article (xml content) with default properties
548
cms.createResource(resourcename, 12, content, null);
549         
550         // ensure created resource type
551
assertResourceType(cms, resourcename, 12);
552         // project must be current project
553
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
554         // state must be "new"
555
assertState(cms, resourcename, CmsResource.STATE_NEW);
556         // the user last modified must be the current user
557
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
558                
559         CmsProperty property1, property2;
560         property1 = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "Test title", null);
561         property2 = cms.readPropertyObject(resourcename, CmsPropertyDefinition.PROPERTY_TITLE, false);
562         assertTrue(property1.isIdentical(property2));
563         
564         property1 = new CmsProperty("template-elements", "/system/modules/org.opencms.frontend.templateone.form/pages/form.html", null);
565         property2 = cms.readPropertyObject(resourcename, "template-elements", false);
566         assertTrue(property1.isIdentical(property2));
567
568         property1 = new CmsProperty(CmsPropertyDefinition.PROPERTY_DESCRIPTION, null, "Admin_/folder1/article_test.html_/sites/default/folder1/article_test.html");
569         property2 = cms.readPropertyObject(resourcename, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
570         assertTrue(property1.isIdentical(property2));
571         
572         // publish the project
573
cms.unlockProject(cms.getRequestContext().currentProject().getId());
574         cms.publishProject();
575         
576         assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
577     }
578     
579     /**
580      * Tests an issue with shared properties after deletion of the original sibling.<p>
581      *
582      * Scenario:
583      * A file A has property P set with value V as shared property. Now A is renamed to B.
584      * Then B is published directly with all siblings (A is now deleted and removed).
585      * Issue: Property P is now empty in B, but should still have the V value.<p>
586      *
587      * @throws Throwable if something goes wrong
588      */

589     public void testSharedPropertyIssue1() throws Throwable JavaDoc {
590
591         CmsObject cms = getCmsObject();
592         echo("Testing issue with shared properties after deletion of the original sibling");
593
594         // switch to the "Offline" project
595
CmsProject offline = cms.readProject("Offline");
596         cms.getRequestContext().setCurrentProject(offline);
597
598         // create and publish the resource
599
String JavaDoc source = "/folder1/testprop.txt";
600         String JavaDoc dest = "/folder1/testprop2.txt";
601
602         cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
603         cms.unlockProject(offline.getId());
604         cms.publishResource(source);
605
606         // now create the shared property on the source
607
cms.lockResource(source);
608         CmsProperty descProperty = new CmsProperty(CmsPropertyDefinition.PROPERTY_DESCRIPTION, null, "A shared value");
609         cms.writePropertyObject(source, descProperty);
610         cms.unlockProject(offline.getId());
611         cms.publishResource(source);
612
613         // now move the resource to a new name and publish again, ensure the property is still there
614
cms.lockResource(source);
615         cms.moveResource(source, dest);
616         cms.unlockProject(offline.getId());
617         cms.publishResource(dest, true, new CmsShellReport(Locale.ENGLISH));
618
619         CmsProperty resultProperty = cms.readPropertyObject(dest, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
620         assertEquals("A shared value", descProperty.getResourceValue());
621         assertTrue(
622             "Property '" + CmsPropertyDefinition.PROPERTY_DESCRIPTION + "' must be identical",
623             descProperty.isIdentical(resultProperty));
624     }
625     
626     /**
627      * Tests the NULL_PROPERTY.<p>
628      *
629      * @throws Exception if the test fails
630      */

631     public void testNullProperty() throws Exception JavaDoc {
632         
633         // get the null property
634
CmsProperty nullProperty = CmsProperty.getNullProperty();
635         // create another property
636
CmsProperty p = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "Some title", null);
637         // do a comparison
638
assertFalse("Created property must not be equal to NULL_PROPERTY", p.equals(nullProperty));
639         assertFalse("NULL_PROPERTY must not be equal to created Property", nullProperty.equals(p));
640         assertTrue("NULL_PROPERTY must be equal to itself", nullProperty.equals(nullProperty));
641         assertTrue("NULL_PROPERTY must be identical to itself", nullProperty == CmsProperty.getNullProperty());
642     }
643     
644     /**
645      * Tests changing the values of a frozen property.<p>
646      *
647      * @throws Throwable if something goes wrong
648      */

649     public void testFrozenProperty() throws Throwable JavaDoc {
650         
651         CmsProperty property = CmsProperty.getNullProperty();
652         if (! property.isFrozen()) {
653             fail("NULL_PROPERTY is not frozen!");
654         }
655         boolean gotException = false;
656         try {
657             property.setAutoCreatePropertyDefinition(true);
658         } catch (CmsRuntimeException e) {
659             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
660             gotException = true;
661         }
662         assertTrue("Operation did not throw the required Exception", gotException);
663         gotException = false;
664         try {
665             property.setFrozen(false);
666         } catch (CmsRuntimeException e) {
667             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
668             gotException = true;
669         }
670         assertTrue("Operation did not throw the required Exception", gotException);
671         gotException = false;
672         try {
673             property.setName("SomeString");
674         } catch (CmsRuntimeException e) {
675             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
676             gotException = true;
677         }
678         assertTrue("Operation did not throw the required Exception", gotException);
679         gotException = false;
680         try {
681             property.setValue("SomeString", CmsProperty.TYPE_INDIVIDUAL);
682         } catch (CmsRuntimeException e) {
683             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
684             gotException = true;
685         }
686         assertTrue("Operation did not throw the required Exception", gotException);
687         gotException = false;
688         try {
689             property.setResourceValue("SomeString");
690         } catch (CmsRuntimeException e) {
691             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
692             gotException = true;
693         }
694         assertTrue("Operation did not throw the required Exception", gotException);
695         gotException = false;
696         try {
697             property.setStructureValue("SomeString");
698         } catch (CmsRuntimeException e) {
699             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
700             gotException = true;
701         }
702         assertTrue("Operation did not throw the required Exception", gotException);
703         gotException = false;
704         try {
705             property.setResourceValueList(Collections.singletonList("SomeString"));
706         } catch (CmsRuntimeException e) {
707             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
708             gotException = true;
709         }
710         assertTrue("Operation did not throw the required Exception", gotException);
711         gotException = false;
712         try {
713             property.setStructureValueList(Collections.singletonList("SomeString"));
714         } catch (CmsRuntimeException e) {
715             assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
716             gotException = true;
717         }
718         assertTrue("Operation did not throw the required Exception", gotException);
719     }
720 }
Popular Tags