KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestCreateWriteResource.java,v $
3  * Date : $Date: 2005/06/28 20:40:34 $
4  * Version: $Revision: 1.19 $
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.CmsResourceTypeFolder;
35 import org.opencms.file.types.CmsResourceTypePlain;
36 import org.opencms.main.CmsIllegalArgumentException;
37 import org.opencms.test.OpenCmsTestCase;
38 import org.opencms.test.OpenCmsTestProperties;
39 import org.opencms.test.OpenCmsTestResourceConfigurableFilter;
40 import org.opencms.test.OpenCmsTestResourceFilter;
41 import org.opencms.util.CmsUUID;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.List JavaDoc;
45
46 import junit.extensions.TestSetup;
47 import junit.framework.Test;
48 import junit.framework.TestSuite;
49
50 /**
51  * Unit tests for the create and import methods.<p>
52  *
53  * @author Alexander Kandzior
54  * @version $Revision: 1.19 $
55  */

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

63     public TestCreateWriteResource(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         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
74         
75         TestSuite suite = new TestSuite();
76         suite.setName(TestCreateWriteResource.class.getName());
77         
78         suite.addTest(new TestCreateWriteResource("testImportResource"));
79         suite.addTest(new TestCreateWriteResource("testImportResourceAgain"));
80         suite.addTest(new TestCreateWriteResource("testImportSibling"));
81         suite.addTest(new TestCreateWriteResource("testImportFolder"));
82         suite.addTest(new TestCreateWriteResource("testImportFolderAgain"));
83         suite.addTest(new TestCreateWriteResource("testCreateResource"));
84         suite.addTest(new TestCreateWriteResource("testCreateResourceAgain"));
85         suite.addTest(new TestCreateWriteResource("testCreateFolder"));
86         suite.addTest(new TestCreateWriteResource("testCreateFolderAgain"));
87         suite.addTest(new TestCreateWriteResource("testCreateDotnameResources"));
88         
89         TestSetup wrapper = new TestSetup(suite) {
90             
91             protected void setUp() {
92                 setupOpenCms("simpletest", "/sites/default/");
93             }
94             
95             protected void tearDown() {
96                 // removeOpenCms();
97
}
98         };
99         
100         return wrapper;
101    }
102     
103     /**
104      * Test creation of invalid resources that have only dots in their name.<p>
105      *
106      * @throws Throwable if something goes wrong
107      */

108     public void testCreateDotnameResources() throws Throwable JavaDoc {
109         
110         CmsObject cms = getCmsObject();
111         echo("Testing creating a resource with only dots in the name");
112         
113         Exception JavaDoc error = null;
114         try {
115             cms.createResource("/folder1/.", CmsResourceTypeFolder.getStaticTypeId(), null, null);
116         } catch (CmsIllegalArgumentException e) {
117             assertEquals(org.opencms.db.Messages.ERR_CREATE_RESOURCE_1, e.getMessageContainer().getKey());
118             error = e;
119         }
120         assertNotNull(error);
121         error = null;
122         try {
123             cms.createResource("/folder1/..", CmsResourceTypePlain.getStaticTypeId(), null, null);
124         } catch (CmsIllegalArgumentException e) {
125             assertEquals(org.opencms.db.Messages.ERR_CREATE_RESOURCE_1, e.getMessageContainer().getKey());
126             error = e;
127         }
128         assertNotNull(error);
129         error = null;
130         try {
131             cms.createResource("/folder1/.../", CmsResourceTypeFolder.getStaticTypeId(), null, null);
132         } catch (CmsIllegalArgumentException e) {
133             assertEquals(org.opencms.db.Messages.ERR_CREATE_RESOURCE_1, e.getMessageContainer().getKey());
134             error = e;
135         }
136         assertNotNull(error);
137         error = null;
138         try {
139             cms.createResource("/folder1/....", CmsResourceTypePlain.getStaticTypeId(), null, null);
140         } catch (CmsIllegalArgumentException e) {
141             assertEquals(org.opencms.db.Messages.ERR_CREATE_RESOURCE_1, e.getMessageContainer().getKey());
142             error = e;
143         }
144         assertNotNull(error);
145         error = null;
146         try {
147             cms.createResource("/folder1/...../", CmsResourceTypeFolder.getStaticTypeId(), null, null);
148         } catch (CmsIllegalArgumentException e) {
149             assertEquals(org.opencms.db.Messages.ERR_CREATE_RESOURCE_1, e.getMessageContainer().getKey());
150             error = e;
151         }
152         assertNotNull(error);
153     }
154    
155    /**
156     * Test the create resource method for a folder.<p>
157     *
158     * @throws Throwable if something goes wrong
159     */

