001 /**
002 * Copyright 2005-2011 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 */
016 package org.kuali.rice.kew.actions;
017
018 import static org.junit.Assert.assertFalse;
019 import static org.junit.Assert.assertTrue;
020
021 import org.junit.Test;
022 import org.kuali.rice.edl.framework.util.EDLFunctions;
023 import org.kuali.rice.kew.api.WorkflowDocument;
024 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
025 import org.kuali.rice.kew.test.KEWTestCase;
026 import org.kuali.rice.krad.UserSession;
027 import org.kuali.rice.krad.util.GlobalVariables;
028
029 public class RouteLogAuthenticationTest extends KEWTestCase {
030
031 public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
032
033 protected void loadTestData() throws Exception {
034 loadXmlFile("ActionsConfig.xml");
035 }
036
037 /**
038 * Tests EDLFunctions.isUserRouteLogAuthenticated
039 */
040 @Test public void testUserRouteLogAuthenticated() throws Exception {
041 String user1PrincipalId = getPrincipalIdForName("user1");
042
043 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user1PrincipalId, DOCUMENT_TYPE_NAME);
044 document.route("");
045
046 // ensure the UserSession is cleared out (could have been set up by other tests)
047 GlobalVariables.setUserSession(null);
048
049 // false because we didn't set up the user session properly
050 assertFalse(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
051
052 // these two should be in the route log
053 GlobalVariables.setUserSession(new UserSession("user1"));
054 assertTrue(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
055 GlobalVariables.setUserSession(new UserSession("bmcgough"));
056 assertTrue(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
057
058 // user2 should NOT be in the route log
059 GlobalVariables.setUserSession(new UserSession("user2"));
060 assertFalse(EDLFunctions.isUserRouteLogAuthenticated(document.getDocumentId() + ""));
061 }
062
063 }