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.dto.NetworkIdDTO;
21 import org.kuali.rice.kew.dto.RouteHeaderDTO;
22 import org.kuali.rice.kew.exception.WorkflowException;
23 import org.kuali.rice.kew.service.WorkflowDocument;
24 import org.kuali.rice.kew.service.WorkflowInfo;
25 import org.kuali.rice.kew.test.KEWTestCase;
26 import org.kuali.rice.kew.util.KEWConstants;
27 import org.kuali.rice.kew.web.session.UserSession;
28 import org.kuali.rice.kim.bo.Person;
29 import org.kuali.rice.kim.service.KIMServiceLocator;
30
31
32
33
34
35
36
37
38 public class WorkflowInfoTest extends KEWTestCase {
39
40 @Override
41 protected void loadTestData() {
42
43 loadXmlFile(BlanketApproveTest.class, "ActionsConfig.xml");
44 }
45
46
47
48
49
50
51 @Test
52 public void testGetRouteHeader() throws Exception {
53
54 UserSession.setAuthenticatedUser(null);
55 String ewestfalPrincipalId = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("ewestfal").getPrincipalId();
56 UserSession.setAuthenticatedUser(new UserSession(ewestfalPrincipalId));
57 WorkflowDocument document = new WorkflowDocument(ewestfalPrincipalId, "TestDocumentType");
58 Long documentId = document.getRouteHeaderId();
59 assertNotNull(documentId);
60
61 RouteHeaderDTO routeHeaderVO = new WorkflowInfo().getRouteHeader(documentId);
62 assertNotNull(routeHeaderVO);
63
64 assertEquals(documentId, routeHeaderVO.getRouteHeaderId());
65 assertEquals(KEWConstants.ROUTE_HEADER_INITIATED_CD, routeHeaderVO.getDocRouteStatus());
66 }
67
68 @Test
69 public void testGetDocumentStatus() throws Exception {
70 WorkflowInfo info = new WorkflowInfo();
71
72 try {
73 String status = info.getDocumentStatus(null);
74 fail("A WorkflowException should have been thrown, instead returned status: " + status);
75 } catch (WorkflowException e) {
76 } catch (IllegalArgumentException e) {
77 }
78
79 try {
80 String status = info.getDocumentStatus(new Long(-1));
81 fail("A WorkflowException Should have been thrown, instead returned status: " + status);
82 } catch (WorkflowException e) {}
83
84
85 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), "TestDocumentType");
86 Long documentId = document.getRouteHeaderId();
87 assertNotNull(documentId);
88
89 String status = info.getDocumentStatus(documentId);
90 assertEquals("Document should be INITIATED.", KEWConstants.ROUTE_HEADER_INITIATED_CD, status);
91
92
93 document.cancel("");
94 status = info.getDocumentStatus(documentId);
95 assertEquals("Document should be CANCELED.", KEWConstants.ROUTE_HEADER_CANCEL_CD, status);
96 }
97
98
99
100
101
102
103 @Test
104 public void testBlanketApproverSubmitted() throws WorkflowException {
105 Person blanketApprover = KIMServiceLocator.getPersonService().getPersonByPrincipalName("ewestfal");
106
107 WorkflowDocument document = new WorkflowDocument(blanketApprover.getPrincipalId(), "BlanketApproveParallelTest");
108 document.blanketApprove("");
109
110 String routedByPrincipalId = new WorkflowInfo().getDocumentRoutedByPrincipalId(document.getRouteHeaderId());
111 assertEquals("the blanket approver should be the routed by", blanketApprover.getPrincipalId(), routedByPrincipalId);
112 }
113
114 @Test
115 public void testGetAppDocId() throws Exception {
116 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), "TestDocumentType");
117 document.saveRoutingData();
118
119 String appDocId = new WorkflowInfo().getAppDocId(document.getRouteHeaderId());
120 assertNull("appDocId should be null", appDocId);
121
122 String appDocIdValue = "1234";
123 document.setAppDocId(appDocIdValue);
124 document.saveRoutingData();
125
126 appDocId = new WorkflowInfo().getAppDocId(document.getRouteHeaderId());
127 assertEquals("Incorrect appDocId", appDocIdValue, appDocId);
128 }
129
130 }