160    public void testCreateFolder() throws Throwable JavaDoc {
161
162        CmsObject cms = getCmsObject();
163        echo("Testing creating a folder");
164        
165        String JavaDoc resourcename = "/folder1/test2/";
166        long timestamp = System.currentTimeMillis()-1;
167        
168        cms.createResource(resourcename, CmsResourceTypeFolder.getStaticTypeId(), null, null);
169        
170        // check the created folder
171
CmsFolder folder = cms.readFolder(resourcename);
172        
173        assertEquals(folder.getState(), CmsResource.STATE_NEW);
174        assertTrue(folder.getDateLastModified() > timestamp);
175        assertTrue(folder.getDateCreated() > timestamp);
176        
177        // ensure created resource is a folder
178
assertIsFolder(cms, resourcename);
179        // project must be current project
180
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
181        // state must be "new"
182
assertState(cms, resourcename, CmsResource.STATE_NEW);
183        // date last modified
184
assertDateLastModifiedAfter(cms, resourcename, timestamp);
185        // date created
186
assertDateCreatedAfter(cms, resourcename, timestamp);
187        // the user last modified must be the current user
188
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
189        
190        // publish the project
191
cms.unlockProject(cms.getRequestContext().currentProject().getId());
192        cms.publishProject();
193        
194        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
195    }
196    
197    /**
198     * Test the create a folder again.<p>
199     *
200     * @throws Throwable if something goes wrong
201     */

202    public void testCreateFolderAgain() throws Throwable JavaDoc {
203
204        CmsObject cms = getCmsObject();
205        echo("Testing to create an existing folder again");
206
207        String JavaDoc resourcename = "/folder1/test2/";
208        storeResources(cms, resourcename);
209        long timestamp = System.currentTimeMillis();
210        
211        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
212        cms.lockResource(resourcename);
213        
214        try {
215            // resource exists and is not deleted, creation must thrw exception
216
cms.createResource(resourcename, CmsResourceTypeFolder.getStaticTypeId(), null, null);
217        } catch (CmsVfsException e) {
218            if (!(e instanceof CmsVfsResourceAlreadyExistsException)) {
219                fail("Existing resource '" + resourcename + "' was not detected!");
220            }
221        }
222        
223        // read resource for comparing id's later
224
CmsResource original = cms.readResource(resourcename);
225        
226        // delete resource and try again
227
cms.deleteResource(resourcename, CmsResource.DELETE_PRESERVE_SIBLINGS);
228        cms.createResource(resourcename, CmsResourceTypeFolder.getStaticTypeId(), null, null);
229        
230        // ensure created resource is a folder
231
assertIsFolder(cms, resourcename);
232        // project must be current project
233
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
234        // state must be "changed"
235
assertState(cms, resourcename, CmsResource.STATE_CHANGED);
236        // date last modified
237
assertDateLastModifiedAfter(cms, resourcename, timestamp);
238        // the user last modified must be the current user
239
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
240        // date created
241
assertDateCreated(cms, resourcename, original.getDateCreated());
242        // the user created must be the current user
243
assertUserCreated(cms, resourcename, cms.readUser(original.getUserCreated()));
244        
245        // compare id's
246
CmsResource created = cms.readResource(resourcename);
247        if (! created.getResourceId().equals(original.getResourceId())) {
248            fail("A created folder that replaced a deleted folder must have the same resource id!");
249        }
250        
251        // publish the project
252
cms.unlockProject(cms.getRequestContext().currentProject().getId());
253        cms.publishProject();
254        
255        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
256    }
257     
258    /**
259     * Test the create resource method.<p>
260     *
261     * @throws Throwable if something goes wrong
262     */

