1 17 package org.alfresco.repo.version.common; 18 19 import java.io.Serializable ; 20 import java.util.Date ; 21 import java.util.HashMap ; 22 import java.util.Map ; 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 38 public class VersionImplTest extends TestCase 39 { 40 43 private final static String PROP_1 = "prop1"; 44 private final static String PROP_2 = "prop2"; 45 private final static String PROP_3 = "prop3"; 46 private final static String VALUE_1 = "value1"; 47 private final static String VALUE_2 = "value2"; 48 private final static String VALUE_3 = "value3"; 49 private final static String VALUE_DESCRIPTION = "This string describes the version details."; 50 private final static VersionType VERSION_TYPE = VersionType.MINOR; 51 private final static String USER_NAME = "userName"; 52 53 56 private final static String VERSION_1 = "1"; 57 58 61 private VersionImpl version = null; 62 private NodeRef nodeRef = null; 63 private Map <String , Serializable > versionProperties = null; 64 private Date createdDate = new Date (); 65 66 69 protected void setUp() throws Exception 70 { 71 super.setUp(); 72 73 this.nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "testWS"), "testID"); 75 assertNotNull(this.nodeRef); 76 77 this.versionProperties = new HashMap <String , Serializable >(); 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 this.version = new VersionImpl(this.versionProperties, this.nodeRef); 90 assertNotNull(this.version); 91 } 92 93 94 97 public void testGetCreatedDate() 98 { 99 Date createdDate1 = this.version.getCreatedDate(); 100 assertEquals(this.createdDate, createdDate1); 101 } 102 103 106 public void testGetCreator() 107 { 108 assertEquals(USER_NAME, this.version.getCreator()); 109 } 110 111 114 public void testGetVersionLabel() 115 { 116 String versionLabel1 = this.version.getVersionLabel(); 117 assertEquals(VersionImplTest.VERSION_1, versionLabel1); 118 } 119 120 123 public void testGetDescription() 124 { 125 String description = this.version.getDescription(); 126 assertEquals(VALUE_DESCRIPTION, description); 127 } 128 129 132 public void testGetVersionType() 133 { 134 VersionType versionType = this.version.getVersionType(); 135 assertEquals(VERSION_TYPE, versionType); 136 } 137 138 142 public void testGetVersionProperties() 143 { 144 Map <String , Serializable > versionProperties = version.getVersionProperties(); 145 assertNotNull(versionProperties); 146 assertEquals(this.versionProperties.size(), versionProperties.size()); 147 } 148 149 152 public void testGetVersionProperty() 153 { 154 String value1 = (String )version.getVersionProperty(VersionImplTest.PROP_1); 155 assertEquals(value1, VersionImplTest.VALUE_1); 156 157 String value2 = (String )version.getVersionProperty(VersionImplTest.PROP_2); 158 assertEquals(value2, VersionImplTest.VALUE_2); 159 160 String value3 = (String )version.getVersionProperty(VersionImplTest.PROP_3); 161 assertEquals(value3, VersionImplTest.VALUE_3); 162 } 163 164 167 public void testGetNodeRef() 168 { 169 NodeRef nodeRef = this.version.getFrozenStateNodeRef(); 170 assertNotNull(nodeRef); 171 assertEquals(nodeRef.toString(), this.nodeRef.toString()); 172 } 173 174 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 |