View Javadoc

1   /*
2    * Copyright 2007-2008 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.kew.dto.NetworkIdDTO;
20  import org.kuali.rice.kew.exception.WorkflowException;
21  import org.kuali.rice.kew.service.WorkflowDocument;
22  import org.kuali.rice.kew.test.KEWTestCase;
23  
24  
25  /**
26   * Tests KRA meta-rule functionality KULRICE-1045
27   * 
28   * Tests meta rule implemented via KRAMetaRuleExpression variant that allows the
29   * rule to be expressed in groovy, with the help of a helper bean
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class KRAMetaRuleGroovyTest extends KEWTestCase {
34      protected void loadTestData() throws Exception {
35          loadXmlFile("KRAMetaRuleGroovy.xml");
36          loadXmlFile("KRAMetaRuleMapsGroovy.xml");
37      }
38  
39      @Test public void testKRAMetaRuleGroovy() throws WorkflowException {
40          WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("arh14"), "KRAMetaRuleTest");
41          doc.routeDocument("routing");
42  
43          doc = new WorkflowDocument(new NetworkIdDTO("user2"), doc.getRouteHeaderId());
44  
45          // user2 defined on bizRule4...the first rule that yields responsibilities
46          assertTrue(doc.isApprovalRequested());
47          
48          doc.approve("approving as user2");
49          
50          doc = new WorkflowDocument(new NetworkIdDTO("user2"), doc.getRouteHeaderId());
51          
52          assertFalse(doc.isApprovalRequested());
53          
54          // now load it up as user3
55          doc = new WorkflowDocument(new NetworkIdDTO("user3"), doc.getRouteHeaderId());
56  
57          // user1 defined on bizRule5...the second rule that yields responsibilities
58          assertTrue(doc.isApprovalRequested());
59          
60          doc.approve("approving as user3");
61  
62          doc = new WorkflowDocument(new NetworkIdDTO("user3"), doc.getRouteHeaderId());
63          assertFalse(doc.isApprovalRequested());
64          doc = new WorkflowDocument(new NetworkIdDTO("user2"), doc.getRouteHeaderId());
65          assertFalse(doc.isApprovalRequested());
66          doc = new WorkflowDocument(new NetworkIdDTO("user1"), doc.getRouteHeaderId());
67          assertFalse(doc.isApprovalRequested());
68       
69          assertTrue(doc.stateIsFinal());
70      }
71  
72      @Test public void testKRAMetaRuleMapsGroovy() throws WorkflowException {
73          WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("arh14"), "KRAMetaRuleMapsTest");
74          doc.routeDocument("routing");
75  
76          // xqi, shenl, dewey
77  
78          // test that TestWorkgroup requests get activated first
79          doc = new WorkflowDocument(new NetworkIdDTO("xqi"), doc.getRouteHeaderId());
80          assertTrue(doc.isApprovalRequested());
81          doc = new WorkflowDocument(new NetworkIdDTO("shenl"), doc.getRouteHeaderId());
82          assertFalse(doc.isApprovalRequested());
83          doc = new WorkflowDocument(new NetworkIdDTO("dewey"), doc.getRouteHeaderId());
84          assertFalse(doc.isApprovalRequested());
85          
86          doc = new WorkflowDocument(new NetworkIdDTO("xqi"), doc.getRouteHeaderId());
87          doc.approve("approving as xqi");
88          
89          // next is shenl from the mock role
90          doc = new WorkflowDocument(new NetworkIdDTO("xqi"), doc.getRouteHeaderId());
91          assertFalse(doc.isApprovalRequested());
92          doc = new WorkflowDocument(new NetworkIdDTO("shenl"), doc.getRouteHeaderId());
93          assertTrue(doc.isApprovalRequested());
94          doc = new WorkflowDocument(new NetworkIdDTO("jhopf"), doc.getRouteHeaderId());
95          assertTrue(doc.isApprovalRequested());
96          doc = new WorkflowDocument(new NetworkIdDTO("dewey"), doc.getRouteHeaderId());
97          assertFalse(doc.isApprovalRequested());
98  
99          doc = new WorkflowDocument(new NetworkIdDTO("shenl"), doc.getRouteHeaderId());
100         doc.approve("approving as shenl");
101         
102         // last is dewey from NonSIT workgroup
103         doc = new WorkflowDocument(new NetworkIdDTO("xqi"), doc.getRouteHeaderId());
104         assertFalse(doc.isApprovalRequested());
105         doc = new WorkflowDocument(new NetworkIdDTO("shenl"), doc.getRouteHeaderId());
106         assertFalse(doc.isApprovalRequested());
107         doc = new WorkflowDocument(new NetworkIdDTO("jhopf"), doc.getRouteHeaderId());
108         assertFalse(doc.isApprovalRequested());
109         doc = new WorkflowDocument(new NetworkIdDTO("dewey"), doc.getRouteHeaderId());
110         assertTrue(doc.isApprovalRequested());
111 
112         doc = new WorkflowDocument(new NetworkIdDTO("dewey"), doc.getRouteHeaderId());
113         doc.approve("approving as dewey");
114      
115         assertTrue(doc.stateIsFinal());
116     }
117 }