View Javadoc

1   /**
2    * Copyright 2005-2013 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   *
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   * 
41   */
42  @BaselineMode(Mode.CLEAR_DB)
43  public class WorkflowInfoTest extends KEWTestCase {
44  
45      @Override
46      protected void loadTestData() {
47          // need this configuration to create a BlanketApproveParallelTest
48          loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml");
49      }
50  
51      /**
52       * Tests the loading of a RouteHeaderVO using the WorkflowInfo.
53       * 
54       * Verifies that an NPE no longer occurrs as mentioned in KULRICE-765.
55       */
56      @Test
57      public void testGetRouteHeader() throws Exception {
58          // ensure the UserSession is cleared out (could have been set up by other tests)
59          GlobalVariables.setUserSession(null);
60          String ewestfalPrincipalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("ewestfal")
61                  .getPrincipalId();
62          GlobalVariables.setUserSession(new UserSession("ewestfal"));
63          WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(ewestfalPrincipalId,
64                  "TestDocumentType");
65          String documentId = workflowDocument.getDocumentId();
66          assertNotNull(documentId);
67  
68          Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId);
69          assertNotNull(document);
70  
71          assertEquals(documentId, document.getDocumentId());
72          assertEquals(DocumentStatus.INITIATED, document.getStatus());
73      }
74  
75      @Test
76      public void testGetDocumentStatus() throws Exception {
77          // verify that a null document id throws an exception
78          try {
79              DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(null);
80              fail("A WorkflowException should have been thrown, instead returned status: " + status);
81          } catch (IllegalArgumentException e) {}
82  
83          // verify that a bad document id throws an exception
84          try {
85              DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus("-1");
86              fail("A IllegalStateException Should have been thrown, instead returned status: " + status);
87          } catch (IllegalStateException e) {}
88  
89          // now create a doc and load it's status
90          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"),
91                  "TestDocumentType");
92          String documentId = document.getDocumentId();
93          assertNotNull(documentId);
94  
95          DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(documentId);
96          assertEquals("Document should be INITIATED.", KewApiConstants.ROUTE_HEADER_INITIATED_CD, status.getCode());
97  
98          // cancel the doc, it's status should be updated
99          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 }