View Javadoc

1   /*
2    * Copyright 2006-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.messaging.exceptionhandling;
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.kew.api.WorkflowDocument;
23  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
24  import org.kuali.rice.kew.test.KEWTestCase;
25  import org.kuali.rice.kew.test.TestUtilities;
26  import org.kuali.rice.test.BaselineTestCase;
27  
28  /**
29   * This is a unit test for testing the functionality of the ExceptionRoutingService. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
34  public class ExceptionRoutingServiceTest extends KEWTestCase {
35  
36  	/**
37  	 * Checks to make sure that the KIM routing is working.
38  	 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting()
39  	 */
40  	@Test public void testKimExceptionRouting() throws Exception {
41  		loadXmlFile("RouteExceptionTestDoc.xml");
42  		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), "TestFinalApproverDocumentType");
43          document.setTitle("");
44          document.route("");
45          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
46          try {
47              document.approve("");
48              fail("document should have thrown routing exception");
49          } catch (Exception e) {
50              //deal with single transaction issue in test.
51          	TestUtilities.getExceptionThreader().join();
52          	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
53              assertTrue("Document should be in exception routing", document.isException());
54          }
55  	}
56  
57  	/**
58  	 * Checks to make sure that the KIM routing is working with hierarchical documents.
59  	 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting()
60  	 */
61  	@Test public void testKimExceptionRoutingWithDocHierarchy() throws Exception {
62  		loadXmlFile("RouteExceptionTestDoc.xml");
63  		String[] docNames = {"TestFinalApproverDocumentType_Child", "TestFinalApproverDocumentType_GrandChild"};
64  		// Test the child doc and then the grandchild doc.
65  		for (int i = 0; i < docNames.length; i++) {
66  			// Perform the same steps as in the previous unit test.
67  			WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), docNames[i]);
68  	        document.setTitle("");
69  	        document.route("");
70  	        document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
71  	        try {
72  	            document.approve("");
73  	            fail("document should have thrown routing exception");
74  	        } catch (Exception e) {
75  	            //deal with single transaction issue in test.
76  	        	TestUtilities.getExceptionThreader().join();
77  	        	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
78  	            assertTrue("Document should be in exception routing", document.isException());
79  	        }
80  		}
81  	}
82  
83  	/**
84  	 * Checks to make sure that the KIM routing is working for a RiceDocument child.
85  	 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting()
86  	 */
87  	@Test public void testKimExceptionRoutingWithRiceDocumentChild() throws Exception {
88  		loadXmlFile("RouteExceptionTestDoc.xml");
89  		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), "DocumentTypeDocument_New");
90          document.setTitle("");
91          document.route("");
92          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
93          try {
94              document.approve("");
95              fail("document should have thrown routing exception");
96          } catch (Exception e) {
97              //deal with single transaction issue in test.
98          	TestUtilities.getExceptionThreader().join();
99          	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
100             assertTrue("Document should be in exception routing", document.isException());
101         }
102 	}
103 }