001 /**
002 * Copyright 2005-2011 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 */
016 package org.kuali.rice.kew.clientapp;
017
018 import org.junit.Test;
019 import org.kuali.rice.kew.actions.BlanketApproveTest;
020 import org.kuali.rice.kew.api.KewApiServiceLocator;
021 import org.kuali.rice.kew.api.WorkflowDocument;
022 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
023 import org.kuali.rice.kew.api.document.Document;
024 import org.kuali.rice.kew.api.document.DocumentStatus;
025 import org.kuali.rice.kew.api.exception.WorkflowException;
026 import org.kuali.rice.kew.test.KEWTestCase;
027 import org.kuali.rice.kew.api.KewApiConstants;
028 import org.kuali.rice.kim.api.identity.Person;
029 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
030 import org.kuali.rice.krad.UserSession;
031 import org.kuali.rice.krad.util.GlobalVariables;
032 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
033 import org.kuali.rice.test.BaselineTestCase.Mode;
034
035 import static org.junit.Assert.*;
036
037 /**
038 * This is a description of what this class does - ewestfal don't forget to fill this in.
039 *
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 *
042 */
043 @BaselineMode(Mode.CLEAR_DB)
044 public class WorkflowInfoTest extends KEWTestCase {
045
046 @Override
047 protected void loadTestData() {
048 // need this configuration to create a BlanketApproveParallelTest
049 loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml");
050 }
051
052 /**
053 * Tests the loading of a RouteHeaderVO using the WorkflowInfo.
054 *
055 * Verifies that an NPE no longer occurrs as mentioned in KULRICE-765.
056 */
057 @Test
058 public void testGetRouteHeader() throws Exception {
059 // ensure the UserSession is cleared out (could have been set up by other tests)
060 GlobalVariables.setUserSession(null);
061 String ewestfalPrincipalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("ewestfal")
062 .getPrincipalId();
063 GlobalVariables.setUserSession(new UserSession("ewestfal"));
064 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(ewestfalPrincipalId,
065 "TestDocumentType");
066 String documentId = workflowDocument.getDocumentId();
067 assertNotNull(documentId);
068
069 Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId);
070 assertNotNull(document);
071
072 assertEquals(documentId, document.getDocumentId());
073 assertEquals(DocumentStatus.INITIATED, document.getStatus());
074 }
075
076 @Test
077 public void testGetDocumentStatus() throws Exception {
078 // verify that a null document id throws an exception
079 try {
080 DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(null);
081 fail("A WorkflowException should have been thrown, instead returned status: " + status);
082 } catch (IllegalArgumentException e) {}
083
084 // verify that a bad document id throws an exception
085 try {
086 DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus("-1");
087 fail("A IllegalStateException Should have been thrown, instead returned status: " + status);
088 } catch (IllegalStateException e) {}
089
090 // now create a doc and load it's status
091 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"),
092 "TestDocumentType");
093 String documentId = document.getDocumentId();
094 assertNotNull(documentId);
095
096 DocumentStatus status = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(documentId);
097 assertEquals("Document should be INITIATED.", KewApiConstants.ROUTE_HEADER_INITIATED_CD, status.getCode());
098
099 // 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.getCode());
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 @Test
142 public void testGetAppDocStatus() throws Exception {
143 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"),
144 "TestDocumentType");
145 document.saveDocumentData();
146
147 String appDocStatus = KewApiServiceLocator.getWorkflowDocumentService().getApplicationDocumentStatus(document.getDocumentId());
148 assertNull("appDocStatus should be null", appDocStatus);
149
150 String appDocStatusValue = "Approved";
151 document.setApplicationDocumentStatus(appDocStatusValue);
152 document.saveDocumentData();
153
154 appDocStatus = KewApiServiceLocator.getWorkflowDocumentService().getApplicationDocumentStatus(document.getDocumentId());
155 assertEquals("Incorrect appDocStatus", appDocStatusValue, appDocStatus);
156 }
157
158 }