View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests the RuleTemplateAttribute class.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
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                  // should be the TestRuleAttribute
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                  // should be the TestRuleDelegationAttribute so should be null
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                  // should be the TestRuleAttribute
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                  // should be the TestRuleValidationAttribute so should be null
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  }