1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43 @BaselineMode(Mode.CLEAR_DB)
44 public class WorkflowInfoTest extends KEWTestCase {
45
46 @Override
47 protected void loadTestData() {
48
49 loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml");
50 }
51
52
53
54
55
56
57 @Test
58 public void testGetRouteHeader() throws Exception {
59
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
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
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
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
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
107
108
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 }