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