263    public void testCreateResource() throws Throwable JavaDoc {
264
265        CmsObject cms = getCmsObject();
266        echo("Testing create resource");
267        
268        String JavaDoc resourcename = "/folder1/test2.html";
269        long timestamp = System.currentTimeMillis()-1;
270               
271        String JavaDoc contentStr = "Hello this is my other content";
272        byte[] content = contentStr.getBytes();
273        
274        cms.createResource(resourcename, CmsResourceTypePlain.getStaticTypeId(), content, null);
275        
276        // ensure created resource type
277
assertResourceType(cms, resourcename, CmsResourceTypePlain.getStaticTypeId());
278        // project must be current project
279
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
280        // state must be "new"
281
assertState(cms, resourcename, CmsResource.STATE_NEW);
282        // date last modified
283
assertDateLastModifiedAfter(cms, resourcename, timestamp);
284        // date created
285
assertDateCreatedAfter(cms, resourcename, timestamp);
286        // the user last modified must be the current user
287
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
288        // check the content
289
assertContent(cms, resourcename, content);
290               
291        // publish the project
292
cms.unlockProject(cms.getRequestContext().currentProject().getId());
293        cms.publishProject();
294        
295        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
296    }
297    
298    /**
299     * Test the create resource method for an already existing resource.<p>
300     *
301     * @throws Throwable if something goes wrong
302     */

303    public void testCreateResourceAgain() throws Throwable JavaDoc {
304
305        CmsObject cms = getCmsObject();
306        echo("Testing to create an existing resource again");
307
308        String JavaDoc resourcename = "/folder1/test2.html";
309        storeResources(cms, resourcename);
310        long timestamp = System.currentTimeMillis();
311        
312        String JavaDoc contentStr = "Hello this is my NEW AND ALSO CHANGED other content";
313        byte[] content = contentStr.getBytes();
314
315        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
316        cms.lockResource(resourcename);
317        
318        try {
319            // resource exists and is not deleted, creation must throw exception
320
cms.createResource(resourcename, CmsResourceTypePlain.getStaticTypeId(), content, null);
321        } catch (Throwable JavaDoc e) {
322            if (!(e instanceof CmsVfsResourceAlreadyExistsException)) {
323                fail("Existing resource '" + resourcename + "' was not detected!");
324            }
325        }
326
327        // read resource for comparing id's later
328
CmsResource original = cms.readResource(resourcename);
329        
330        // delete resource and try again
331
cms.deleteResource(resourcename, CmsResource.DELETE_PRESERVE_SIBLINGS);
332        cms.createResource(resourcename, CmsResourceTypePlain.getStaticTypeId(), content, null);
333               
334        // project must be current project
335
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
336        // state must be "changed"
337
assertState(cms, resourcename, CmsResource.STATE_CHANGED);
338        // date last modified
339
assertDateLastModifiedAfter(cms, resourcename, timestamp);
340        // the user last modified must be the current user
341
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
342        // date created
343
assertDateCreatedAfter(cms, resourcename, timestamp);
344        // the user created must be the current user
345
assertUserCreated(cms, resourcename, cms.getRequestContext().currentUser());
346        // check the content
347
assertContent(cms, resourcename, content);
348        
349        // compare id's
350
CmsResource created = cms.readResource(resourcename);
351        if (created.getResourceId().equals(original.getResourceId())) {
352            fail("A created resource that replaced a deleted resource must not have the same resource id!");
353        }
354        
355        // publish the project
356
cms.unlockProject(cms.getRequestContext().currentProject().getId());
357        cms.publishProject();
358               
359        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
360    }
361
362     /**
363      * Test the import resource method with a folder.<p>
364      *
365      * @throws Throwable if something goes wrong
366      */

367     public void testImportFolder() throws Throwable JavaDoc {
368
369         CmsObject cms = getCmsObject();
370         echo("Testing import resource for a folder");
371         
372         String JavaDoc resourcename = "/folder1/test1/";
373         
374         long timestamp = System.currentTimeMillis() - 87654321;
375         
376         // create a new resource
377
CmsResource resource = new CmsResource (
378             CmsUUID.getNullUUID(),
379             CmsUUID.getNullUUID(),
380             resourcename,
381             CmsResourceTypeFolder.getStaticTypeId(),
382             true,
383             0,
384             cms.getRequestContext().currentProject().getId(),
385             CmsResource.STATE_NEW,
386             timestamp,
387             cms.getRequestContext().currentUser().getId(),
388             timestamp,
389             cms.getRequestContext().currentUser().getId(),
390             CmsResource.DATE_RELEASED_DEFAULT,
391             CmsResource.DATE_EXPIRED_DEFAULT,
392             1, -1
393         );
394         
395         cms.importResource(resourcename, resource, null, null);
396         
397         // ensure created resource is a folder
398
assertIsFolder(cms, resourcename);
399         // project must be current project
400
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
401         // state must be "new"
402
assertState(cms, resourcename, CmsResource.STATE_NEW);
403         // date last modified
404
assertDateLastModified(cms, resourcename, timestamp);
405         // date created
406
assertDateCreated(cms, resourcename, timestamp);
407         // the user last modified must be the current user
408
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
409         
410         // publish the project
411
cms.unlockProject(cms.getRequestContext().currentProject().getId());
412         cms.publishProject();
413         
414         assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
415     }
416     
417     /**
418      * Test the import resource method for an existing folder.<p>
419      *
420      * @throws Throwable if something goes wrong
421      */

