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.clientapp; 017 018import org.junit.Test; 019import org.kuali.rice.kew.actions.BlanketApproveTest; 020import org.kuali.rice.kew.api.KewApiServiceLocator; 021import org.kuali.rice.kew.api.WorkflowDocument; 022import org.kuali.rice.kew.api.WorkflowDocumentFactory; 023import org.kuali.rice.kew.api.document.Document; 024import org.kuali.rice.kew.api.document.DocumentStatus; 025import org.kuali.rice.kew.api.exception.WorkflowException; 026import org.kuali.rice.kew.test.KEWTestCase; 027import org.kuali.rice.kew.api.KewApiConstants; 028import org.kuali.rice.kim.api.identity.Person; 029import org.kuali.rice.kim.api.services.KimApiServiceLocator; 030import org.kuali.rice.krad.UserSession; 031import org.kuali.rice.krad.util.GlobalVariables; 032import org.kuali.rice.test.BaselineTestCase.BaselineMode; 033import org.kuali.rice.test.BaselineTestCase.Mode; 034 035import static org.junit.Assert.*; 036 037/** 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 * 041 */ 042@BaselineMode(Mode.CLEAR_DB) 043public class WorkflowInfoTest extends KEWTestCase { 044 045 @Override 046 protected void loadTestData() { 047 // need this configuration to create a BlanketApproveParallelTest 048 loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml"); 049 } 050 051 /** 052 * Tests the loading of a RouteHeaderVO using the WorkflowInfo. 053 * 054 * Verifies that an NPE no longer occurrs as mentioned in KULRICE-765. 055 */ 056 @Test 057 public void testGetRouteHeader() throws Exception { 058 // ensure the UserSession is cleared out (could have been set up by other tests) 059 GlobalVariables.setUserSession(null); 060 String ewestfalPrincipalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("ewestfal") 061 .getPrincipalId(); 062 GlobalVariables.setUserSession(new UserSession("ewestfal")); 063 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(ewestfalPrincipalId, 064 "TestDocumentType"); 065 String documentId = workflowDocument.getDocumentId(); 066 assertNotNull(documentId); 067 068 Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId); 069 assertNotNull(document); 070 071 assertEquals(documentId, document.getDocumentId()); 072 assertEquals(DocumentStatus.INITIATED, document.getStatus()); 073 } 074 075 @Test 076 public void testGetDocumentStatus() throws Exception { 077 // verify that a null document id throws an exception 078 try { 079 DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(null); 080 fail("A WorkflowException should have been thrown, instead returned status: " + status); 081 } catch (IllegalArgumentException e) {} 082 083 // verify that a bad document id throws an exception 084 try { 085 DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus("-1"); 086 fail("A IllegalStateException Should have been thrown, instead returned status: " + status); 087 } catch (IllegalStateException e) {} 088 089 // now create a doc and load it's status 090 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), 091 "TestDocumentType"); 092 String documentId = document.getDocumentId(); 093 assertNotNull(documentId); 094 095 DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(documentId); 096 assertEquals("Document should be INITIATED.", KewApiConstants.ROUTE_HEADER_INITIATED_CD, status.getCode()); 097 098 // cancel the doc, it's status should be updated 099 document.cancel(""); 100 status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(documentId); 101 assertEquals("Document should be CANCELED.", KewApiConstants.ROUTE_HEADER_CANCEL_CD, status.getCode()); 102 } 103 104 /** 105 * test for issue KFSMI-2979 This method verifies that 106 * workflowInfo.getRoutedByPrincipalIdByDocumentId returns the blanket approver for a document that 107 * was put onroute by that person (the blanket approver) 108 */ 109 @Test 110 public void testBlanketApproverSubmitted() throws WorkflowException { 111 Person blanketApprover = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("ewestfal"); 112 113 WorkflowDocument document = WorkflowDocumentFactory.createDocument(blanketApprover.getPrincipalId(), 114 "BlanketApproveParallelTest"); 115 document.blanketApprove(""); 116 117 String routedByPrincipalId = KewApiServiceLocator.getWorkflowDocumentService().getRoutedByPrincipalIdByDocumentId( 118 document.getDocumentId()); 119 assertEquals("the blanket approver should be the routed by", blanketApprover.getPrincipalId(), 120 routedByPrincipalId); 121 } 122 123 @Test 124 public void testGetAppDocId() throws Exception { 125 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), 126 "TestDocumentType"); 127 document.saveDocumentData(); 128 129 String appDocId = KewApiServiceLocator.getWorkflowDocumentService().getApplicationDocumentId(document.getDocumentId()); 130 assertNull("appDocId should be null", appDocId); 131 132 String appDocIdValue = "1234"; 133 document.setApplicationDocumentId(appDocIdValue); 134 document.saveDocumentData(); 135 136 appDocId = KewApiServiceLocator.getWorkflowDocumentService().getApplicationDocumentId(document.getDocumentId()); 137 assertEquals("Incorrect appDocId", appDocIdValue, appDocId); 138 } 139 140 @Test 141 public void testGetAppDocStatus() throws Exception { 142 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), 143 "TestDocumentType"); 144 document.saveDocumentData(); 145 146 String appDocStatus = KewApiServiceLocator.getWorkflowDocumentService().getApplicationDocumentStatus(document.getDocumentId()); 147 assertNull("appDocStatus should be null", appDocStatus); 148 149 String appDocStatusValue = "Approved"; 150 document.setApplicationDocumentStatus(appDocStatusValue); 151 document.saveDocumentData(); 152 153 appDocStatus = KewApiServiceLocator.getWorkflowDocumentService().getApplicationDocumentStatus(document.getDocumentId()); 154 assertEquals("Incorrect appDocStatus", appDocStatusValue, appDocStatus); 155 } 156 157}