1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.kuali.rice.kew.api.KewApiConstants;
23 import org.kuali.rice.kew.api.WorkflowDocument;
24 import org.kuali.rice.kew.impl.document.WorkflowDocumentImpl;
25 import org.kuali.rice.krad.UserSession;
26 import org.mockito.Mockito;
27
28
29 import java.util.concurrent.*;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class SessionDocumentServiceImplTest {
48
49
50 private SessionDocumentServiceImpl sessionDocumentServiceImpl = new SessionDocumentServiceImpl();
51 private UserSession session;
52 private WorkflowDocument doc;
53 private String docId = "1";
54 private ConcurrentHashMap<String, WorkflowDocument> map = new ConcurrentHashMap<String, WorkflowDocument>();
55
56 @Before
57 public void setUp() {
58 session = Mockito.mock(UserSession.class);
59 doc = Mockito.mock(WorkflowDocumentImpl.class);
60 Mockito.when(doc.getDocumentId()).thenReturn(docId);
61 map.put(docId,doc);
62 }
63
64 @Test
65 public void testAddDocumentToUserSession() {
66 try {
67 sessionDocumentServiceImpl.addDocumentToUserSession(session, doc);
68 } catch(Exception e) {
69 Assert.fail("Exception occurred adding document to user session");
70 }
71 }
72 @Test
73 public void testGetDocumentFromSessionWithEntry() {
74 try {
75 Mockito.when(session.retrieveObject(KewApiConstants.WORKFLOW_DOCUMENT_MAP_ATTR_NAME)).thenReturn(map);
76 WorkflowDocument returnedDoc = sessionDocumentServiceImpl.getDocumentFromSession(session,docId);
77 Assert.assertEquals("Document should match mock document", doc, returnedDoc);
78 } catch(Exception e) {
79 Assert.fail("Exception occurred retrieving document to user session");
80 }
81 }
82
83 @Test
84 public void testGetDocumentFromSessionWithNoEntry() {
85 try {
86 Mockito.when(session.retrieveObject(KewApiConstants.WORKFLOW_DOCUMENT_MAP_ATTR_NAME)).thenReturn(null);
87 WorkflowDocument returnedDoc = sessionDocumentServiceImpl.getDocumentFromSession(session,docId);
88 Assert.assertNull("Document should have returned null", returnedDoc);
89 } catch(Exception e) {
90 Assert.fail("Exception occurred retrieving document to user session");
91 }
92 }
93
94 }
95