422     public void testImportFolderAgain() throws Throwable JavaDoc {
423
424         CmsObject cms = getCmsObject();
425         echo("Testing to import an existing folder again");
426         
427         String JavaDoc resourcename = "/folder1/test1/";
428         
429         storeResources(cms, resourcename);
430         long timestamp = System.currentTimeMillis() - 12345678;
431
432         // create a new folder
433
CmsResource resource = new CmsResource (
434             CmsUUID.getNullUUID(),
435             CmsUUID.getNullUUID(),
436             resourcename,
437             CmsResourceTypeFolder.getStaticTypeId(),
438             true,
439             0,
440             cms.getRequestContext().currentProject().getId(),
441             CmsResource.STATE_NEW,
442             timestamp,
443             cms.getRequestContext().currentUser().getId(),
444             timestamp,
445             cms.getRequestContext().currentUser().getId(),
446             CmsResource.DATE_RELEASED_DEFAULT,
447             CmsResource.DATE_EXPIRED_DEFAULT,
448             1, -1
449         );
450         
451         cms.importResource(resourcename, resource, null, null);
452         
453         // ensure created resource is a folder
454
assertIsFolder(cms, resourcename);
455         // project must be current project
456
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
457         // state must be "new"
458
assertState(cms, resourcename, CmsResource.STATE_CHANGED);
459         // date last modified
460
assertDateLastModified(cms, resourcename, timestamp);
461         // the user last modified must be the current user
462
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
463         // now evaluate the filter
464
assertFilter(cms, resourcename, OpenCmsTestResourceFilter.FILTER_CREATE_RESOURCE);
465         
466         // publish the project
467
cms.unlockProject(cms.getRequestContext().currentProject().getId());
468         cms.publishProject();
469         
470         assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
471     }
472     
473     /**
474      * Test the import resource method.<p>
475      *
476      * @throws Throwable if something goes wrong
477      */

478     public void testImportResource() throws Throwable JavaDoc {
479
480         CmsObject cms = getCmsObject();
481         echo("Testing import resource");
482         
483         String JavaDoc resourcename = "/folder1/test1.html";
484         
485         String JavaDoc contentStr = "Hello this is my content";
486         byte[] content = contentStr.getBytes();
487         long timestamp = System.currentTimeMillis() - 87654321;
488         
489         // create a new resource
490
CmsResource resource = new CmsResource (
491             CmsUUID.getNullUUID(),
492             CmsUUID.getNullUUID(),
493             resourcename,
494             CmsResourceTypePlain.getStaticTypeId(),
495             false,
496             0,
497             cms.getRequestContext().currentProject().getId(),
498             CmsResource.STATE_NEW,
499             timestamp,
500             cms.getRequestContext().currentUser().getId(),
501             timestamp,
502             cms.getRequestContext().currentUser().getId(),
503             CmsResource.DATE_RELEASED_DEFAULT,
504             CmsResource.DATE_EXPIRED_DEFAULT,
505             1, content.length
506         );
507         
508         cms.importResource(resourcename, resource, content, null);
509         
510         // ensure created resource type
511
assertResourceType(cms, resourcename, CmsResourceTypePlain.getStaticTypeId());
512         // project must be current project
513
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
514         // state must be "new"
515
assertState(cms, resourcename, CmsResource.STATE_NEW);
516         // date last modified
517
assertDateLastModified(cms, resourcename, timestamp);
518         // date created
519
assertDateCreated(cms, resourcename, timestamp);
520         // the user last modified must be the current user
521
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
522         // the content
523
assertContent(cms, resourcename, content);
524         
525         // publish the project
526
cms.unlockProject(cms.getRequestContext().currentProject().getId());
527         cms.publishProject();
528         
529         assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
530     }
531     
532     /**
533      * Test the import resource method.<p>
534      *
535      * @throws Throwable if something goes wrong
536      */

