View Javadoc

1   /*
2    * Copyright 2007 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.clientapp;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.actions.BlanketApproveTest;
20  import org.kuali.rice.kew.dto.NetworkIdDTO;
21  import org.kuali.rice.kew.dto.RouteHeaderDTO;
22  import org.kuali.rice.kew.exception.WorkflowException;
23  import org.kuali.rice.kew.service.WorkflowDocument;
24  import org.kuali.rice.kew.service.WorkflowInfo;
25  import org.kuali.rice.kew.test.KEWTestCase;
26  import org.kuali.rice.kew.util.KEWConstants;
27  import org.kuali.rice.kew.web.session.UserSession;
28  import org.kuali.rice.kim.bo.Person;
29  import org.kuali.rice.kim.service.KIMServiceLocator;
30  
31  
32  /**
33   * This is a description of what this class does - ewestfal don't forget to fill this in.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   *
37   */
38  public class WorkflowInfoTest extends KEWTestCase {
39  
40  	@Override
41  	protected void loadTestData() {
42  		// need this configuration to create a BlanketApproveParallelTest
43  		loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml");
44  	}
45  	
46      /**
47       * Tests the loading of a RouteHeaderVO using the WorkflowInfo.
48       *
49       * Verifies that an NPE no longer occurrs as mentioned in KULRICE-765.
50       */
51      @Test
52      public void testGetRouteHeader() throws Exception {
53       // ensure the UserSession is cleared out (could have been set up by other tests)
54      UserSession.setAuthenticatedUser(null);
55      String ewestfalPrincipalId = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("ewestfal").getPrincipalId();
56      UserSession.setAuthenticatedUser(new UserSession(ewestfalPrincipalId));
57      WorkflowDocument document = new WorkflowDocument(ewestfalPrincipalId, "TestDocumentType");
58  	Long documentId = document.getRouteHeaderId();
59  	assertNotNull(documentId);
60  
61  	RouteHeaderDTO routeHeaderVO = new WorkflowInfo().getRouteHeader(documentId);
62  	assertNotNull(routeHeaderVO);
63  
64  	assertEquals(documentId, routeHeaderVO.getRouteHeaderId());
65  	assertEquals(KEWConstants.ROUTE_HEADER_INITIATED_CD, routeHeaderVO.getDocRouteStatus());
66      }
67  
68      @Test
69      public void testGetDocumentStatus() throws Exception {
70  	WorkflowInfo info = new WorkflowInfo();
71  	// verify that a null document id throws an exception
72  	try {
73  	    String status = info.getDocumentStatus(null);
74  	    fail("A WorkflowException should have been thrown, instead returned status: " + status);
75  	} catch (WorkflowException e) {
76      } catch (IllegalArgumentException e) {
77      }
78  	// verify that a bad document id throws an exception
79  	try {
80  	    String status = info.getDocumentStatus(new Long(-1));
81  	    fail("A WorkflowException Should have been thrown, instead returned status: " + status);
82  	} catch (WorkflowException e) {}
83  
84  	// now create a doc and load it's status
85  	WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), "TestDocumentType");
86  	Long documentId = document.getRouteHeaderId();
87  	assertNotNull(documentId);
88  
89  	String status = info.getDocumentStatus(documentId);
90  	assertEquals("Document should be INITIATED.", KEWConstants.ROUTE_HEADER_INITIATED_CD, status);
91  
92  	// cancel the doc, it's status should be updated
93  	document.cancel("");
94  	status = info.getDocumentStatus(documentId);
95  	assertEquals("Document should be CANCELED.", KEWConstants.ROUTE_HEADER_CANCEL_CD, status);
96      }
97      
98      /**
99       * test for issue KFSMI-2979
100      * This method verifies that workflowInfo.getDocumentRoutedByPrincipalId returns the blanket approver 
101      * for a document that was put onroute by that person (the blanket approver)
102      */
103     @Test
104     public void testBlanketApproverSubmitted() throws WorkflowException {
105     	Person blanketApprover = KIMServiceLocator.getPersonService().getPersonByPrincipalName("ewestfal");
106 
107         WorkflowDocument document = new WorkflowDocument(blanketApprover.getPrincipalId(), "BlanketApproveParallelTest");
108         document.blanketApprove("");
109 
110         String routedByPrincipalId = new WorkflowInfo().getDocumentRoutedByPrincipalId(document.getRouteHeaderId());
111         assertEquals("the blanket approver should be the routed by", blanketApprover.getPrincipalId(), routedByPrincipalId);
112     }
113     
114     @Test
115     public void testGetAppDocId() throws Exception {
116     	WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), "TestDocumentType");
117     	document.saveRoutingData();
118     	
119     	String appDocId = new WorkflowInfo().getAppDocId(document.getRouteHeaderId());
120     	assertNull("appDocId should be null", appDocId);
121     	
122     	String appDocIdValue = "1234";
123     	document.setAppDocId(appDocIdValue);
124     	document.saveRoutingData();
125     	
126     	appDocId = new WorkflowInfo().getAppDocId(document.getRouteHeaderId());
127     	assertEquals("Incorrect appDocId", appDocIdValue, appDocId);
128     }
129 
130 }