1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.util.ClassLoaderUtils;
20 import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
21 import org.kuali.rice.kew.rule.bo.RuleTemplateAttributeBo;
22 import org.kuali.rice.kew.service.KEWServiceLocator;
23 import org.kuali.rice.kew.test.KEWTestCase;
24
25 import java.util.List;
26
27 import static org.junit.Assert.*;
28
29
30
31
32
33
34 public class RuleTemplateAttributeTest extends KEWTestCase {
35
36 protected void loadTestData() throws Exception {
37 loadXmlFile("RuleTemplateAttributeTestConfig.xml");
38 }
39
40 @Test
41 public void testGetWorkflowAttribute() throws Exception {
42 RuleTemplateBo template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName("TemplateWithRuleValidationAttribute");
43 List<RuleTemplateAttributeBo> ruleTemplateAttributes = (List<RuleTemplateAttributeBo>) template.getRuleTemplateAttributes();
44 int index = 0;
45 for (RuleTemplateAttributeBo ruleTemplateAttribute : ruleTemplateAttributes) {
46 boolean runtimeThrown = false;
47 WorkflowRuleAttribute attribute = null;
48 try {
49 attribute = ruleTemplateAttribute.getWorkflowAttribute();
50 } catch (RuntimeException e) {
51 runtimeThrown = true;
52 }
53 if (index == 0) {
54
55 assertFalse("RuntimeException should not have been thrown.", runtimeThrown);
56 assertNotNull("Attribute should exist.", attribute);
57 attribute = (WorkflowRuleAttribute) ClassLoaderUtils.unwrapFromProxy(attribute);
58 assertEquals("Should be TestRuleAttribute", TestRuleAttribute.class, attribute.getClass());
59 } else if (index == 1) {
60
61 assertTrue("RuntimeException should have been thrown.", runtimeThrown);
62 assertNull("This should be the rule delegation attribute, not a WorkflowAttribute.", attribute);
63 }
64 index++;
65 }
66 }
67
68 @Test
69 public void testIsWorkflowAttribute() throws Exception {
70 RuleTemplateBo template = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName("TemplateWithRuleValidationAttribute");
71 List<RuleTemplateAttributeBo> ruleTemplateAttributes = (List<RuleTemplateAttributeBo>) template.getRuleTemplateAttributes();
72 int index = 0;
73 for (RuleTemplateAttributeBo ruleTemplateAttribute : ruleTemplateAttributes) {
74 boolean isWorkflowAttribute = ruleTemplateAttribute.isWorkflowAttribute();
75 Object attribute = ruleTemplateAttribute.getAttribute();
76 attribute = ClassLoaderUtils.unwrapFromProxy(attribute);
77 if (index == 0) {
78
79 assertNotNull(attribute);
80 assertEquals("Should be TestRuleAttribute", TestRuleAttribute.class, attribute.getClass());
81 assertTrue("TestRuleAttribute is a workflow attribute.", isWorkflowAttribute);
82 } else if (index == 1) {
83
84 assertEquals("Should be TestRuleValidationAttribute", TestRuleValidationAttribute.class, attribute.getClass());
85 assertFalse("TestRuleValidationAttribute is not a workflow attribute", isWorkflowAttribute);
86 }
87 index++;
88 }
89 }
90
91 }