1 17 package org.alfresco.repo.version; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 import org.alfresco.model.ContentModel; 27 import org.alfresco.service.cmr.repository.AssociationRef; 28 import org.alfresco.service.cmr.repository.ChildAssociationRef; 29 import org.alfresco.service.cmr.repository.NodeRef; 30 import org.alfresco.service.cmr.repository.NodeService; 31 import org.alfresco.service.cmr.repository.Path; 32 import org.alfresco.service.cmr.version.Version; 33 import org.alfresco.service.namespace.QName; 34 import org.alfresco.service.namespace.RegexQNamePattern; 35 import org.alfresco.util.debug.NodeStoreInspector; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 42 public class NodeServiceImplTest extends BaseVersionStoreTest 43 { 44 private static Log logger = LogFactory.getLog(NodeServiceImplTest.class); 45 46 49 protected NodeService lightWeightVersionStoreNodeService = null; 50 51 54 private final static String MSG_ERR = 55 "This operation is not supported by a version store implementation of the node service."; 56 57 60 private NodeRef dummyNodeRef = null; 61 private QName dummyQName = null; 62 63 66 protected void onSetUpInTransaction() throws Exception 67 { 68 super.onSetUpInTransaction(); 69 70 this.lightWeightVersionStoreNodeService = (NodeService)this.applicationContext.getBean("versionNodeService"); 72 73 this.dummyNodeRef = new NodeRef( 75 this.versionService.getVersionStoreReference(), 76 "dummy"); 77 this.dummyQName = QName.createQName("{dummy}dummy"); 78 } 79 80 83 public void testGetType() 84 { 85 NodeRef versionableNode = createNewVersionableNode(); 87 88 Version version = createVersion(versionableNode, this.versionProperties); 90 91 QName versionedType = this.lightWeightVersionStoreNodeService.getType(version.getFrozenStateNodeRef()); 93 assertNotNull(versionedType); 94 assertEquals(this.dbNodeService.getType(versionableNode), versionedType); 95 } 96 97 100 public void testGetProperties() 101 { 102 NodeRef versionableNode = createNewVersionableNode(); 104 105 Map <QName, Serializable > origProps = this.dbNodeService.getProperties(versionableNode); 107 108 Version version = createVersion(versionableNode, this.versionProperties); 110 111 Map <QName, Serializable > versionedProperties = this.lightWeightVersionStoreNodeService.getProperties(version.getFrozenStateNodeRef()); 113 for (QName key : origProps.keySet()) 115 { 116 assertTrue(versionedProperties.containsKey(key)); 117 assertEquals(origProps.get(key), versionedProperties.get(key)); 118 } 119 120 } 122 123 126 public void testGetProperty() 127 { 128 NodeRef versionableNode = createNewVersionableNode(); 130 131 Version version = createVersion(versionableNode, this.versionProperties); 133 134 Serializable value1 = this.lightWeightVersionStoreNodeService.getProperty( 136 version.getFrozenStateNodeRef(), 137 PROP_1); 138 assertEquals(VALUE_1, value1); 139 140 Collection <String > multiValue = (Collection <String >)this.lightWeightVersionStoreNodeService.getProperty(version.getFrozenStateNodeRef(), MULTI_PROP); 142 assertNotNull(multiValue); 143 assertEquals(2, multiValue.size()); 144 String [] array = multiValue.toArray(new String [multiValue.size()]); 145 assertEquals(MULTI_VALUE_1, array[0]); 146 assertEquals(MULTI_VALUE_2, array[1]); 147 } 148 149 152 public void testGetChildAssocs() 153 { 154 if (logger.isDebugEnabled()) 155 { 156 System.out.println(NodeStoreInspector.dumpNodeStore( 158 this.dbNodeService, 159 this.versionService.getVersionStoreReference()) + "\n\n"); 160 logger.debug(""); 161 } 162 163 NodeRef versionableNode = createNewVersionableNode(); 165 Collection <ChildAssociationRef> origionalChildren = this.dbNodeService.getChildAssocs(versionableNode); 166 assertNotNull(origionalChildren); 167 168 HashMap <String , ChildAssociationRef> origionalChildAssocRefs = new HashMap <String , ChildAssociationRef>(); 170 for (ChildAssociationRef ref : origionalChildren) 171 { 172 origionalChildAssocRefs.put(ref.getChildRef().getId(), ref); 173 } 174 175 Version version = createVersion(versionableNode, this.versionProperties); 177 178 if (logger.isDebugEnabled()) 179 { 180 System.out.println(NodeStoreInspector.dumpNodeStore( 182 this.dbNodeService, 183 this.versionService.getVersionStoreReference())); 184 } 185 186 Collection <ChildAssociationRef> versionedChildren = this.lightWeightVersionStoreNodeService.getChildAssocs(version.getFrozenStateNodeRef()); 188 assertNotNull(versionedChildren); 189 assertEquals(origionalChildren.size(), versionedChildren.size()); 190 191 for (ChildAssociationRef versionedChildRef : versionedChildren) 192 { 193 ChildAssociationRef origChildAssocRef = origionalChildAssocRefs.get(versionedChildRef.getChildRef().getId()); 194 assertNotNull(origChildAssocRef); 195 196 assertEquals( 197 origChildAssocRef.getChildRef(), 198 versionedChildRef.getChildRef()); 199 assertEquals( 200 origChildAssocRef.isPrimary(), 201 versionedChildRef.isPrimary()); 202 assertEquals( 203 origChildAssocRef.getNthSibling(), 204 versionedChildRef.getNthSibling()); 205 } 206 } 207 208 211 public void testGetAssociationTargets() 212 { 213 NodeRef versionableNode = createNewVersionableNode(); 215 216 List <AssociationRef> origAssocs = this.dbNodeService.getTargetAssocs( 218 versionableNode, 219 RegexQNamePattern.MATCH_ALL); 220 221 Version version = createVersion(versionableNode, this.versionProperties); 223 224 List <AssociationRef> assocs = this.lightWeightVersionStoreNodeService.getTargetAssocs( 225 version.getFrozenStateNodeRef(), 226 RegexQNamePattern.MATCH_ALL); 227 assertNotNull(assocs); 228 assertEquals(origAssocs.size(), assocs.size()); 229 } 230 231 234 public void testHasAspect() 235 { 236 NodeRef versionableNode = createNewVersionableNode(); 238 239 Version version = createVersion(versionableNode, this.versionProperties); 241 242 boolean test1 = this.lightWeightVersionStoreNodeService.hasAspect( 243 version.getFrozenStateNodeRef(), 244 ContentModel.ASPECT_UIFACETS); 245 assertFalse(test1); 246 247 boolean test2 = this.lightWeightVersionStoreNodeService.hasAspect( 248 version.getFrozenStateNodeRef(), 249 ContentModel.ASPECT_VERSIONABLE); 250 assertTrue(test2); 251 } 252 253 256 public void testGetAspects() 257 { 258 NodeRef versionableNode = createNewVersionableNode(); 260 Set <QName> origAspects = this.dbNodeService.getAspects(versionableNode); 261 262 Version version = createVersion(versionableNode, this.versionProperties); 264 265 Set <QName> aspects = this.lightWeightVersionStoreNodeService.getAspects(version.getFrozenStateNodeRef()); 266 assertEquals(origAspects.size(), aspects.size()); 267 268 } 270 271 274 public void testGetParentAssocs() 275 { 276 NodeRef versionableNode = createNewVersionableNode(); 278 279 Version version = createVersion(versionableNode, this.versionProperties); 281 NodeRef nodeRef = version.getFrozenStateNodeRef(); 282 283 List <ChildAssociationRef> results = this.lightWeightVersionStoreNodeService.getParentAssocs(nodeRef); 284 assertNotNull(results); 285 assertEquals(1, results.size()); 286 ChildAssociationRef childAssoc = results.get(0); 287 assertEquals(nodeRef, childAssoc.getChildRef()); 288 NodeRef versionStoreRoot = this.dbNodeService.getRootNode(this.versionService.getVersionStoreReference()); 289 assertEquals(versionStoreRoot, childAssoc.getParentRef()); 290 } 291 292 295 public void testGetPrimaryParent() 296 { 297 NodeRef versionableNode = createNewVersionableNode(); 299 300 Version version = createVersion(versionableNode, this.versionProperties); 302 NodeRef nodeRef = version.getFrozenStateNodeRef(); 303 304 ChildAssociationRef childAssoc = this.lightWeightVersionStoreNodeService.getPrimaryParent(nodeRef); 305 assertNotNull(childAssoc); 306 assertEquals(nodeRef, childAssoc.getChildRef()); 307 NodeRef versionStoreRoot = this.dbNodeService.getRootNode(this.versionService.getVersionStoreReference()); 308 assertEquals(versionStoreRoot, childAssoc.getParentRef()); 309 } 310 311 315 316 319 public void testCreateNode() 320 { 321 try 322 { 323 this.lightWeightVersionStoreNodeService.createNode( 324 dummyNodeRef, 325 null, 326 dummyQName, 327 ContentModel.TYPE_CONTENT); 328 fail("This operation is not supported."); 329 } 330 catch (UnsupportedOperationException exception) 331 { 332 if (exception.getMessage() != MSG_ERR) 333 { 334 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 335 } 336 } 337 } 338 339 342 public void testAddAspect() 343 { 344 try 345 { 346 this.lightWeightVersionStoreNodeService.addAspect( 347 dummyNodeRef, 348 TEST_ASPECT_QNAME, 349 null); 350 fail("This operation is not supported."); 351 } 352 catch (UnsupportedOperationException exception) 353 { 354 if (exception.getMessage() != MSG_ERR) 355 { 356 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 357 } 358 } 359 } 360 361 364 public void testRemoveAspect() 365 { 366 try 367 { 368 this.lightWeightVersionStoreNodeService.removeAspect( 369 dummyNodeRef, 370 TEST_ASPECT_QNAME); 371 fail("This operation is not supported."); 372 } 373 catch (UnsupportedOperationException exception) 374 { 375 if (exception.getMessage() != MSG_ERR) 376 { 377 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 378 } 379 } 380 } 381 382 385 public void testDeleteNode() 386 { 387 try 388 { 389 this.lightWeightVersionStoreNodeService.deleteNode(this.dummyNodeRef); 390 fail("This operation is not supported."); 391 } 392 catch (UnsupportedOperationException exception) 393 { 394 if (exception.getMessage() != MSG_ERR) 395 { 396 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 397 } 398 } 399 } 400 401 404 public void testAddChild() 405 { 406 try 407 { 408 this.lightWeightVersionStoreNodeService.addChild( 409 this.dummyNodeRef, 410 this.dummyNodeRef, 411 this.dummyQName, 412 this.dummyQName); 413 fail("This operation is not supported."); 414 } 415 catch (UnsupportedOperationException exception) 416 { 417 if (exception.getMessage() != MSG_ERR) 418 { 419 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 420 } 421 } 422 } 423 424 427 public void testRemoveChild() 428 { 429 try 430 { 431 this.lightWeightVersionStoreNodeService.removeChild( 432 this.dummyNodeRef, 433 this.dummyNodeRef); 434 fail("This operation is not supported."); 435 } 436 catch (UnsupportedOperationException exception) 437 { 438 if (exception.getMessage() != MSG_ERR) 439 { 440 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 441 } 442 } 443 } 444 445 448 public void testSetProperties() 449 { 450 try 451 { 452 this.lightWeightVersionStoreNodeService.setProperties( 453 this.dummyNodeRef, 454 new HashMap <QName, Serializable >()); 455 fail("This operation is not supported."); 456 } 457 catch (UnsupportedOperationException exception) 458 { 459 if (exception.getMessage() != MSG_ERR) 460 { 461 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 462 } 463 } 464 } 465 466 469 public void testSetProperty() 470 { 471 try 472 { 473 this.lightWeightVersionStoreNodeService.setProperty( 474 this.dummyNodeRef, 475 this.dummyQName, 476 "dummy"); 477 fail("This operation is not supported."); 478 } 479 catch (UnsupportedOperationException exception) 480 { 481 if (exception.getMessage() != MSG_ERR) 482 { 483 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 484 } 485 } 486 } 487 488 491 public void testCreateAssociation() 492 { 493 try 494 { 495 this.lightWeightVersionStoreNodeService.createAssociation( 496 this.dummyNodeRef, 497 this.dummyNodeRef, 498 this.dummyQName); 499 fail("This operation is not supported."); 500 } 501 catch (UnsupportedOperationException exception) 502 { 503 if (exception.getMessage() != MSG_ERR) 504 { 505 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 506 } 507 } 508 } 509 510 513 public void testRemoveAssociation() 514 { 515 try 516 { 517 this.lightWeightVersionStoreNodeService.removeAssociation( 518 this.dummyNodeRef, 519 this.dummyNodeRef, 520 this.dummyQName); 521 fail("This operation is not supported."); 522 } 523 catch (UnsupportedOperationException exception) 524 { 525 if (exception.getMessage() != MSG_ERR) 526 { 527 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 528 } 529 } 530 } 531 532 535 public void testGetAssociationSources() 536 { 537 try 538 { 539 this.lightWeightVersionStoreNodeService.getSourceAssocs( 540 this.dummyNodeRef, 541 this.dummyQName); 542 fail("This operation is not supported."); 543 } 544 catch (UnsupportedOperationException exception) 545 { 546 if (exception.getMessage() != MSG_ERR) 547 { 548 fail("Unexpected exception raised during method excution: " + exception.getMessage()); 549 } 550 } 551 } 552 553 556 public void testGetPath() 557 { 558 Path path = this.lightWeightVersionStoreNodeService.getPath(this.dummyNodeRef); 559 } 560 561 564 public void testGetPaths() 565 { 566 List <Path> paths = this.lightWeightVersionStoreNodeService.getPaths(this.dummyNodeRef, false); 567 } 568 } 569 | Popular Tags |