1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service;
17
18 import org.junit.Test;
19 import org.kuali.rice.kew.api.WorkflowDocument;
20 import org.kuali.rice.krad.UserSession;
21 import org.kuali.rice.krad.test.document.AccountRequestDocument;
22 import org.kuali.rice.krad.util.GlobalVariables;
23 import org.kuali.rice.krad.util.MessageMap;
24 import org.kuali.rice.krad.test.KRADTestCase;
25
26 import static org.junit.Assert.assertEquals;
27
28
29
30
31
32
33
34 public class DocumentServiceTest extends KRADTestCase {
35
36 public DocumentServiceTest() {
37 }
38
39 @Override
40 public void setUp() throws Exception {
41 super.setUp();
42 GlobalVariables.setMessageMap(new MessageMap());
43 GlobalVariables.setUserSession(new UserSession("quickstart"));
44 }
45
46 @Override
47 public void tearDown() throws Exception {
48 GlobalVariables.setMessageMap(new MessageMap());
49 GlobalVariables.setUserSession(null);
50 super.tearDown();
51 }
52
53
54
55
56
57
58 @Test public void testGetNewDocument() throws Exception {
59 AccountRequestDocument travelDocument = (AccountRequestDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountRequest");
60 WorkflowDocument wd = travelDocument.getDocumentHeader().getWorkflowDocument();
61
62 assertEquals("Initiator should be the current user", wd.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPerson().getPrincipalId());
63 }
64
65
66
67
68
69
70 @Test public void testGetNewDocumentDifferentInitiatorThanCurrentUser() throws Exception {
71 AccountRequestDocument travelDocument = (AccountRequestDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountRequest", "testuser1");
72 WorkflowDocument wd = travelDocument.getDocumentHeader().getWorkflowDocument();
73
74 assertEquals("Initiator should be testuser1", wd.getInitiatorPrincipalId(), "testuser1");
75 }
76
77
78
79
80
81
82 @Test public void testGetNewDocumentInvalidInitiator() throws Exception {
83 AccountRequestDocument travelDocument = (AccountRequestDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountRequest", "notValidUserAtAll");
84 WorkflowDocument wd = travelDocument.getDocumentHeader().getWorkflowDocument();
85
86 assertEquals("Initiator should be the current user", wd.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPerson().getPrincipalId());
87 }
88 }