KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > rule > RuleTypeImplTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.rule;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
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 /**
33  * Parameter definition implementation unit test.
34  *
35  * @author Roy Wetherall
36  */

37 public class RuleTypeImplTest extends BaseSpringTest
38 {
39     private static final String JavaDoc NAME = "name";
40     
41     private NodeService nodeService;
42     private ContentService contentService;
43     
44     private StoreRef testStoreRef;
45     private NodeRef rootNodeRef;
46     
47     @Override JavaDoc
48     protected void onSetUpInTransaction() throws Exception JavaDoc
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     // TODO Test the display label, ensuring that the label is retrieved from the resource
77

78     // TODO Test setRuleTriggers
79

80     // TODO Test triggerRuleType
81

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 JavaDoc<RuleTrigger> triggers = new ArrayList JavaDoc<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         // Update some content in order to trigger the rule type
104
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         // Reset
110
ruleType.rulesTriggered = false;
111         assertFalse(ruleType.rulesTriggered);
112         
113         // Create a child association in order to trigger the rule type
114
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 JavaDoc<RuleTrigger> ruleTriggers)
127         {
128             super(ruleTriggers);
129         }
130         
131         @Override JavaDoc
132         public void triggerRuleType(NodeRef nodeRef, NodeRef actionedUponNodeRef)
133         {
134             this.rulesTriggered = true;
135         }
136         
137     }
138 }
139
Popular Tags