KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > version > ContentServiceImplTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.version;
18
19 import org.alfresco.model.ContentModel;
20 import org.alfresco.service.cmr.repository.ContentReader;
21 import org.alfresco.service.cmr.repository.ContentService;
22 import org.alfresco.service.cmr.repository.ContentWriter;
23 import org.alfresco.service.cmr.repository.NodeRef;
24 import org.alfresco.service.cmr.version.Version;
25
26 /**
27  * Tests for retrieving frozen content from a verioned node
28  *
29  * @author Roy Wetherall
30  */

31 public class ContentServiceImplTest extends BaseVersionStoreTest
32 {
33     /**
34      * Test content data
35      */

36     private final static String JavaDoc UPDATED_CONTENT = "This content has been updated with a new value.";
37     
38     /**
39      * The version content store
40      */

41     private ContentService contentService;
42     
43     /**
44      * Called during the transaction setup
45      */

46     protected void onSetUpInTransaction() throws Exception JavaDoc
47     {
48         super.onSetUpInTransaction();
49         
50         // Get the instance of the required content service
51
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
52     }
53     
54     /**
55      * Test getReader
56      */

57     public void testGetReader()
58     {
59         // Create a new versionable node
60
NodeRef versionableNode = createNewVersionableNode();
61         
62         // Create a new version
63
Version version = createVersion(versionableNode, this.versionProperties);
64         NodeRef versionNodeRef = version.getFrozenStateNodeRef();
65         
66         // Get the content reader for the frozen node
67
ContentReader contentReader = this.contentService.getReader(versionNodeRef, ContentModel.PROP_CONTENT);
68         assertNotNull(contentReader);
69         assertEquals(TEST_CONTENT, contentReader.getContentString());
70         
71         // Now update the content and verison again
72
ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);
73         assertNotNull(contentWriter);
74         contentWriter.putContent(UPDATED_CONTENT);
75         Version version2 = createVersion(versionableNode, this.versionProperties);
76         NodeRef version2NodeRef = version2.getFrozenStateNodeRef();
77         
78         // Get the content reader for the new verisoned content
79
ContentReader contentReader2 = this.contentService.getReader(version2NodeRef, ContentModel.PROP_CONTENT);
80         assertNotNull(contentReader2);
81         assertEquals(UPDATED_CONTENT, contentReader2.getContentString());
82     }
83     
84     /**
85      * Test getWriter
86      */

87     public void testGetWriter()
88     {
89         // Create a new versionable node
90
NodeRef versionableNode = createNewVersionableNode();
91         
92         // Create a new version
93
Version version = createVersion(versionableNode, this.versionProperties);
94         
95         // Get writer is not supported by the version content service
96
try
97         {
98             ContentWriter contentWriter = this.contentService.getWriter(
99                     version.getFrozenStateNodeRef(),
100                     ContentModel.PROP_CONTENT,
101                     true);
102             contentWriter.putContent("bobbins");
103             fail("This operation is not supported.");
104         }
105         catch (Exception JavaDoc exception)
106         {
107             // An exception should be raised
108
}
109     }
110 }
111
Popular Tags