537     public void testImportResourceAgain() throws Throwable JavaDoc {
538
539         CmsObject cms = getCmsObject();
540         echo("Testing to import an existing resource again");
541         
542         String JavaDoc resourcename = "/folder1/test1.html";
543         
544         storeResources(cms, resourcename);
545         long timestamp = System.currentTimeMillis() - 12345678;
546         
547         String JavaDoc contentStr = "Hello this is my NEW AND CHANGED content";
548         byte[] content = contentStr.getBytes();
549
550         // create a new resource
551
CmsResource resource = new CmsResource (
552             CmsUUID.getNullUUID(),
553             CmsUUID.getNullUUID(),
554             resourcename,
555             CmsResourceTypePlain.getStaticTypeId(),
556             false,
557             0,
558             cms.getRequestContext().currentProject().getId(),
559             CmsResource.STATE_NEW,
560             timestamp,
561             cms.getRequestContext().currentUser().getId(),
562             timestamp,
563             cms.getRequestContext().currentUser().getId(),
564             CmsResource.DATE_RELEASED_DEFAULT,
565             CmsResource.DATE_EXPIRED_DEFAULT,
566             1, content.length
567         );
568         
569         cms.importResource(resourcename, resource, content, null);
570         
571         // ensure created resource type
572
assertResourceType(cms, resourcename, CmsResourceTypePlain.getStaticTypeId());
573         // project must be current project
574
assertProject(cms, resourcename, cms.getRequestContext().currentProject());
575         // state must be "new"
576
assertState(cms, resourcename, CmsResource.STATE_CHANGED);
577         // date last modified
578
assertDateLastModified(cms, resourcename, timestamp);
579         // the user last modified must be the current user
580
assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());
581         // now evaluate the filter
582
assertFilter(cms, resourcename, OpenCmsTestResourceFilter.FILTER_CREATE_RESOURCE);
583                 
584         // publish the project
585
cms.unlockProject(cms.getRequestContext().currentProject().getId());
586         cms.publishProject();
587         
588         assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
589     }
590         
591     /**
592      * Test the import of a sibling.<p>
593      *
594      * @throws Throwable if something goes wrong
595      */

