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 static org.junit.Assert.assertTrue;
19  
20  import org.junit.Test;
21  import org.kuali.rice.kew.api.WorkflowDocument;
22  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23  import org.kuali.rice.kew.exception.WorkflowException;
24  import org.kuali.rice.kew.test.KEWTestCase;
25  import org.kuali.rice.kew.test.TestUtilities;
26  
27  /**
28   * Test hierarchical routing coupled with KRA meta-rule
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class KRAMetaRuleHierarchyTest extends KEWTestCase {
32      // this matches the hierarchy of meta-rules defined
33      // in KRAMetaRuleHierarchy.xml
34      private static final String HIERARCHY =
35          "<stop id=\"top\">" +
36            "<stop id=\"a\">" +
37              "<stop id=\"a-1\"/>" +
38              "<stop id=\"a-2\"/>" +
39            "</stop>" +
40            "<stop id=\"b\">" +
41              "<stop id=\"b-1\"/>" +
42              "<stop id=\"b-2\"/>" +
43            "</stop>" +
44          "</stop>";
45  
46      protected void approve(String user, String docId) throws WorkflowException {
47          log.info("Approving as " + user);
48          WorkflowDocument doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(user), docId);
49          doc.approve("approving as " + user);
50      }
51  
52      @Test
53      public void test() throws WorkflowException {
54          loadXmlFile("KRAMetaRuleHierarchy.xml");
55          
56          WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("quickstart"), "KRAMetaRuleHierarchyTest");
57          
58          doc.setApplicationContent(HIERARCHY);
59          doc.route("initial route");
60  
61          TestUtilities.logActionRequests(doc.getDocumentId());
62          // user 2 is before user3 because of ordering between business rules included by meta-rule
63          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user2", "shenl", "jhopf", "ewestfal" }, true);
64          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3", "user1", "arh14", "rkirkend", "xqi" }, false);
65          
66          approve("user2", doc.getDocumentId());
67  
68          TestUtilities.logActionRequests(doc.getDocumentId());
69          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3", "shenl", "jhopf", "ewestfal" }, true);
70          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user2", "user1", "arh14", "rkirkend", "xqi" }, false);
71  
72          approve("shenl", doc.getDocumentId());
73          
74          TestUtilities.logActionRequests(doc.getDocumentId());
75          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3", "jhopf", "ewestfal" }, true);
76          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "shenl", "user2", "user1", "arh14", "rkirkend", "xqi" }, false);
77          
78          approve("jhopf", doc.getDocumentId());
79          
80          TestUtilities.logActionRequests(doc.getDocumentId());
81          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3", "ewestfal" }, true);
82          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "jhopf", "shenl", "user2", "user1", "arh14", "rkirkend", "xqi" }, false);
83          
84          approve("ewestfal", doc.getDocumentId());
85          
86          TestUtilities.logActionRequests(doc.getDocumentId());
87          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3", "rkirkend" }, true);
88          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "ewestfal", "shenl", "user2", "user1", "arh14", "xqi" }, false);
89          
90          approve("rkirkend", doc.getDocumentId());
91          
92          TestUtilities.logActionRequests(doc.getDocumentId());
93          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3" }, true);
94          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "rkirkend", "ewestfal", "shenl", "user2", "user1", "arh14", "xqi" }, false);
95          
96          approve("user3", doc.getDocumentId());
97          
98          TestUtilities.logActionRequests(doc.getDocumentId());
99          TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "arh14" }, true);
100         TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user3", "rkirkend", "ewestfal", "shenl", "user2", "user1", "xqi" }, false);
101         
102         approve("arh14", doc.getDocumentId());
103         
104         TestUtilities.logActionRequests(doc.getDocumentId());
105         TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user1" }, true);
106         TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "arh14", "user3", "rkirkend", "ewestfal", "shenl", "user2", "arh14", "xqi" }, false);
107         
108         approve("user1", doc.getDocumentId());
109         
110         TestUtilities.logActionRequests(doc.getDocumentId());        
111         TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "xqi" }, true);
112         TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "user1", "arh14", "user3", "rkirkend", "ewestfal", "shenl", "user2" }, false);
113         
114         approve("xqi", doc.getDocumentId());
115         
116         TestUtilities.logActionRequests(doc.getDocumentId());
117         TestUtilities.assertApprovals(doc.getDocumentId(), new String[] { "xqi", "user1", "arh14", "user3", "rkirkend", "ewestfal", "shenl", "user2" }, false);
118 
119         TestUtilities.logActionRequests(doc.getDocumentId());
120 
121         doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), doc.getDocumentId());
122         assertTrue(doc.isFinal());
123     }
124 }