1 17 package org.alfresco.repo.copy; 18 19 import java.io.Serializable ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.alfresco.model.ContentModel; 25 import org.alfresco.repo.action.evaluator.NoConditionEvaluator; 26 import org.alfresco.repo.action.executer.AddFeaturesActionExecuter; 27 import org.alfresco.repo.action.executer.CopyActionExecuter; 28 import org.alfresco.repo.action.executer.MoveActionExecuter; 29 import org.alfresco.repo.dictionary.DictionaryDAO; 30 import org.alfresco.repo.dictionary.M2Aspect; 31 import org.alfresco.repo.dictionary.M2Association; 32 import org.alfresco.repo.dictionary.M2ChildAssociation; 33 import org.alfresco.repo.dictionary.M2Model; 34 import org.alfresco.repo.dictionary.M2Property; 35 import org.alfresco.repo.dictionary.M2Type; 36 import org.alfresco.repo.rule.RuleModel; 37 import org.alfresco.repo.security.authentication.AuthenticationComponent; 38 import org.alfresco.service.cmr.action.Action; 39 import org.alfresco.service.cmr.action.ActionCondition; 40 import org.alfresco.service.cmr.action.ActionService; 41 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 42 import org.alfresco.service.cmr.repository.AssociationRef; 43 import org.alfresco.service.cmr.repository.ChildAssociationRef; 44 import org.alfresco.service.cmr.repository.ContentData; 45 import org.alfresco.service.cmr.repository.ContentReader; 46 import org.alfresco.service.cmr.repository.ContentService; 47 import org.alfresco.service.cmr.repository.ContentWriter; 48 import org.alfresco.service.cmr.repository.CopyService; 49 import org.alfresco.service.cmr.repository.NodeRef; 50 import org.alfresco.service.cmr.repository.NodeService; 51 import org.alfresco.service.cmr.repository.StoreRef; 52 import org.alfresco.service.cmr.rule.Rule; 53 import org.alfresco.service.cmr.rule.RuleService; 54 import org.alfresco.service.cmr.rule.RuleType; 55 import org.alfresco.service.namespace.NamespaceService; 56 import org.alfresco.service.namespace.QName; 57 import org.alfresco.service.namespace.RegexQNamePattern; 58 import org.alfresco.util.BaseSpringTest; 59 60 65 public class CopyServiceImplTest extends BaseSpringTest 66 { 67 70 private NodeService nodeService; 71 private CopyService copyService; 72 private DictionaryDAO dictionaryDAO; 73 private ContentService contentService; 74 private RuleService ruleService; 75 private ActionService actionService; 76 private AuthenticationComponent authenticationComponent; 77 78 81 private StoreRef storeRef; 82 private NodeRef sourceNodeRef; 83 private NodeRef rootNodeRef; 84 private NodeRef targetNodeRef; 85 private NodeRef nonPrimaryChildNodeRef; 86 private NodeRef childNodeRef; 87 private NodeRef destinationNodeRef; 88 89 92 private static final String TEST_TYPE_NAMESPACE = "testTypeNamespaceURI"; 93 private static final QName TEST_TYPE_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testType"); 94 private static final QName PROP1_QNAME_MANDATORY = QName.createQName(TEST_TYPE_NAMESPACE, "prop1Mandatory"); 95 private static final QName PROP2_QNAME_OPTIONAL = QName.createQName(TEST_TYPE_NAMESPACE, "prop2Optional"); 96 97 private static final QName TEST_ASPECT_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testAspect"); 98 private static final QName PROP3_QNAME_MANDATORY = QName.createQName(TEST_TYPE_NAMESPACE, "prop3Mandatory"); 99 private static final QName PROP4_QNAME_OPTIONAL = QName.createQName(TEST_TYPE_NAMESPACE, "prop4Optional"); 100 101 private static final QName PROP_QNAME_MY_NODE_REF = QName.createQName(TEST_TYPE_NAMESPACE, "myNodeRef"); 102 private static final QName PROP_QNAME_MY_ANY = QName.createQName(TEST_TYPE_NAMESPACE, "myAny"); 103 104 private static final QName TEST_MANDATORY_ASPECT_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testMandatoryAspect"); 105 private static final QName PROP5_QNAME_MANDATORY = QName.createQName(TEST_TYPE_NAMESPACE, "prop5Mandatory"); 106 107 private static final String TEST_VALUE_1 = "testValue1"; 108 private static final String TEST_VALUE_2 = "testValue2"; 109 private static final String TEST_VALUE_3 = "testValue3"; 110 111 private static final QName TEST_CHILD_ASSOC_TYPE_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "contains"); 112 private static final QName TEST_CHILD_ASSOC_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testChildAssocName"); 113 private static final QName TEST_ASSOC_TYPE_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testAssocName"); 114 private static final QName TEST_CHILD_ASSOC_QNAME2 = QName.createQName(TEST_TYPE_NAMESPACE, "testChildAssocName2"); 115 116 private static final ContentData CONTENT_DATA_TEXT = new ContentData(null, "text/plain", 0L, "UTF-8"); 117 118 121 private static final String SOME_CONTENT = "This is some content ..."; 122 123 128 public void setDictionaryDAO(DictionaryDAO dictionaryDAO) 129 { 130 this.dictionaryDAO = dictionaryDAO; 131 } 132 133 136 @Override 137 protected void onSetUpInTransaction() 138 throws Exception 139 { 140 this.nodeService = (NodeService)this.applicationContext.getBean("dbNodeService"); 142 this.copyService = (CopyService)this.applicationContext.getBean("copyService"); 143 this.contentService = (ContentService)this.applicationContext.getBean("contentService"); 144 this.ruleService = (RuleService)this.applicationContext.getBean("ruleService"); 145 this.actionService = (ActionService)this.applicationContext.getBean("actionService"); 146 this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent"); 147 148 this.authenticationComponent.setSystemUserAsCurrentUser(); 149 150 createTestModel(); 152 153 this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); 155 this.rootNodeRef = this.nodeService.getRootNode(storeRef); 156 157 ChildAssociationRef childAssocRef = this.nodeService.createNode( 159 rootNodeRef, 160 ContentModel.ASSOC_CHILDREN, 161 QName.createQName("{test}test"), 162 TEST_TYPE_QNAME, 163 createTypePropertyBag()); 164 this.sourceNodeRef = childAssocRef.getChildRef(); 165 166 Map <QName, Serializable > aspectProperties = new HashMap <QName, Serializable >(); 168 aspectProperties.put(PROP3_QNAME_MANDATORY, TEST_VALUE_1); 169 aspectProperties.put(PROP4_QNAME_OPTIONAL, TEST_VALUE_2); 170 171 this.nodeService.addAspect( 173 this.sourceNodeRef, 174 TEST_ASPECT_QNAME, 175 aspectProperties); 176 177 this.nodeService.addAspect(sourceNodeRef, ContentModel.ASPECT_TITLED, null); 178 179 ChildAssociationRef temp3 =this.nodeService.createNode( 181 this.sourceNodeRef, 182 TEST_CHILD_ASSOC_TYPE_QNAME, 183 TEST_CHILD_ASSOC_QNAME, 184 TEST_TYPE_QNAME, 185 createTypePropertyBag()); 186 this.childNodeRef = temp3.getChildRef(); 187 188 ChildAssociationRef temp2 = this.nodeService.createNode( 190 rootNodeRef, 191 ContentModel.ASSOC_CHILDREN, 192 QName.createQName("{test}testNonPrimaryChild"), 193 TEST_TYPE_QNAME, 194 createTypePropertyBag()); 195 196 this.nonPrimaryChildNodeRef = temp2.getChildRef(); 197 this.nodeService.addChild( 198 this.sourceNodeRef, 199 this.nonPrimaryChildNodeRef, 200 TEST_CHILD_ASSOC_TYPE_QNAME, 201 TEST_CHILD_ASSOC_QNAME2); 202 203 ChildAssociationRef temp = this.nodeService.createNode( 205 rootNodeRef, 206 ContentModel.ASSOC_CHILDREN, 207 QName.createQName("{test}testAssoc"), 208 TEST_TYPE_QNAME, 209 createTypePropertyBag()); 210 this.targetNodeRef = temp.getChildRef(); 211 this.nodeService.createAssociation(this.sourceNodeRef, this.targetNodeRef, TEST_ASSOC_TYPE_QNAME); 212 213 Map <QName, Serializable > destinationProps = new HashMap <QName, Serializable >(); 215 destinationProps.put(PROP1_QNAME_MANDATORY, TEST_VALUE_1); 216 destinationProps.put(PROP5_QNAME_MANDATORY, TEST_VALUE_3); 217 destinationProps.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT); 218 ChildAssociationRef temp5 = this.nodeService.createNode( 219 this.rootNodeRef, 220 ContentModel.ASSOC_CHILDREN, 221 QName.createQName("{test}testDestinationNode"), 222 TEST_TYPE_QNAME, 223 destinationProps); 224 this.destinationNodeRef = temp5.getChildRef(); 225 } 226 227 @Override 228 protected void onTearDownInTransaction() throws Exception 229 { 230 authenticationComponent.clearCurrentSecurityContext(); 231 super.onTearDownInTransaction(); 232 } 233 234 239 private Map <QName, Serializable > createTypePropertyBag() 240 { 241 Map <QName, Serializable > result = new HashMap <QName, Serializable >(); 242 result.put(PROP1_QNAME_MANDATORY, TEST_VALUE_1); 243 result.put(PROP2_QNAME_OPTIONAL, TEST_VALUE_2); 244 result.put(PROP5_QNAME_MANDATORY, TEST_VALUE_3); 245 result.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT); 246 return result; 247 } 248 249 252 private void createTestModel() 253 { 254 M2Model model = M2Model.createModel("test:nodeoperations"); 255 model.createNamespace(TEST_TYPE_NAMESPACE, "test"); 256 model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX); 257 model.createImport(NamespaceService.SYSTEM_MODEL_1_0_URI, NamespaceService.SYSTEM_MODEL_PREFIX); 258 model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX); 259 260 M2Type testType = model.createType("test:" + TEST_TYPE_QNAME.getLocalName()); 261 testType.setParentName("cm:" + ContentModel.TYPE_CONTENT.getLocalName()); 262 263 M2Property prop1 = testType.createProperty("test:" + PROP1_QNAME_MANDATORY.getLocalName()); 264 prop1.setMandatory(true); 265 prop1.setType("d:" + DataTypeDefinition.TEXT.getLocalName()); 266 prop1.setMultiValued(false); 267 268 M2Property prop2 = testType.createProperty("test:" + PROP2_QNAME_OPTIONAL.getLocalName()); 269 prop2.setMandatory(false); 270 prop2.setType("d:" + DataTypeDefinition.TEXT.getLocalName()); 271 prop2.setMandatory(false); 272 273 M2Property propNodeRef = testType.createProperty("test:" + PROP_QNAME_MY_NODE_REF.getLocalName()); 274 propNodeRef.setMandatory(false); 275 propNodeRef.setType("d:" + DataTypeDefinition.NODE_REF.getLocalName()); 276 propNodeRef.setMandatory(false); 277 278 M2Property propAnyNodeRef = testType.createProperty("test:" + PROP_QNAME_MY_ANY.getLocalName()); 279 propAnyNodeRef.setMandatory(false); 280 propAnyNodeRef.setType("d:" + DataTypeDefinition.ANY.getLocalName()); 281 propAnyNodeRef.setMandatory(false); 282 283 M2ChildAssociation childAssoc = testType.createChildAssociation("test:" + TEST_CHILD_ASSOC_TYPE_QNAME.getLocalName()); 284 childAssoc.setTargetClassName("sys:base"); 285 childAssoc.setTargetMandatory(false); 286 287 M2Association assoc = testType.createAssociation("test:" + TEST_ASSOC_TYPE_QNAME.getLocalName()); 288 assoc.setTargetClassName("sys:base"); 289 assoc.setTargetMandatory(false); 290 291 M2Aspect testAspect = model.createAspect("test:" + TEST_ASPECT_QNAME.getLocalName()); 292 293 M2Property prop3 = testAspect.createProperty("test:" + PROP3_QNAME_MANDATORY.getLocalName()); 294 prop3.setMandatory(true); 295 prop3.setType("d:" + DataTypeDefinition.TEXT.getLocalName()); 296 prop3.setMultiValued(false); 297 298 M2Property prop4 = testAspect.createProperty("test:" + PROP4_QNAME_OPTIONAL.getLocalName()); 299 prop4.setMandatory(false); 300 prop4.setType("d:" + DataTypeDefinition.TEXT.getLocalName()); 301 prop4.setMultiValued(false); 302 303 M2Aspect testMandatoryAspect = model.createAspect("test:" + TEST_MANDATORY_ASPECT_QNAME.getLocalName()); 304 M2Property prop5 = testMandatoryAspect.createProperty("test:" + PROP5_QNAME_MANDATORY.getLocalName()); 305 prop5.setType("d:" + DataTypeDefinition.TEXT.getLocalName()); 306 prop5.setMandatory(true); 307 308 testType.addMandatoryAspect("test:" + TEST_MANDATORY_ASPECT_QNAME.getLocalName()); 309 310 dictionaryDAO.putModel(model); 311 } 312 313 316 public void testCopyToNewNode() 317 { 318 NodeRef copy = this.copyService.copy( 320 this.sourceNodeRef, 321 this.rootNodeRef, 322 ContentModel.ASSOC_CHILDREN, 323 QName.createQName("{test}copyAssoc")); 324 checkCopiedNode(this.sourceNodeRef, copy, true, true, false); 325 326 NodeRef copy2 = this.copyService.copy( 328 this.sourceNodeRef, 329 this.rootNodeRef, 330 ContentModel.ASSOC_CHILDREN, 331 QName.createQName("{test}copyAssoc"), 332 true); 333 checkCopiedNode(this.sourceNodeRef, copy2, true, true, true); 334 335 NodeRef copyOfCopy = this.copyService.copy( 337 copy, 338 this.rootNodeRef, 339 ContentModel.ASSOC_CHILDREN, 340 QName.createQName("{test}copyOfCopy")); 341 checkCopiedNode(copy, copyOfCopy, true, true, false); 342 343 346 ContentWriter contentWriter = this.contentService.getWriter(this.sourceNodeRef, ContentModel.PROP_CONTENT, true); 348 contentWriter.putContent(SOME_CONTENT); 349 NodeRef copyWithContent = this.copyService.copy( 350 this.sourceNodeRef, 351 this.rootNodeRef, 352 ContentModel.ASSOC_CHILDREN, 353 QName.createQName("{test}copyWithContent")); 354 checkCopiedNode(this.sourceNodeRef, copyWithContent, true, true, false); 355 ContentReader contentReader = this.contentService.getReader(copyWithContent, ContentModel.PROP_CONTENT); 356 assertNotNull(contentReader); 357 assertEquals(SOME_CONTENT, contentReader.getContentString()); 358 359 361 } 364 365 public void testCopyNodeWithRules() 366 { 367 Rule rule = this.ruleService.createRule(RuleType.INBOUND); 369 370 Map <String , Serializable > props = new HashMap <String , Serializable >(1); 371 props.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE); 372 Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME, props); 373 rule.addAction(action); 374 375 ActionCondition actionCondition = this.actionService.createActionCondition(NoConditionEvaluator.NAME); 376 rule.addActionCondition(actionCondition); 377 378 this.ruleService.saveRule(this.sourceNodeRef, rule); 379 380 384 NodeRef copy = this.copyService.copy( 386 this.sourceNodeRef, 387 this.rootNodeRef, 388 ContentModel.ASSOC_CHILDREN, 389 QName.createQName("{test}withRulesCopy"), 390 true); 391 392 395 checkCopiedNode(this.sourceNodeRef, copy, true, true, true); 396 397 401 assertTrue(this.nodeService.hasAspect(copy, RuleModel.ASPECT_RULES)); 402 assertTrue(this.ruleService.hasRules(copy)); 403 assertTrue(this.ruleService.rulesEnabled(copy)); 404 List <Rule> copiedRules = this.ruleService.getRules(copy); 405 assertEquals(1, copiedRules.size()); 406 Rule copiedRule = copiedRules.get(0); 407 assertFalse(rule.getId() == copiedRule.getId()); 408 assertEquals(rule.getAction(0).getActionDefinitionName(), copiedRule.getAction(0).getActionDefinitionName()); 409 410 NodeRef copy2 = this.copyService.copy( 412 this.sourceNodeRef, 413 this.rootNodeRef, 414 ContentModel.ASSOC_CHILDREN, 415 QName.createQName("{test}withRuleCopyNoChildren"), 416 false); 417 418 421 checkCopiedNode(this.sourceNodeRef, copy2, true, true, false); 422 423 427 assertTrue(this.nodeService.hasAspect(copy2, RuleModel.ASPECT_RULES)); 428 assertTrue(this.ruleService.hasRules(copy2)); 429 assertTrue(this.ruleService.rulesEnabled(copy2)); 430 List <Rule> copiedRules2 = this.ruleService.getRules(copy2); 431 assertEquals(1, copiedRules.size()); 432 Rule copiedRule2 = copiedRules2.get(0); 433 assertFalse(rule.getId() == copiedRule2.getId()); 434 assertEquals(rule.getAction(0).getActionDefinitionName(), copiedRule2.getAction(0).getActionDefinitionName()); 435 } 436 437 public void testCopyToExistingNode() 438 { 439 this.copyService.copy(this.sourceNodeRef, this.destinationNodeRef); 441 checkCopiedNode(this.sourceNodeRef, this.destinationNodeRef, false, true, false); 442 443 448 450 } 453 454 457 public void testRecursiveCopy() 458 { 459 NodeRef nodeOne = this.nodeService.createNode( 461 this.rootNodeRef, 462 ContentModel.ASSOC_CHILDREN, 463 ContentModel.ASSOC_CHILDREN, 464 ContentModel.TYPE_CONTAINER).getChildRef(); 465 NodeRef nodeTwo = this.nodeService.createNode( 466 nodeOne, 467 ContentModel.ASSOC_CHILDREN, 468 ContentModel.ASSOC_CHILDREN, 469 ContentModel.TYPE_CONTAINER).getChildRef(); 470 NodeRef nodeThree = this.nodeService.createNode( 471 nodeTwo, 472 ContentModel.ASSOC_CHILDREN, 473 ContentModel.ASSOC_CHILDREN, 474 ContentModel.TYPE_CONTAINER).getChildRef(); 475 476 this.copyService.copy(nodeOne, nodeThree, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, true); 478 479 } 482 483 486 public void testRelativeLinks() 487 { 488 QName nodeOneAssocName = QName.createQName("{test}nodeOne"); 489 QName nodeTwoAssocName = QName.createQName("{test}nodeTwo"); 490 QName nodeThreeAssocName = QName.createQName("{test}nodeThree"); 491 QName nodeFourAssocName = QName.createQName("{test}nodeFour"); 492 493 NodeRef nodeOne = this.nodeService.createNode( 494 this.rootNodeRef, 495 ContentModel.ASSOC_CHILDREN, 496 nodeOneAssocName, 497 TEST_TYPE_QNAME).getChildRef(); 498 NodeRef nodeTwo = this.nodeService.createNode( 499 nodeOne, 500 TEST_CHILD_ASSOC_TYPE_QNAME, 501 nodeTwoAssocName, 502 TEST_TYPE_QNAME).getChildRef(); 503 NodeRef nodeThree = this.nodeService.createNode( 504 nodeTwo, 505 TEST_CHILD_ASSOC_TYPE_QNAME, 506 nodeThreeAssocName, 507 TEST_TYPE_QNAME).getChildRef(); 508 NodeRef nodeFour = this.nodeService.createNode( 509 nodeOne, 510 TEST_CHILD_ASSOC_TYPE_QNAME, 511 nodeFourAssocName, 512 TEST_TYPE_QNAME).getChildRef(); 513 this.nodeService.addChild(nodeFour, nodeThree, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME); 514 this.nodeService.createAssociation(nodeTwo, nodeThree, TEST_ASSOC_TYPE_QNAME); 515 this.nodeService.setProperty(nodeOne, PROP_QNAME_MY_NODE_REF, nodeThree); 516 this.nodeService.setProperty(nodeOne, PROP_QNAME_MY_ANY, nodeThree); 517 518 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 520 params.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, nodeTwo); 521 params.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_TYPE_QNAME); 522 params.put(MoveActionExecuter.PARAM_ASSOC_QNAME, QName.createQName("{test}ruleCopy")); 523 Rule rule = this.ruleService.createRule(RuleType.INBOUND); 524 ActionCondition condition = this.actionService.createActionCondition(NoConditionEvaluator.NAME); 525 rule.addActionCondition(condition); 526 Action action = this.actionService.createAction(CopyActionExecuter.NAME, params); 527 rule.addAction(action); 528 this.ruleService.saveRule(nodeOne, rule); 529 530 NodeRef nodeOneCopy = this.copyService.copy(nodeOne, this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}copiedNodeOne"), true); 532 NodeRef nodeTwoCopy = null; 533 NodeRef nodeThreeCopy = null; 534 NodeRef nodeFourCopy = null; 535 536 539 List <ChildAssociationRef> nodeOneCopyChildren = this.nodeService.getChildAssocs(nodeOneCopy); 540 assertNotNull(nodeOneCopyChildren); 541 assertEquals(3, nodeOneCopyChildren.size()); 542 for (ChildAssociationRef nodeOneCopyChild : nodeOneCopyChildren) 543 { 544 if (nodeOneCopyChild.getQName().equals(nodeTwoAssocName) == true) 545 { 546 nodeTwoCopy = nodeOneCopyChild.getChildRef(); 547 548 List <ChildAssociationRef> nodeTwoCopyChildren = this.nodeService.getChildAssocs(nodeTwoCopy); 549 assertNotNull(nodeTwoCopyChildren); 550 assertEquals(1, nodeTwoCopyChildren.size()); 551 for (ChildAssociationRef nodeTwoCopyChild : nodeTwoCopyChildren) 552 { 553 if (nodeTwoCopyChild.getQName().equals(nodeThreeAssocName) == true) 554 { 555 nodeThreeCopy = nodeTwoCopyChild.getChildRef(); 556 } 557 } 558 } 559 else if (nodeOneCopyChild.getQName().equals(nodeFourAssocName) == true) 560 { 561 nodeFourCopy = nodeOneCopyChild.getChildRef(); 562 } 563 } 564 assertNotNull(nodeTwoCopy); 565 assertNotNull(nodeThreeCopy); 566 assertNotNull(nodeFourCopy); 567 568 List <ChildAssociationRef> children = this.nodeService.getChildAssocs( 570 nodeFourCopy, 571 RegexQNamePattern.MATCH_ALL, 572 TEST_CHILD_ASSOC_QNAME); 573 assertNotNull(children); 574 assertEquals(1, children.size()); 575 ChildAssociationRef child = children.get(0); 576 assertEquals(child.getChildRef(), nodeThreeCopy); 577 578 NodeRef nodeRef = (NodeRef)this.nodeService.getProperty(nodeOneCopy, PROP_QNAME_MY_NODE_REF); 580 assertNotNull(nodeRef); 581 assertEquals(nodeThreeCopy, nodeRef); 582 583 NodeRef anyNodeRef = (NodeRef)this.nodeService.getProperty(nodeOneCopy, PROP_QNAME_MY_ANY); 585 assertNotNull(anyNodeRef); 586 assertEquals(nodeThreeCopy, anyNodeRef); 587 588 List <AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeTwoCopy, TEST_ASSOC_TYPE_QNAME); 590 assertNotNull(assocs); 591 assertEquals(1, assocs.size()); 592 AssociationRef assoc = assocs.get(0); 593 assertEquals(assoc.getTargetRef(), nodeThreeCopy); 594 595 List <Rule> rules = this.ruleService.getRules(nodeOneCopy); 597 assertNotNull(rules); 598 assertEquals(1, rules.size()); 599 Rule copiedRule = rules.get(0); 600 assertNotNull(copiedRule); 601 List <Action> ruleActions = copiedRule.getActions(); 602 assertNotNull(ruleActions); 603 assertEquals(1, ruleActions.size()); 604 Action ruleAction = ruleActions.get(0); 605 NodeRef value = (NodeRef)ruleAction.getParameterValue(MoveActionExecuter.PARAM_DESTINATION_FOLDER); 606 assertNotNull(value); 607 assertEquals(nodeTwoCopy, value); 608 } 609 610 616 private void checkCopiedNode(NodeRef sourceNodeRef, NodeRef destinationNodeRef, boolean newCopy, boolean sameStore, boolean copyChildren) 617 { 618 if (newCopy == true) 619 { 620 if (sameStore == true) 621 { 622 boolean hasCopyAspect = this.nodeService.hasAspect(destinationNodeRef, ContentModel.ASPECT_COPIEDFROM); 624 assertTrue(hasCopyAspect); 625 NodeRef copyNodeRef = (NodeRef)this.nodeService.getProperty(destinationNodeRef, ContentModel.PROP_COPY_REFERENCE); 626 assertNotNull(copyNodeRef); 627 assertEquals(sourceNodeRef, copyNodeRef); 628 } 629 else 630 { 631 assertEquals(sourceNodeRef.getId(), destinationNodeRef.getId()); 633 } 634 } 635 636 boolean hasTestAspect = this.nodeService.hasAspect(destinationNodeRef, TEST_ASPECT_QNAME); 637 assertTrue(hasTestAspect); 638 639 Map <QName, Serializable > destinationProperties = this.nodeService.getProperties(destinationNodeRef); 641 assertNotNull(destinationProperties); 642 String value1 = (String )destinationProperties.get(PROP1_QNAME_MANDATORY); 643 assertNotNull(value1); 644 assertEquals(TEST_VALUE_1, value1); 645 String value2 = (String )destinationProperties.get(PROP2_QNAME_OPTIONAL); 646 assertNotNull(value2); 647 assertEquals(TEST_VALUE_2, value2); 648 String value3 = (String )destinationProperties.get(PROP3_QNAME_MANDATORY); 649 assertNotNull(value3); 650 assertEquals(TEST_VALUE_1, value3); 651 String value4 = (String )destinationProperties.get(PROP4_QNAME_OPTIONAL); 652 assertNotNull(value4); 653 assertEquals(TEST_VALUE_2, value4); 654 655 List <AssociationRef> destinationTargets = this.nodeService.getTargetAssocs(destinationNodeRef, TEST_ASSOC_TYPE_QNAME); 657 assertNotNull(destinationTargets); 658 assertEquals(1, destinationTargets.size()); 659 AssociationRef nodeAssocRef = destinationTargets.get(0); 660 assertNotNull(nodeAssocRef); 661 assertEquals(this.targetNodeRef, nodeAssocRef.getTargetRef()); 662 663 List <ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(destinationNodeRef); 665 assertNotNull(childAssocRefs); 666 int expectedSize = 2; 667 if (this.nodeService.hasAspect(destinationNodeRef, RuleModel.ASPECT_RULES) == true) 668 { 669 expectedSize = expectedSize + 1; 670 } 671 672 assertEquals(expectedSize, childAssocRefs.size()); 673 for (ChildAssociationRef ref : childAssocRefs) 674 { 675 if (ref.getQName().equals(TEST_CHILD_ASSOC_QNAME2) == true) 676 { 677 assertFalse(ref.isPrimary()); 679 assertEquals(this.nonPrimaryChildNodeRef, ref.getChildRef()); 680 } 681 else 682 { 683 if (copyChildren == false) 684 { 685 if (ref.getTypeQName().equals(RuleModel.ASSOC_RULE_FOLDER) == true) 686 { 687 assertTrue(ref.isPrimary()); 688 assertTrue(this.childNodeRef.equals(ref.getChildRef()) == false); 689 } 690 else 691 { 692 assertFalse(ref.isPrimary()); 693 assertEquals(this.childNodeRef, ref.getChildRef()); 694 } 695 } 696 else 697 { 698 assertTrue(ref.isPrimary()); 699 assertTrue(this.childNodeRef.equals(ref.getChildRef()) == false); 700 701 } 703 } 704 } 705 } 706 } 707 | Popular Tags |