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.messaging.exceptionhandling;
017
018 import static org.junit.Assert.assertTrue;
019 import static org.junit.Assert.fail;
020
021 import org.junit.Test;
022 import org.kuali.rice.kew.api.WorkflowDocument;
023 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
024 import org.kuali.rice.kew.test.KEWTestCase;
025 import org.kuali.rice.kew.test.TestUtilities;
026 import org.kuali.rice.test.BaselineTestCase;
027
028 /**
029 * This is a unit test for testing the functionality of the ExceptionRoutingService.
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
034 public class ExceptionRoutingServiceTest extends KEWTestCase {
035
036 /**
037 * Checks to make sure that the KIM routing is working.
038 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting()
039 */
040 @Test public void testKimExceptionRouting() throws Exception {
041 loadXmlFile("RouteExceptionTestDoc.xml");
042 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), "TestFinalApproverDocumentType");
043 document.setTitle("");
044 document.route("");
045 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
046 try {
047 document.approve("");
048 fail("document should have thrown routing exception");
049 } catch (Exception e) {
050 //deal with single transaction issue in test.
051 TestUtilities.getExceptionThreader().join();
052 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
053 assertTrue("Document should be in exception routing", document.isException());
054 }
055 }
056
057 /**
058 * Checks to make sure that the KIM routing is working with hierarchical documents.
059 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting()
060 */
061 @Test public void testKimExceptionRoutingWithDocHierarchy() throws Exception {
062 loadXmlFile("RouteExceptionTestDoc.xml");
063 String[] docNames = {"TestFinalApproverDocumentType_Child", "TestFinalApproverDocumentType_GrandChild"};
064 // Test the child doc and then the grandchild doc.
065 for (int i = 0; i < docNames.length; i++) {
066 // Perform the same steps as in the previous unit test.
067 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), docNames[i]);
068 document.setTitle("");
069 document.route("");
070 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
071 try {
072 document.approve("");
073 fail("document should have thrown routing exception");
074 } catch (Exception e) {
075 //deal with single transaction issue in test.
076 TestUtilities.getExceptionThreader().join();
077 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
078 assertTrue("Document should be in exception routing", document.isException());
079 }
080 }
081 }
082
083 /**
084 * Checks to make sure that the KIM routing is working for a RiceDocument child.
085 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting()
086 */
087 @Test public void testKimExceptionRoutingWithRiceDocumentChild() throws Exception {
088 loadXmlFile("RouteExceptionTestDoc.xml");
089 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), "DocumentTypeDocument_New");
090 document.setTitle("");
091 document.route("");
092 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
093 try {
094 document.approve("");
095 fail("document should have thrown routing exception");
096 } catch (Exception e) {
097 //deal with single transaction issue in test.
098 TestUtilities.getExceptionThreader().join();
099 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
100 assertTrue("Document should be in exception routing", document.isException());
101 }
102 }
103 }