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 @BaselineMode(Mode.CLEAR_DB)
43 public class WorkflowInfoTest extends KEWTestCase {
44
45 @Override
46 protected void loadTestData() {
47
48 loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml");
49 }
50
51
52
53
54
55
56 @Test
57 public void testGetRouteHeader() throws Exception {
58
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
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
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
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
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
106
107
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 }