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.actions;
17  
18  import static org.junit.Assert.assertFalse;
19  import static org.junit.Assert.assertTrue;
20  
21  import org.junit.Test;
22  import org.kuali.rice.edl.framework.util.EDLFunctions;
23  import org.kuali.rice.kew.api.WorkflowDocument;
24  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
25  import org.kuali.rice.kew.test.KEWTestCase;
26  import org.kuali.rice.krad.UserSession;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  
29  public class RouteLogAuthenticationTest extends KEWTestCase {
30  
31  	public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
32  
33      protected void loadTestData() throws Exception {
34          loadXmlFile("ActionsConfig.xml");
35      }
36  
37  	/**
38       * Tests EDLFunctions.isUserRouteLogAuthenticated
39       */
40      @Test public void testUserRouteLogAuthenticated() throws Exception {
41      	String user1PrincipalId = getPrincipalIdForName("user1");
42  
43      	WorkflowDocument document = WorkflowDocumentFactory.createDocument(user1PrincipalId, DOCUMENT_TYPE_NAME);
44      	document.route("");
45  
46      	// ensure the UserSession is cleared out (could have been set up by other tests)
47      	GlobalVariables.setUserSession(null);
48  
49          // false because we didn't set up the user session properly
50          assertFalse(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
51  
52          // these two should be in the route log
53          GlobalVariables.setUserSession(new UserSession("user1"));
54          assertTrue(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
55          GlobalVariables.setUserSession(new UserSession("bmcgough"));
56          assertTrue(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
57  
58          // user2 should NOT be in the route log
59          GlobalVariables.setUserSession(new UserSession("user2"));
60          assertFalse(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
61      }
62  
63  }