001/** 002 * Copyright 2005-2014 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 */ 016package org.kuali.rice.kew.messaging.exceptionhandling; 017 018import static org.junit.Assert.assertEquals; 019import static org.junit.Assert.assertTrue; 020import static org.junit.Assert.fail; 021 022import org.junit.Test; 023import org.kuali.rice.kew.api.WorkflowDocument; 024import org.kuali.rice.kew.api.WorkflowDocumentFactory; 025import org.kuali.rice.kew.api.document.DocumentStatus; 026import org.kuali.rice.kew.test.KEWTestCase; 027import org.kuali.rice.kew.test.TestUtilities; 028import org.kuali.rice.test.BaselineTestCase; 029 030/** 031 * This is a unit test for testing the functionality of the ExceptionRoutingService. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035@BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB) 036public class ExceptionRoutingServiceTest extends KEWTestCase { 037 038 /** 039 * Checks to make sure that the KIM routing is working. 040 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting() 041 */ 042 @Test public void testKimExceptionRouting() throws Exception { 043 loadXmlFile("RouteExceptionTestDoc.xml"); 044 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), "TestFinalApproverDocumentType"); 045 document.setTitle(""); 046 document.route(""); 047 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()); 048 try { 049 document.approve(""); 050 fail("document should have thrown routing exception"); 051 } catch (Exception e) { 052 //deal with single transaction issue in test. 053 TestUtilities.getExceptionThreader().join(); 054 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()); 055 assertTrue("Document should be in exception routing", document.isException()); 056 } 057 } 058 059 /** 060 * Checks to make sure that the KIM routing is working with hierarchical documents. 061 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting() 062 */ 063 @Test public void testKimExceptionRoutingWithDocHierarchy() throws Exception { 064 loadXmlFile("RouteExceptionTestDoc.xml"); 065 String[] docNames = {"TestFinalApproverDocumentType_Child", "TestFinalApproverDocumentType_GrandChild"}; 066 // Test the child doc and then the grandchild doc. 067 for (int i = 0; i < docNames.length; i++) { 068 // Perform the same steps as in the previous unit test. 069 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), docNames[i]); 070 document.setTitle(""); 071 document.route(""); 072 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()); 073 try { 074 document.approve(""); 075 fail("document should have thrown routing exception"); 076 } catch (Exception e) { 077 //deal with single transaction issue in test. 078 TestUtilities.getExceptionThreader().join(); 079 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()); 080 assertTrue("Document should be in exception routing", document.isException()); 081 } 082 } 083 } 084 085 /** 086 * Checks to make sure that the KIM routing is working for a RiceDocument child. 087 * Based upon the test method org.kuali.rice.kew.doctype.DocumentTypeTest.testFinalApproverRouting() 088 */ 089 @Test public void testKimExceptionRoutingWithRiceDocumentChild() throws Exception { 090 loadXmlFile("RouteExceptionTestDoc.xml"); 091 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("admin"), "DocumentTypeDocument_New"); 092 document.setTitle(""); 093 document.route(""); 094 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()); 095 try { 096 document.approve(""); 097 fail("document should have thrown routing exception"); 098 } catch (Exception e) { 099 //deal with single transaction issue in test. 100 TestUtilities.getExceptionThreader().join(); 101 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()); 102 assertTrue("Document should be in exception routing", document.isException()); 103 } 104 } 105 106 /** 107 * Makes sure the {@link org.kuali.rice.kew.routeheader.service.WorkflowDocumentService#placeInExceptionRouting(String, org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue, String)} 108 * method exposed through {@link org.kuali.rice.kew.api.action.WorkflowDocumentActionsService#placeInExceptionRouting(org.kuali.rice.kew.api.action.DocumentActionParameters)} and 109 * {@link WorkflowDocument#placeInExceptionRouting(String)} at the time of this writing works when not called in the context of an exisiting message. 110 */ 111 @Test public void testExplicitlyPlacingDocumentInException() { 112 loadXmlFile("org/kuali/rice/kew/routeheader/AppDocStatusTestConfig.xml"); 113 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "TestAppDocStatusDoc1"); 114 document.setTitle(""); 115 document.route(""); 116 // no message will be associated with this invocation inside ExceptionRoutingServiceImpl 117 document.placeInExceptionRouting("explicitly placing in exception routing"); 118 assertEquals(DocumentStatus.EXCEPTION, document.getStatus()); 119 } 120}