596     public void testImportSibling() throws Throwable JavaDoc {
597
598         CmsObject cms = getCmsObject();
599         echo("Testing to import an existing resource as sibling");
600
601         CmsProperty prop1 = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "The title", null);
602         CmsProperty prop2 = new CmsProperty(CmsPropertyDefinition.PROPERTY_DESCRIPTION, "The description", null);
603         CmsProperty prop3 = new CmsProperty(CmsPropertyDefinition.PROPERTY_KEYWORDS, "The keywords", null);
604         
605         List JavaDoc properties = new ArrayList JavaDoc();
606         properties.add(prop1);
607         
608         String JavaDoc siblingname = "/folder1/test1.html";
609         
610         // make sure some non-shared properties are attached to the sibling
611
cms.lockResource(siblingname);
612         cms.writePropertyObjects(siblingname, properties);
613         cms.unlockResource(siblingname);
614         
615         long timestamp = System.currentTimeMillis() - 12345678;
616         
617         String JavaDoc resourcename1 = "/folder2/test1_sib1.html";
618         String JavaDoc resourcename2 = "/folder1/subfolder11/test1_sib2.html";
619         
620         // read the existing resource to create siblings for
621
CmsFile file = cms.readFile(siblingname);
622         byte[] content = file.getContents();
623         
624         assertTrue(file.getLength() > 0);
625         assertTrue(content.length > 0);
626         
627         storeResources(cms, siblingname);
628
629         // create a new resource
630
CmsResource resource;
631
632         // cw: Test changed: must now provide correct content size in resource
633
resource= new CmsResource (
634             file.getStructureId(),
635             file.getResourceId(),
636             resourcename2,
637             CmsResourceTypePlain.getStaticTypeId(),
638             false,
639             0,
640             cms.getRequestContext().currentProject().getId(),
641             CmsResource.STATE_NEW,
642             timestamp,
643             cms.getRequestContext().currentUser().getId(),
644             timestamp,
645             cms.getRequestContext().currentUser().getId(),
646             CmsResource.DATE_RELEASED_DEFAULT,
647             CmsResource.DATE_EXPIRED_DEFAULT,
648             1, content.length
649         );
650         
651         properties.add(prop2);
652         // using null as content must create sibling of existing content
653
cms.importResource(resourcename2, resource, null, properties);
654         
655         // project must be current project
656
assertProject(cms, resourcename2, cms.getRequestContext().currentProject());
657         // resource type
658
assertResourceType(cms, resourcename2, CmsResourceTypePlain.getStaticTypeId());
659         assertResourceType(cms, siblingname, CmsResourceTypePlain.getStaticTypeId());
660         // state
661
assertState(cms, resourcename2, CmsResource.STATE_NEW);
662         assertState(cms, siblingname, CmsResource.STATE_CHANGED);
663         // date last modified
664
assertDateLastModified(cms, resourcename2, file.getDateLastModified());
665         assertDateLastModified(cms, siblingname, file.getDateLastModified());
666         // the user last modified
667
assertUserLastModified(cms, resourcename2, cms.getRequestContext().currentUser());
668         assertUserLastModified(cms, siblingname, cms.getRequestContext().currentUser());
669         // content must be identical to stored content of new resource
670
assertContent(cms, resourcename2, content);
671         assertContent(cms, siblingname, content);
672         // check the sibling count
673
assertSiblingCountIncremented(cms, siblingname, 1);
674
675         // now evaluate the filter
676
OpenCmsTestResourceConfigurableFilter filter =
677             new OpenCmsTestResourceConfigurableFilter(OpenCmsTestResourceFilter.FILTER_CREATE_RESOURCE);
678
679         filter.disableSiblingCountTest();
680         assertFilter(cms, siblingname, filter);
681         
682         String JavaDoc contentStr = "Hello this is my NEW AND CHANGED sibling content";
683         content = contentStr.getBytes();
684         
685         resource= new CmsResource (
686             file.getStructureId(),
687             file.getResourceId(),
688             resourcename1,
689             CmsResourceTypePlain.getStaticTypeId(),
690             false,
691             0,
692             cms.getRequestContext().currentProject().getId(),
693             CmsResource.STATE_NEW,
694             timestamp,
695             cms.getRequestContext().currentUser().getId(),
696             timestamp,
697             cms.getRequestContext().currentUser().getId(),
698             CmsResource.DATE_RELEASED_DEFAULT,
699             CmsResource.DATE_EXPIRED_DEFAULT,
700             1, content.length
701         );
702         
703         properties.add(prop3);
704         // using new content must replace existing content
705
cms.importResource(resourcename1, resource, content, properties);
706                 
707         // project must be current project
708
assertProject(cms, resourcename1, cms.getRequestContext().currentProject());
709         assertProject(cms, resourcename2, cms.getRequestContext().currentProject());
710         // resource type
711
assertResourceType(cms, resourcename1, CmsResourceTypePlain.getStaticTypeId());
712         assertResourceType(cms, resourcename2, CmsResourceTypePlain.getStaticTypeId());
713         assertResourceType(cms, siblingname, CmsResourceTypePlain.getStaticTypeId());
714         // state
715
assertState(cms, resourcename1, CmsResource.STATE_NEW);
716         assertState(cms, resourcename2, CmsResource.STATE_NEW);
717         assertState(cms, siblingname, CmsResource.STATE_CHANGED);
718         // date last modified
719
assertDateLastModified(cms, resourcename1, timestamp);
720         assertDateLastModified(cms, resourcename2, timestamp);
721         assertDateLastModified(cms, siblingname, timestamp);
722         // the user last modified
723
assertUserLastModified(cms, resourcename1, cms.getRequestContext().currentUser());
724         assertUserLastModified(cms, resourcename2, cms.getRequestContext().currentUser());
725         assertUserLastModified(cms, siblingname, cms.getRequestContext().currentUser());
726         // content must be identical to stored content of new resource
727
assertContent(cms, resourcename1, content);
728         assertContent(cms, resourcename2, content);
729         assertContent(cms, siblingname, content);
730         // check the sibling count
731
assertSiblingCountIncremented(cms, siblingname, 2);
732
733         // now evaluate the filter
734
assertFilter(cms, siblingname, filter);
735         
736         // publish the project
737
cms.unlockProject(cms.getRequestContext().currentProject().getId());
738         cms.publishProject();
739         
740         assertState(cms, resourcename1, CmsResource.STATE_UNCHANGED);
741         assertState(cms, resourcename2, CmsResource.STATE_UNCHANGED);
742     }
743 }
744
Popular Tags