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 static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import java.util.List;
24
25 import org.apache.log4j.Logger;
26 import org.junit.Test;
27 import org.kuali.rice.kew.api.KewApiServiceLocator;
28 import org.kuali.rice.kew.api.document.DocumentLink;
29 import org.kuali.rice.kew.api.document.WorkflowDocumentService;
30 import org.kuali.rice.kew.test.KEWTestCase;
31 import org.kuali.rice.test.BaselineTestCase;
32
33
34
35
36
37
38
39 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
40 public class DocumentLinkTest extends KEWTestCase {
41
42 private static final Logger LOG = Logger.getLogger(DocumentLinkTest.class);
43
44 private WorkflowDocumentService service;
45
46 @Override
47 protected void setUpAfterDataLoad() throws Exception {
48 super.setUpAfterDataLoad();
49 this.service = KewApiServiceLocator.getWorkflowDocumentService();
50 }
51
52 @Test public void testAddLinkBTW2DocsSucess() throws Exception {
53
54
55 DocumentLink testDocLink1 = DocumentLink.Builder.create("5000", "6000").build();
56
57
58 testDocLink1 = service.addDocumentLink(testDocLink1);
59 assertNotNull(testDocLink1.getId());
60 assertEquals("5000", testDocLink1.getOriginatingDocumentId());
61 assertEquals("6000", testDocLink1.getDestinationDocumentId());
62
63
64 List<DocumentLink> outgoingLinks = service.getOutgoingDocumentLinks("6000");
65 assertEquals(1, outgoingLinks.size());
66 DocumentLink testDocLink2 = outgoingLinks.get(0);
67
68 assertEquals(testDocLink1.getOriginatingDocumentId(), testDocLink2.getDestinationDocumentId());
69 assertEquals(testDocLink2.getOriginatingDocumentId(), testDocLink1.getDestinationDocumentId());
70
71 }
72
73 @Test public void testAddDuplicatedLinkBTW2DocsFailure() throws Exception {
74
75 DocumentLink testDocLink = DocumentLink.Builder.create("5000", "6000").build();
76
77 DocumentLink testDocLinkAdded = service.addDocumentLink(testDocLink);
78 assertNotNull(testDocLinkAdded);
79 assertNotNull(testDocLinkAdded.getId());
80
81 List<DocumentLink> links1 = service.getOutgoingDocumentLinks("5000");
82 assertEquals(1, links1.size());
83
84 DocumentLink testDocLinkAdded2 = service.addDocumentLink(testDocLink);
85 assertNotNull(testDocLinkAdded);
86 assertNotNull(testDocLinkAdded.getId());
87 assertEquals(testDocLinkAdded2, testDocLinkAdded);
88
89 List<DocumentLink> links2 = service.getOutgoingDocumentLinks("5000");
90 assertEquals(1, links2.size());
91
92 assertEquals(links1.size(), links2.size());
93
94 }
95
96 @Test public void testAddIncomplelteLinkBTW2DocsFailure() throws Exception {
97
98 try {
99 DocumentLink.Builder.create(null, null);
100 fail();
101 } catch (IllegalArgumentException e) {}
102
103 try{
104 DocumentLink.Builder.create("6000", null);
105 fail();
106 } catch (IllegalArgumentException e){
107 assertTrue(e.getMessage().contains("was null or blank"));
108 }
109
110 }
111
112 @Test public void testGetLinkBTW2DocsSucess() throws Exception {
113
114 DocumentLink testDocLink = DocumentLink.Builder.create("5000", "6000").build();
115
116 DocumentLink link1 = service.addDocumentLink(testDocLink);
117
118
119 link1 = service.getDocumentLink(link1.getId());
120
121 assertNotNull(link1);
122 assertEquals(testDocLink.getOriginatingDocumentId(), link1.getOriginatingDocumentId());
123 assertEquals(testDocLink.getDestinationDocumentId(), link1.getDestinationDocumentId());
124
125 }
126
127 @Test public void testGetLinkBTW2DocsFailure() throws Exception {
128
129
130 DocumentLink testDocLink = DocumentLink.Builder.create("5000", "6000").build();
131
132 service.addDocumentLink(testDocLink);
133
134 List<DocumentLink> links = service.getOutgoingDocumentLinks("5001");
135
136 assertTrue(links.isEmpty());
137
138 }
139
140 @Test public void testGetAllLinksFromOrgnDocSucess() throws Exception {
141
142 DocumentLink link1 = DocumentLink.Builder.create("5000", "6000").build();
143 service.addDocumentLink(link1);
144
145 DocumentLink link2 = DocumentLink.Builder.create("5009", "6009").build();
146 service.addDocumentLink(link2);
147
148 DocumentLink link3 = DocumentLink.Builder.create("5000", "6003").build();
149 service.addDocumentLink(link3);
150
151 DocumentLink link4 = DocumentLink.Builder.create("5000", "6004").build();
152 service.addDocumentLink(link4);
153
154 List<DocumentLink> links = service.getOutgoingDocumentLinks("5000");
155 assertEquals(3, links.size());
156
157 }
158
159 @Test public void testGetAllLinksFromOrgnDocFailure()throws Exception {
160
161 DocumentLink link1 = DocumentLink.Builder.create("5000", "6000").build();
162 service.addDocumentLink(link1);
163
164 DocumentLink link2 = DocumentLink.Builder.create("5009", "6009").build();
165 service.addDocumentLink(link2);
166
167 DocumentLink link3 = DocumentLink.Builder.create("5000", "6003").build();
168 service.addDocumentLink(link3);
169
170 List<DocumentLink> links = service.getOutgoingDocumentLinks("8000");
171
172 assertEquals(0, links.size());
173
174 }
175
176 @Test public void testRemoveLinkBTW2DocsSucess() throws Exception{
177
178 DocumentLink link1 = DocumentLink.Builder.create("5000", "6000").build();
179 link1 = service.addDocumentLink(link1);
180
181 List<DocumentLink> links1 = service.getOutgoingDocumentLinks("5000");
182
183 assertEquals(1, links1.size());
184
185 List<DocumentLink> links2 = service.getOutgoingDocumentLinks("6000");
186
187 assertEquals(1, links2.size());
188
189 DocumentLink deletedLink = service.deleteDocumentLink(link1.getId());
190 assertNotNull(deletedLink);
191
192 List<DocumentLink> links3 = service.getOutgoingDocumentLinks("5000");
193
194 assertEquals(0, links3.size());
195 }
196
197 @Test public void testRemoveAllLinksFromOrgnDocSucess() throws Exception {
198
199 DocumentLink link1 = DocumentLink.Builder.create("5000", "6000").build();
200 link1 = service.addDocumentLink(link1);
201
202 DocumentLink link2 = DocumentLink.Builder.create("5000", "6002").build();
203 link2 = service.addDocumentLink(link2);
204
205 List<DocumentLink> links01 = service.getOutgoingDocumentLinks("5000");
206 List<DocumentLink> links02 = service.getOutgoingDocumentLinks("6000");
207 List<DocumentLink> links03 = service.getOutgoingDocumentLinks("6002");
208
209 assertEquals(2, links01.size());
210 assertEquals(1, links02.size());
211 assertEquals(1, links03.size());
212
213
214 List<DocumentLink> deletedDocuments = service.deleteDocumentLinksByDocumentId("5000");
215 assertEquals(2, deletedDocuments.size());
216
217 links01 = service.getOutgoingDocumentLinks("5000");
218 links02 = service.getOutgoingDocumentLinks("6000");
219 links03 = service.getOutgoingDocumentLinks("6002");
220
221 assertEquals(0, links01.size());
222 assertEquals(0, links02.size());
223 assertEquals(0, links03.size());
224
225 }
226
227 @Test public void testDocLinktoItself() throws Exception {
228 try{
229 DocumentLink.Builder.create("5000", "5000");
230 fail();
231 } catch(IllegalArgumentException e){
232 assertTrue(e.getMessage().contains("cannot link a document with itself"));
233 }
234 }
235
236 }