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.routing;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.api.WorkflowDocument;
20  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
21  import org.kuali.rice.kew.api.action.ActionRequest;
22  import org.kuali.rice.kew.test.KEWTestCase;
23  import org.kuali.rice.kew.test.TestUtilities;
24  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25  
26  import java.util.List;
27  
28  import static org.junit.Assert.assertTrue;
29  
30  public class RoutingWithEmptyWorkGroupTest extends KEWTestCase {
31  
32  	protected void loadTestData() throws Exception {
33  		loadXmlFile("RoutingWithEmptyGroupConfig.xml");
34  	}
35  
36  	@Test public void testRoutingToEmptyWorkgroup() throws Exception {
37  
38  		String user1PrincipalId = getPrincipalIdForName("user1");
39  		String user2PrincipalId = getPrincipalIdForName("user2");
40  
41  		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(user1PrincipalId, "EmptyWorkgroupDocType");
42  
43  		doc = WorkflowDocumentFactory.loadDocument("user1", doc.getDocumentId());
44  
45  		doc.route("");
46  
47  		// the document should skip node 1 because it is routing to user1, it should
48  		// skip node 2 (effectively) because that node is using a group with no members,
49  		// and then it should land on node 3 being in user 2's action list
50  		
51  		doc = WorkflowDocumentFactory.loadDocument(user2PrincipalId, doc.getDocumentId());
52  		
53  		assertTrue("Document should be enroute", doc.isEnroute());
54  		TestUtilities.assertAtNode(doc, "Node3");
55  		
56  		TestUtilities.assertInActionList(user2PrincipalId, doc.getDocumentId());
57  		
58  		// verify that an action request was generated at Node 2 to the "EmptyWorkgroup" but was immediately deactivated
59  		List<ActionRequest> actionRequests = doc.getRootActionRequests();
60  		for (ActionRequest actionRequest : actionRequests) {
61  			if ("Node2".equals(actionRequest.getNodeName())) {
62  				assertTrue("action request should be for a group", actionRequest.isGroupRequest());
63  				assertTrue("action request should be marked as \"done\"", actionRequest.isDone());
64  				assertTrue("Group should have no members.", KimApiServiceLocator.getGroupService().getMemberPrincipalIds(
65                          actionRequest.getGroupId()).isEmpty());
66  			}
67  		}
68  	}
69  }