001/**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.routing;
017
018import org.junit.Test;
019import org.kuali.rice.kew.api.WorkflowDocument;
020import org.kuali.rice.kew.api.WorkflowDocumentFactory;
021import org.kuali.rice.kew.api.action.ActionRequest;
022import org.kuali.rice.kew.test.KEWTestCase;
023import org.kuali.rice.kew.test.TestUtilities;
024import org.kuali.rice.kim.api.services.KimApiServiceLocator;
025
026import java.util.List;
027
028import static org.junit.Assert.assertTrue;
029
030public class RoutingWithEmptyWorkGroupTest extends KEWTestCase {
031
032        protected void loadTestData() throws Exception {
033                loadXmlFile("RoutingWithEmptyGroupConfig.xml");
034        }
035
036        @Test public void testRoutingToEmptyWorkgroup() throws Exception {
037
038                String user1PrincipalId = getPrincipalIdForName("user1");
039                String user2PrincipalId = getPrincipalIdForName("user2");
040
041                WorkflowDocument doc = WorkflowDocumentFactory.createDocument(user1PrincipalId, "EmptyWorkgroupDocType");
042
043                doc = WorkflowDocumentFactory.loadDocument("user1", doc.getDocumentId());
044
045                doc.route("");
046
047                // the document should skip node 1 because it is routing to user1, it should
048                // skip node 2 (effectively) because that node is using a group with no members,
049                // and then it should land on node 3 being in user 2's action list
050                
051                doc = WorkflowDocumentFactory.loadDocument(user2PrincipalId, doc.getDocumentId());
052                
053                assertTrue("Document should be enroute", doc.isEnroute());
054                TestUtilities.assertAtNode(doc, "Node3");
055                
056                TestUtilities.assertInActionList(user2PrincipalId, doc.getDocumentId());
057                
058                // verify that an action request was generated at Node 2 to the "EmptyWorkgroup" but was immediately deactivated
059                List<ActionRequest> actionRequests = doc.getRootActionRequests();
060                for (ActionRequest actionRequest : actionRequests) {
061                        if ("Node2".equals(actionRequest.getNodeName())) {
062                                assertTrue("action request should be for a group", actionRequest.isGroupRequest());
063                                assertTrue("action request should be marked as \"done\"", actionRequest.isDone());
064                                assertTrue("Group should have no members.", KimApiServiceLocator.getGroupService().getMemberPrincipalIds(
065                        actionRequest.getGroupId()).isEmpty());
066                        }
067                }
068        }
069}