View Javadoc
1   /**
2    * Copyright 2005-2014 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.actions;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.api.WorkflowDocument;
20  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
21  import org.kuali.rice.kew.api.action.ActionRequestType;
22  import org.kuali.rice.kew.test.KEWTestCase;
23  import org.kuali.rice.kew.api.KewApiConstants;
24  import org.kuali.rice.kim.api.KimConstants;
25  
26  import static org.junit.Assert.assertTrue;
27  import static org.junit.Assert.fail;
28  
29  /**
30   *
31   * @author delyea
32   */
33  public class AcknowledgeActionTest extends KEWTestCase {
34  
35      private String getSavedStatusDisplayValue() {
36          return (String) KewApiConstants.DOCUMENT_STATUSES.get(KewApiConstants.ROUTE_HEADER_SAVED_CD);
37      }
38  
39      @Test public void testSavedDocumentAdhocRequest() throws Exception {
40          WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "TestDocumentType");
41          doc.saveDocument("");
42          doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false);
43          String userId = getPrincipalIdForName("dewey");
44          doc = WorkflowDocumentFactory.loadDocument(userId, doc.getDocumentId());
45          assertTrue("Acknowledge should be requested of user " + userId, doc.isAcknowledgeRequested());
46          try {
47              doc.acknowledge("");
48          } catch (Exception e) {
49              fail("A non-initator with an Ack request should be allowed to take the Ack action on a " + getSavedStatusDisplayValue() + " document");
50          }
51          assertTrue("Document should be " + getSavedStatusDisplayValue(), doc.isSaved());
52  
53          String workgroupUserId = getPrincipalIdForName("dewey");
54          doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "TestDocumentType");
55          doc.saveDocument("");
56  
57          doc.adHocToGroup(ActionRequestType.ACKNOWLEDGE, "annotation1", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "NonSIT"), "respDesc1", false);
58          doc = WorkflowDocumentFactory.loadDocument(workgroupUserId, doc.getDocumentId());
59          assertTrue("Acknowledge should be requested of user " + workgroupUserId, doc.isAcknowledgeRequested());
60          try {
61              doc.acknowledge("");
62          } catch (Exception e) {
63              fail("A non-initator with an Ack request should be allowed to take the Ack action on a " + getSavedStatusDisplayValue() + " document");
64          }
65          assertTrue("Document should be " + getSavedStatusDisplayValue(), doc.isSaved());
66      }
67  }