View Javadoc

1   /**
2    * Copyright 2005-2013 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  import static org.junit.Assert.fail;
20  
21  import org.junit.Test;
22  import org.kuali.rice.core.api.config.property.Config;
23  import org.kuali.rice.core.api.config.property.ConfigContext;
24  import org.kuali.rice.kew.api.WorkflowDocument;
25  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
26  import org.kuali.rice.kew.test.KEWTestCase;
27  import org.kuali.rice.ksb.util.KSBConstants;
28  
29  /**
30   * Tests the generation of Action Requests from RoleAttributes
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class RoleAttributeTest extends KEWTestCase {
35  
36  	@Test public void testWorkgroupRoleAttribute() throws Exception {
37  		loadXmlFile("WorkgroupRoleAttributeTestConfig.xml");
38  		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), "WorkgroupRoleAttributeDocument");
39  		document.route("");
40  
41  		assertTrue("document should be enroute.", document.isEnroute());
42  	}
43  
44  	/**
45  	 * Tests that if you return a non-null Id object with a null id value inside, that the role action request
46  	 * generation handles it properly.
47  	 */
48  	@Test public void testBadWorkgroupRoleAttribute() throws Exception {
49  		loadXmlFile("BadWorkgroupRoleAttributeTestConfig.xml");
50  		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), "BadWorkgroupRoleAttributeDocument");
51  
52  
53          ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.Config.ALLOW_SYNC_EXCEPTION_ROUTING, "false");
54  		try {
55  			document.route("");
56  			fail("Should have thrown an error because we had some bad ids.");
57  		} catch (Exception e) {
58          } finally {
59              // be sure to change it back afterward!
60              ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.Config.ALLOW_SYNC_EXCEPTION_ROUTING, "true");
61          }
62  	}
63  }