KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > version > common > VersionImplTest


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.common;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Date JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.alfresco.repo.version.VersionModel;
25 import org.alfresco.service.cmr.repository.NodeRef;
26 import org.alfresco.service.cmr.repository.StoreRef;
27 import org.alfresco.service.cmr.version.Version;
28 import org.alfresco.service.cmr.version.VersionServiceException;
29 import org.alfresco.service.cmr.version.VersionType;
30
31 import junit.framework.TestCase;
32
33 /**
34  * VersionImpl Unit Test
35  *
36  * @author Roy Wetherall
37  */

38 public class VersionImplTest extends TestCase
39 {
40     /**
41      * Property names and values
42      */

43     private final static String JavaDoc PROP_1 = "prop1";
44     private final static String JavaDoc PROP_2 = "prop2";
45     private final static String JavaDoc PROP_3 = "prop3";
46     private final static String JavaDoc VALUE_1 = "value1";
47     private final static String JavaDoc VALUE_2 = "value2";
48     private final static String JavaDoc VALUE_3 = "value3";
49     private final static String JavaDoc VALUE_DESCRIPTION = "This string describes the version details.";
50     private final static VersionType VERSION_TYPE = VersionType.MINOR;
51     private final static String JavaDoc USER_NAME = "userName";
52     
53     /**
54      * Version labels
55      */

56     private final static String JavaDoc VERSION_1 = "1";
57     
58     /**
59      * Data used during tests
60      */

61     private VersionImpl version = null;
62     private NodeRef nodeRef = null;
63     private Map JavaDoc<String JavaDoc, Serializable JavaDoc> versionProperties = null;
64     private Date JavaDoc createdDate = new Date JavaDoc();
65
66     /**
67      * Test case set up
68      */

69     protected void setUp() throws Exception JavaDoc
70     {
71         super.setUp();
72         
73         // Create the node reference
74
this.nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "testWS"), "testID");
75         assertNotNull(this.nodeRef);
76         
77         // Create the version property map
78
this.versionProperties = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>();
79         this.versionProperties.put(VersionModel.PROP_VERSION_LABEL, VERSION_1);
80         this.versionProperties.put(VersionModel.PROP_CREATED_DATE, this.createdDate);
81         this.versionProperties.put(VersionModel.PROP_CREATOR, USER_NAME);
82         this.versionProperties.put(Version.PROP_DESCRIPTION, VALUE_DESCRIPTION);
83         this.versionProperties.put(VersionModel.PROP_VERSION_TYPE, VERSION_TYPE);
84         this.versionProperties.put(PROP_1, VALUE_1);
85         this.versionProperties.put(PROP_2, VALUE_2);
86         this.versionProperties.put(PROP_3, VALUE_3);
87         
88         // Create the root version
89
this.version = new VersionImpl(this.versionProperties, this.nodeRef);
90         assertNotNull(this.version);
91     }
92     
93
94     /**
95      * Test getCreatedDate()
96      */

97     public void testGetCreatedDate()
98     {
99         Date JavaDoc createdDate1 = this.version.getCreatedDate();
100         assertEquals(this.createdDate, createdDate1);
101     }
102     
103     /**
104      * Test getCreator
105      */

106     public void testGetCreator()
107     {
108         assertEquals(USER_NAME, this.version.getCreator());
109     }
110
111     /**
112      * Test getVersionLabel()
113      */

114     public void testGetVersionLabel()
115     {
116         String JavaDoc versionLabel1 = this.version.getVersionLabel();
117         assertEquals(VersionImplTest.VERSION_1, versionLabel1);
118     }
119     
120     /**
121      * Test getDescription
122      */

123     public void testGetDescription()
124     {
125         String JavaDoc description = this.version.getDescription();
126         assertEquals(VALUE_DESCRIPTION, description);
127     }
128     
129     /**
130      * Test getVersionType
131      */

132     public void testGetVersionType()
133     {
134         VersionType versionType = this.version.getVersionType();
135         assertEquals(VERSION_TYPE, versionType);
136     }
137     
138     /**
139      * Test getVersionProperties
140      *
141      */

142     public void testGetVersionProperties()
143     {
144         Map JavaDoc<String JavaDoc, Serializable JavaDoc> versionProperties = version.getVersionProperties();
145         assertNotNull(versionProperties);
146         assertEquals(this.versionProperties.size(), versionProperties.size());
147     }
148
149     /**
150      * Test getVersionProperty
151      */

152     public void testGetVersionProperty()
153     {
154         String JavaDoc value1 = (String JavaDoc)version.getVersionProperty(VersionImplTest.PROP_1);
155         assertEquals(value1, VersionImplTest.VALUE_1);
156         
157         String JavaDoc value2 = (String JavaDoc)version.getVersionProperty(VersionImplTest.PROP_2);
158         assertEquals(value2, VersionImplTest.VALUE_2);
159         
160         String JavaDoc value3 = (String JavaDoc)version.getVersionProperty(VersionImplTest.PROP_3);
161         assertEquals(value3, VersionImplTest.VALUE_3);
162     }
163
164     /**
165      * Test getNodeRef()
166      */

167     public void testGetNodeRef()
168     {
169         NodeRef nodeRef = this.version.getFrozenStateNodeRef();
170         assertNotNull(nodeRef);
171         assertEquals(nodeRef.toString(), this.nodeRef.toString());
172     }
173     
174     /**
175      * Exception case - no node ref supplied when creating a verison
176      */

177     public void testNoNodeRefOnVersionCreate()
178     {
179         try
180         {
181             new VersionImpl(this.versionProperties, null);
182             fail("It is invalid to create a version object without a node ref specified.");
183         }
184         catch (VersionServiceException exception)
185         {
186         }
187     }
188 }
189
Popular Tags