1 17 package org.alfresco.repo.rule; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.alfresco.model.ContentModel; 23 import org.alfresco.repo.content.MimetypeMap; 24 import org.alfresco.repo.rule.ruletrigger.RuleTrigger; 25 import org.alfresco.service.cmr.repository.ContentService; 26 import org.alfresco.service.cmr.repository.ContentWriter; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.cmr.repository.NodeService; 29 import org.alfresco.service.cmr.repository.StoreRef; 30 import org.alfresco.util.BaseSpringTest; 31 32 37 public class RuleTypeImplTest extends BaseSpringTest 38 { 39 private static final String NAME = "name"; 40 41 private NodeService nodeService; 42 private ContentService contentService; 43 44 private StoreRef testStoreRef; 45 private NodeRef rootNodeRef; 46 47 @Override 48 protected void onSetUpInTransaction() throws Exception 49 { 50 this.nodeService = (NodeService)this.applicationContext.getBean("nodeService"); 51 this.contentService = (ContentService)this.applicationContext.getBean("contentService"); 52 53 this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); 54 this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); 55 } 56 57 public void testConstructor() 58 { 59 create(); 60 } 61 62 private RuleTypeImpl create() 63 { 64 RuleTypeImpl temp = new RuleTypeImpl(null); 65 temp.setBeanName(NAME); 66 assertNotNull(temp); 67 return temp; 68 } 69 70 public void testGetName() 71 { 72 RuleTypeImpl temp = create(); 73 assertEquals(NAME, temp.getName()); 74 } 75 76 78 80 82 public void testMockInboundRuleType() 83 { 84 NodeRef nodeRef = this.nodeService.createNode( 85 this.rootNodeRef, 86 ContentModel.ASSOC_CHILDREN, 87 ContentModel.ASSOC_CHILDREN, 88 ContentModel.TYPE_CONTENT).getChildRef(); 89 NodeRef nodeRef2 = this.nodeService.createNode( 90 this.rootNodeRef, 91 ContentModel.ASSOC_CHILDREN, 92 ContentModel.ASSOC_CHILDREN, 93 ContentModel.TYPE_CONTAINER).getChildRef(); 94 95 List <RuleTrigger> triggers = new ArrayList <RuleTrigger>(2); 96 triggers.add((RuleTrigger)this.applicationContext.getBean("on-content-create-trigger")); 97 triggers.add((RuleTrigger)this.applicationContext.getBean("on-content-update-trigger")); 98 triggers.add((RuleTrigger)this.applicationContext.getBean("on-create-child-association-trigger")); 99 100 ExtendedRuleType ruleType = new ExtendedRuleType(triggers); 101 assertFalse(ruleType.rulesTriggered); 102 103 ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); 105 contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); 106 contentWriter.putContent("any old content"); 107 assertTrue(ruleType.rulesTriggered); 108 109 ruleType.rulesTriggered = false; 111 assertFalse(ruleType.rulesTriggered); 112 113 this.nodeService.addChild( 115 nodeRef2, 116 nodeRef, 117 ContentModel.ASSOC_CHILDREN, 118 ContentModel.ASSOC_CHILDREN); 119 assertTrue(ruleType.rulesTriggered); 120 } 121 122 private class ExtendedRuleType extends RuleTypeImpl 123 { 124 public boolean rulesTriggered = false; 125 126 public ExtendedRuleType(List <RuleTrigger> ruleTriggers) 127 { 128 super(ruleTriggers); 129 } 130 131 @Override 132 public void triggerRuleType(NodeRef nodeRef, NodeRef actionedUponNodeRef) 133 { 134 this.rulesTriggered = true; 135 } 136 137 } 138 } 139 | Popular Tags |