1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.docmentlink;
17
18 import java.util.List;
19 import org.apache.log4j.Logger;
20 import org.junit.Test;
21 import org.kuali.rice.kew.dto.NetworkIdDTO;
22 import org.kuali.rice.kew.dto.DocumentLinkDTO;
23 import org.kuali.rice.kew.service.WorkflowDocument;
24 import org.kuali.rice.kew.exception.WorkflowException;
25 import org.kuali.rice.kew.test.KEWTestCase;
26 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
27
28
29
30
31
32
33
34
35 public class DocumentLinkTest extends KEWTestCase{
36
37 private static final Logger LOG = Logger.getLogger(DocumentLinkTest.class);
38
39 @Test public void testAddLinkBTW2DocsSucess() throws Exception {
40 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
41
42 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
43
44 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
45 testDocLinkVO.setDestDocId(Long.valueOf(6000));
46 doc.addLinkedDocument(testDocLinkVO);
47
48 DocumentLinkDTO link1 = doc.getLinkedDocument(testDocLinkVO);
49
50 testDocLinkVO.setOrgnDocId(Long.valueOf(6000));
51 testDocLinkVO.setDestDocId(Long.valueOf(5000));
52
53 DocumentLinkDTO link2 = doc.getLinkedDocument(testDocLinkVO);
54
55 assertEquals(link1.getOrgnDocId(), link2.getDestDocId());
56 assertEquals(link2.getOrgnDocId(), link1.getDestDocId());
57
58 }
59
60 @Test public void testAddDuplicatedLinkBTW2DocsFailure() throws Exception {
61 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
62
63 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
64
65 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
66 testDocLinkVO.setDestDocId(Long.valueOf(6000));
67
68 doc.addLinkedDocument(testDocLinkVO);
69
70 List<DocumentLinkDTO> links = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
71
72 doc.addLinkedDocument(testDocLinkVO);
73
74 List<DocumentLinkDTO> links2 = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
75
76 assertEquals(links.size(), links2.size());
77
78 }
79
80 @Test public void testAddIncomplelteLinkBTW2DocsFailure() throws Exception{
81
82 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
83
84 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
85
86 try{
87 doc.addLinkedDocument(testDocLinkVO);
88 assertFalse(true);
89 }
90 catch(WorkflowRuntimeException e){
91 assertTrue(e.getMessage().contains("doc id is null"));
92 }
93
94 try{
95
96 testDocLinkVO.setOrgnDocId(Long.valueOf(6000));
97 doc.addLinkedDocument(testDocLinkVO);
98 assertFalse(true);
99 }
100 catch(WorkflowRuntimeException e){
101 assertTrue(e.getMessage().contains("doc id is null"));
102 }
103
104 }
105
106 @Test public void testGetLinkBTW2DocsSucess() throws Exception{
107
108 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
109
110 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
111
112 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
113 testDocLinkVO.setDestDocId(Long.valueOf(6000));
114 doc.addLinkedDocument(testDocLinkVO);
115
116 DocumentLinkDTO link1 = doc.getLinkedDocument(testDocLinkVO);
117
118 assertNotNull(link1);
119 assertEquals(testDocLinkVO.getOrgnDocId(), link1.getOrgnDocId());
120 assertEquals(testDocLinkVO.getDestDocId(), link1.getDestDocId());
121
122 }
123
124 @Test public void testGetLinkBTW2DocsFailure() throws Exception{
125
126 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
127
128 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
129
130 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
131 testDocLinkVO.setDestDocId(Long.valueOf(6000));
132 doc.addLinkedDocument(testDocLinkVO);
133
134 testDocLinkVO.setOrgnDocId(Long.valueOf(5001));
135
136 DocumentLinkDTO link1 = doc.getLinkedDocument(testDocLinkVO);
137
138 assertEquals(null, link1);
139
140 }
141
142 @Test public void testGetAllLinksFromOrgnDocSucess() throws Exception {
143
144 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
145 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
146
147
148
149 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
150 testDocLinkVO.setDestDocId(Long.valueOf(6000));
151 doc.addLinkedDocument(testDocLinkVO);
152
153 testDocLinkVO.setOrgnDocId(Long.valueOf(5009));
154 testDocLinkVO.setDestDocId(Long.valueOf(6009));
155 doc.addLinkedDocument(testDocLinkVO);
156
157 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
158 testDocLinkVO.setDestDocId(Long.valueOf(6003));
159 doc.addLinkedDocument(testDocLinkVO);
160
161 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
162 testDocLinkVO.setDestDocId(Long.valueOf(6004));
163
164 doc.addLinkedDocument(testDocLinkVO);
165
166 List<DocumentLinkDTO> links2 = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
167
168 assertEquals(3, links2.size());
169
170 }
171
172 @Test public void testGetAllLinksFromOrgnDocFailure()throws Exception {
173
174 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
175 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
176
177
178 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
179 testDocLinkVO.setDestDocId(Long.valueOf(6000));
180 doc.addLinkedDocument(testDocLinkVO);
181
182 testDocLinkVO.setOrgnDocId(Long.valueOf(5009));
183 testDocLinkVO.setDestDocId(Long.valueOf(6009));
184 doc.addLinkedDocument(testDocLinkVO);
185
186 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
187 testDocLinkVO.setDestDocId(Long.valueOf(6003));
188 doc.addLinkedDocument(testDocLinkVO);
189
190 List<DocumentLinkDTO> links2 = doc.getLinkedDocumentsByDocId(Long.valueOf(8000));
191
192 assertEquals(0, links2.size());
193
194 }
195
196 @Test public void testRemoveLinkBTW2DocsSucess() throws Exception{
197
198 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
199 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
200
201
202 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
203 testDocLinkVO.setDestDocId(Long.valueOf(6000));
204 doc.addLinkedDocument(testDocLinkVO);
205
206 List<DocumentLinkDTO> links1 = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
207
208 assertEquals(1, links1.size());
209
210 List<DocumentLinkDTO> links0 = doc.getLinkedDocumentsByDocId(Long.valueOf(6000));
211
212 assertEquals(1, links0.size());
213
214 doc.removeLinkedDocument(testDocLinkVO);
215
216 List<DocumentLinkDTO> links2 = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
217
218 assertEquals(0, links2.size());
219 }
220
221 @Test public void testRemoveAllLinksFromOrgnDocSucess() throws Exception {
222
223 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
224 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
225
226
227 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
228 testDocLinkVO.setDestDocId(Long.valueOf(6000));
229 doc.addLinkedDocument(testDocLinkVO);
230
231 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
232 testDocLinkVO.setDestDocId(Long.valueOf(6002));
233 doc.addLinkedDocument(testDocLinkVO);
234
235 List<DocumentLinkDTO> links01 = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
236 List<DocumentLinkDTO> links02 = doc.getLinkedDocumentsByDocId(Long.valueOf(6000));
237 List<DocumentLinkDTO> links03 = doc.getLinkedDocumentsByDocId(Long.valueOf(6002));
238
239 assertEquals(2, links01.size());
240 assertEquals(1, links02.size());
241 assertEquals(1, links03.size());
242
243
244 doc.removeLinkedDocuments(Long.valueOf(5000));
245
246 links01 = doc.getLinkedDocumentsByDocId(Long.valueOf(5000));
247 links02 = doc.getLinkedDocumentsByDocId(Long.valueOf(6000));
248 links03 = doc.getLinkedDocumentsByDocId(Long.valueOf(6002));
249
250 assertEquals(0, links01.size());
251 assertEquals(0, links02.size());
252 assertEquals(0, links03.size());
253
254 }
255
256 @Test public void testDocLinktoItself() throws Exception {
257
258 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
259
260 try{
261
262 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
263
264
265 testDocLinkVO.setOrgnDocId(Long.valueOf(5000));
266 testDocLinkVO.setDestDocId(Long.valueOf(5000));
267 doc.addLinkedDocument(testDocLinkVO);
268 fail();
269 }
270 catch(WorkflowRuntimeException ex){
271 assertTrue(ex.getMessage().contains("no self link"));
272
273 }
274 }
275
276
277 @Test public void testDocLinkClient() throws Exception {
278
279 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
280 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
281
282
283 testDocLinkVO.setOrgnDocId(Long.valueOf(5009));
284 testDocLinkVO.setDestDocId(Long.valueOf(6008));
285 doc.addLinkedDocument(testDocLinkVO);
286
287 testDocLinkVO.setOrgnDocId(Long.valueOf(5009));
288 testDocLinkVO.setDestDocId(Long.valueOf(6009));
289 doc.addLinkedDocument(testDocLinkVO);
290
291 testDocLinkVO.setOrgnDocId(Long.valueOf(5002));
292 testDocLinkVO.setDestDocId(Long.valueOf(6002));
293 doc.addLinkedDocument(testDocLinkVO);
294
295 testDocLinkVO.setOrgnDocId(Long.valueOf(5003));
296 testDocLinkVO.setDestDocId(Long.valueOf(6003));
297 doc.addLinkedDocument(testDocLinkVO);
298
299 List<DocumentLinkDTO> links = doc.getLinkedDocumentsByDocId(Long.valueOf(5009));
300
301 for(DocumentLinkDTO link : links)
302 LOG.info("******************************\t link btw:\t" + link.getOrgnDocId()+ "\t" + link.getDestDocId());
303
304
305
306 }
307
308 @Test public void testAddDocLinkWithLinkID() throws Exception {
309
310 DocumentLinkDTO testDocLinkVO = new DocumentLinkDTO();
311 WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
312
313
314 testDocLinkVO.setOrgnDocId(Long.valueOf(5009));
315 testDocLinkVO.setDestDocId(Long.valueOf(6009));
316 doc.addLinkedDocument(testDocLinkVO);
317
318 testDocLinkVO.setLinbkId(Long.valueOf(2106));
319 testDocLinkVO.setOrgnDocId(Long.valueOf(5010));
320 testDocLinkVO.setDestDocId(Long.valueOf(6010));
321 doc.addLinkedDocument(testDocLinkVO);
322
323
324
325
326
327
328
329
330 testDocLinkVO.setLinbkId(null);
331 testDocLinkVO.setOrgnDocId(Long.valueOf(5011));
332 testDocLinkVO.setDestDocId(Long.valueOf(6011));
333 doc.addLinkedDocument(testDocLinkVO);
334
335 List<DocumentLinkDTO> links = doc.getLinkedDocumentsByDocId(Long.valueOf(5009));
336
337 for(DocumentLinkDTO link : links)
338 LOG.info("******************************\t link btw:\t" + link.getOrgnDocId()+ "\t" + link.getDestDocId());
339
340
341
342 }
343 }