1 17 package org.alfresco.repo.dictionary; 18 19 import org.alfresco.model.ContentModel; 20 import org.alfresco.repo.content.MimetypeMap; 21 import org.alfresco.repo.transaction.TransactionUtil; 22 import org.alfresco.service.cmr.coci.CheckOutCheckInService; 23 import org.alfresco.service.cmr.dictionary.DictionaryException; 24 import org.alfresco.service.cmr.dictionary.DictionaryService; 25 import org.alfresco.service.cmr.dictionary.ModelDefinition; 26 import org.alfresco.service.cmr.repository.ContentWriter; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.namespace.NamespaceService; 29 import org.alfresco.service.namespace.QName; 30 import org.alfresco.util.BaseAlfrescoSpringTest; 31 import org.alfresco.util.PropertyMap; 32 33 38 public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest 39 { 40 41 private static final QName TEST_MODEL_ONE = QName.createQName("{http://www.alfresco.org/test/testmodel1/1.0}testModelOne"); 42 43 44 public static final String MODEL_ONE_XML = 45 "<model name='test1:testModelOne' xmlns='http://www.alfresco.org/model/dictionary/1.0'>" + 46 47 " <description>Test model one</description>" + 48 " <author>Alfresco</author>" + 49 " <published>2005-05-30</published>" + 50 " <version>1.0</version>" + 51 52 " <imports>" + 53 " <import uri='http://www.alfresco.org/model/dictionary/1.0' prefix='d'/>" + 54 " </imports>" + 55 56 " <namespaces>" + 57 " <namespace uri='http://www.alfresco.org/test/testmodel1/1.0' prefix='test1'/>" + 58 " </namespaces>" + 59 60 " <types>" + 61 62 " <type name='test1:base'>" + 63 " <title>Base</title>" + 64 " <description>The Base Type</description>" + 65 " <properties>" + 66 " <property name='test1:prop1'>" + 67 " <type>d:text</type>" + 68 " </property>" + 69 " </properties>" + 70 " </type>" + 71 72 " </types>" + 73 74 "</model>"; 75 76 public static final String MODEL_ONE_MODIFIED_XML = 77 "<model name='test1:testModelOne' xmlns='http://www.alfresco.org/model/dictionary/1.0'>" + 78 79 " <description>Test model one (updated)</description>" + 80 " <author>Alfresco</author>" + 81 " <published>2005-05-30</published>" + 82 " <version>1.1</version>" + 83 84 " <imports>" + 85 " <import uri='http://www.alfresco.org/model/dictionary/1.0' prefix='d'/>" + 86 " </imports>" + 87 88 " <namespaces>" + 89 " <namespace uri='http://www.alfresco.org/test/testmodel1/1.0' prefix='test1'/>" + 90 " </namespaces>" + 91 92 " <types>" + 93 94 " <type name='test1:base'>" + 95 " <title>Base</title>" + 96 " <description>The Base Type</description>" + 97 " <properties>" + 98 " <property name='test1:prop1'>" + 99 " <type>d:text</type>" + 100 " </property>" + 101 " <property name='test1:prop2'>" + 102 " <type>d:text</type>" + 103 " </property>" + 104 " </properties>" + 105 " </type>" + 106 107 " </types>" + 108 109 "</model>"; 110 111 112 private DictionaryService dictionaryService; 113 private NamespaceService namespaceService; 114 private CheckOutCheckInService cociService; 115 private DictionaryDAO dictionaryDAO; 116 117 120 @Override 121 protected void onSetUpInTransaction() throws Exception 122 { 123 124 super.onSetUpInTransaction(); 125 126 this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService"); 128 this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService"); 129 this.cociService = (CheckOutCheckInService)this.applicationContext.getBean("checkOutCheckInService"); 130 this.dictionaryDAO = (DictionaryDAO)this.applicationContext.getBean("dictionaryDAO"); 131 132 } 133 134 137 public void testCreateAndUpdateDictionaryModelNodeContent() 138 { 139 try 140 { 141 this.dictionaryService.getModel(TEST_MODEL_ONE); 143 fail("This model has not yet been loaded into the dictionary service"); 144 } 145 catch (DictionaryException exception) 146 { 147 } 149 150 String uri = this.namespaceService.getNamespaceURI("test1"); 152 assertNull(uri); 153 154 PropertyMap properties = new PropertyMap(1); 156 properties.put(ContentModel.PROP_MODEL_ACTIVE, true); 157 final NodeRef modelNode = this.nodeService.createNode( 158 this.rootNodeRef, 159 ContentModel.ASSOC_CHILDREN, 160 QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"), 161 ContentModel.TYPE_DICTIONARY_MODEL, 162 properties).getChildRef(); 163 assertNotNull(modelNode); 164 165 ContentWriter contentWriter = this.contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true); 167 contentWriter.setEncoding("UTF-8"); 168 contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML); 169 contentWriter.putContent(MODEL_ONE_XML); 170 171 setComplete(); 173 endTransaction(); 174 175 final NodeRef workingCopy = TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<NodeRef>() 176 { 177 public NodeRef doWork() throws Exception 178 { 179 assertEquals(QName.createQName("{http://www.alfresco.org/test/testmodel1/1.0}testModelOne"), 181 DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_NAME)); 182 assertEquals("Test model one", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_DESCRIPTION)); 183 assertEquals("Alfresco", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_AUTHOR)); 184 assertEquals("1.0", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_VERSION)); 186 187 ModelDefinition modelDefinition2 = DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE); 189 assertNotNull(modelDefinition2); 190 assertEquals("Test model one", modelDefinition2.getDescription()); 191 192 String uri2 = DictionaryModelTypeTest.this.namespaceService.getNamespaceURI("test1"); 194 assertEquals(uri2, "http://www.alfresco.org/test/testmodel1/1.0"); 195 196 NodeRef workingCopy = DictionaryModelTypeTest.this.cociService.checkout(modelNode); 198 ContentWriter contentWriter2 = DictionaryModelTypeTest.this.contentService.getWriter(workingCopy, ContentModel.PROP_CONTENT, true); 199 contentWriter2.putContent(MODEL_ONE_MODIFIED_XML); 200 201 return workingCopy; 202 } 203 }); 204 205 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object >() 206 { 207 public Object doWork() throws Exception 208 { 209 assertEquals("1.0", DictionaryModelTypeTest.this.nodeService.getProperty(workingCopy, ContentModel.PROP_MODEL_VERSION)); 211 212 DictionaryModelTypeTest.this.cociService.checkin(workingCopy, null); 214 return null; 215 } 216 }); 217 218 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object >() 219 { 220 public Object doWork() throws Exception 221 { 222 assertEquals("1.1", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_VERSION)); 224 return null; 225 } 226 }); 227 228 } 229 230 public void testIsActiveFlagAndDelete() 231 { 232 this.dictionaryDAO.removeModel(TEST_MODEL_ONE); 233 234 try 235 { 236 this.dictionaryService.getModel(TEST_MODEL_ONE); 238 fail("This model has not yet been loaded into the dictionary service"); 239 } 240 catch (DictionaryException exception) 241 { 242 } 244 245 PropertyMap properties = new PropertyMap(1); 247 final NodeRef modelNode = this.nodeService.createNode( 248 this.rootNodeRef, 249 ContentModel.ASSOC_CHILDREN, 250 QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"), 251 ContentModel.TYPE_DICTIONARY_MODEL, 252 properties).getChildRef(); 253 assertNotNull(modelNode); 254 255 ContentWriter contentWriter = this.contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true); 257 contentWriter.setEncoding("UTF-8"); 258 contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML); 259 contentWriter.putContent(MODEL_ONE_XML); 260 261 setComplete(); 263 endTransaction(); 264 265 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object >() 266 { 267 public Object doWork() throws Exception 268 { 269 try 271 { 272 DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE); 274 fail("This model has not yet been loaded into the dictionary service"); 275 } 276 catch (DictionaryException exception) 277 { 278 } 280 281 DictionaryModelTypeTest.this.nodeService.setProperty(modelNode, ContentModel.PROP_MODEL_ACTIVE, true); 283 284 return null; 285 } 286 }); 287 288 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object >() 289 { 290 public Object doWork() throws Exception 291 { 292 assertNotNull(DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE)); 294 295 DictionaryModelTypeTest.this.nodeService.setProperty(modelNode, ContentModel.PROP_MODEL_ACTIVE, false); 297 298 return null; 299 } 300 }); 301 302 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object >() 303 { 304 public Object doWork() throws Exception 305 { 306 try 308 { 309 DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE); 311 fail("This model has not yet been loaded into the dictionary service"); 312 } 313 catch (DictionaryException exception) 314 { 315 } 317 318 DictionaryModelTypeTest.this.nodeService.setProperty(modelNode, ContentModel.PROP_MODEL_ACTIVE, true); 320 321 return null; 322 } 323 }); 324 325 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object >() 326 { 327 public Object doWork() throws Exception 328 { 329 assertNotNull(DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE)); 331 332 DictionaryModelTypeTest.this.nodeService.deleteNode(modelNode); 333 334 try 336 { 337 DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE); 339 fail("This model has not yet been loaded into the dictionary service"); 340 } 341 catch (DictionaryException exception) 342 { 343 } 345 346 return null; 347 } 348 }); 349 } 350 } 351 | Popular Tags |