View Javadoc

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