View Javadoc
1   /*
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.rice.kew.impl.document;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.junit.Test;
21  import org.kuali.rice.kew.api.KewApiConstants;
22  import org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue;
23  import org.kuali.rice.kew.docsearch.SearchableAttributeStringValue;
24  import org.kuali.rice.kew.doctype.bo.DocumentType;
25  import org.kuali.rice.kew.documentlink.DocumentLink;
26  import org.kuali.rice.kew.engine.node.Branch;
27  import org.kuali.rice.kew.engine.node.BranchState;
28  import org.kuali.rice.kew.engine.node.NodeState;
29  import org.kuali.rice.kew.engine.node.RouteNode;
30  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
31  import org.kuali.rice.kew.notes.Attachment;
32  import org.kuali.rice.kew.notes.Note;
33  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValueContent;
35  import org.kuali.rice.kew.routeheader.DocumentStatusTransition;
36  import org.kuali.rice.kew.service.KEWServiceLocator;
37  import org.kuali.rice.kew.test.KEWTestCase;
38  import org.kuali.rice.krad.data.KradDataServiceLocator;
39  import org.kuali.rice.krad.data.PersistenceOption;
40  import org.kuali.rice.krad.service.KRADServiceLocator;
41  import org.kuali.rice.test.TestHarnessServiceLocator;
42  import org.springframework.dao.OptimisticLockingFailureException;
43  import org.springframework.jdbc.core.JdbcTemplate;
44  
45  import java.sql.Timestamp;
46  import java.util.ArrayList;
47  import java.util.Collection;
48  import java.util.Date;
49  import java.util.List;
50  
51  import static org.junit.Assert.*;
52  
53  /**
54   * Tests to confirm JPA mapping for the Kew module Document data objects
55   */
56  public class KewDocumentDataJpaTest extends KEWTestCase {
57      public static final String TEST_DOC_ID = "1234";
58      public static final String SEARCHABLE_ATTR_ID = "1000";
59      public static final String SEARCHABLE_ATTR_KEY = "testAttribute";
60      public static final String SEARCHABLE_ATTR_VAL = "testing";
61      public static final Timestamp SEARCHABLE_ATTR_VAL_DT = new Timestamp(System.currentTimeMillis());
62  
63      public static final String DOC_CNT = "<xml>some content</xml>";
64      public static final String NOTE_TXT = "noteText";
65  
66      @Test
67      public void testDocumentContentFetchAndSave() throws Exception{
68          DocumentRouteHeaderValueContent dc = setupDocumentValueContent();
69          assertTrue("DocumentRouteHeaderContent persisted", dc != null && StringUtils.equals(TEST_DOC_ID,
70                  dc.getDocumentId()) && StringUtils.equals(dc.getDocumentContent(),DOC_CNT));
71  
72          dc = KRADServiceLocator.getDataObjectService().find(DocumentRouteHeaderValueContent.class,TEST_DOC_ID);
73          assertTrue("DocumentRouteHeaderContent refetched", dc != null && StringUtils.equals(TEST_DOC_ID,
74                  dc.getDocumentId()) && StringUtils.equals(dc.getDocumentContent(),DOC_CNT));
75      }
76  
77      @Test
78      public void testDocumentRouteHeaderValueFindByDocumentId() throws Exception{
79          DocumentRouteHeaderValue savedVal = setupDocumentRouteHeaderValue();
80          DocumentRouteHeaderValue fetchedVal = KEWServiceLocator.getRouteHeaderService().
81                                              getRouteHeader(savedVal.getDocumentId(), true);
82          assertTrue("getRouteHeader fetched correctly",fetchedVal != null &&
83                  StringUtils.equals(fetchedVal.getDocumentId(),savedVal.getDocumentId()));
84  
85      }
86  
87      @Test
88      public void testDocumentRouteHeaderValueGetRouteHeaders() throws Exception{
89          DocumentRouteHeaderValue savedRouteHeader = setupDocumentRouteHeaderValue();
90          setupDocumentRouteHeaderValueWithRouteHeaderAssigned();
91          List<String> documentIds = new ArrayList<String>();
92          documentIds.add(TEST_DOC_ID);
93          documentIds.add(savedRouteHeader.getDocumentId());
94  
95          Collection<DocumentRouteHeaderValue> routeHeaders =
96                  KEWServiceLocator.getRouteHeaderService().getRouteHeaders(documentIds,true);
97          assertTrue("getRouteHeaders fetched",routeHeaders != null && routeHeaders.size() == 2);
98      }
99  
100     @Test
101     public void testDocumentRouteHeaderValueLockRouteHeader() throws Exception{
102         DocumentRouteHeaderValue dv = setupDocumentRouteHeaderValue();
103         KEWServiceLocator.getRouteHeaderService().lockRouteHeader(dv.getDocumentId());
104         dv = KEWServiceLocator.getRouteHeaderService().getRouteHeader(dv.getDocumentId());
105         dv.setAppDocStatus("X");
106         KEWServiceLocator.getRouteHeaderService().saveRouteHeader(dv);
107     }
108 
109     @Test
110     public void testDocumentRouteHeaderValueSaveRouteHeader() throws Exception{
111         DocumentRouteHeaderValue dv = setupDocumentRouteHeaderValue();
112         dv.setAppDocStatus("X");
113         KEWServiceLocator.getRouteHeaderService().saveRouteHeader(dv);
114         assertTrue("saveRouteHeader saved correctly",StringUtils.equals(dv.getAppDocStatus(),"X"));
115     }
116 
117     @Test(expected = OptimisticLockingFailureException.class)
118     public void testDocumentRouteHeaderValueSaveRouteHeaderThrowsOptimisticException() throws Exception{
119         DocumentRouteHeaderValue dv = setupDocumentRouteHeaderValue();
120         dv.setVersionNumber(null);
121         KEWServiceLocator.getRouteHeaderService().saveRouteHeader(dv);
122         fail();
123     }
124 
125     @Test
126     public void testDocumentRouteHeaderValueDelete() throws Exception{
127         DocumentRouteHeaderValue dv = setupDocumentRouteHeaderValueWithRouteHeaderAssigned();
128 
129         KEWServiceLocator.getRouteHeaderService().deleteRouteHeader(dv);
130         dv = KEWServiceLocator.getRouteHeaderService().getRouteHeader(dv.getDocumentId());
131         assertTrue("Route Header deleted", dv == null);
132     }
133 
134     @Test
135     public void testDocumentRouteHeaderValueGetNextDocumentId() throws Exception{
136         String val = KEWServiceLocator.getRouteHeaderService().getNextDocumentId();
137         assertTrue("Next value found",StringUtils.isNotEmpty(val));
138     }
139 
140     @Test
141     public void testDocumentRouteHeaderValueClearRouteHeaderSearchValues() throws Exception{
142         setupDocumentRouteHeaderValueWithRouteHeaderAssigned();
143         setupSearchAttributeStringValue();
144         KEWServiceLocator.getRouteHeaderService().clearRouteHeaderSearchValues(TEST_DOC_ID);
145     }
146     @Test
147     public void testDocumentRouteHeaderValueHasSearchableAttributeValue() throws Exception{
148         setupSearchAttributeStringValue();
149         setupSearchAttributeDateTimeValue();
150 
151         boolean hasSAValue = KEWServiceLocator.getRouteHeaderService().hasSearchableAttributeValue(TEST_DOC_ID,
152                 SEARCHABLE_ATTR_KEY,SEARCHABLE_ATTR_VAL);
153         assertTrue("hasSearchableAttributeValue found", hasSAValue == true);
154     }
155 
156 
157     @Test
158     public void testDocumentStatusTransition() throws Exception{
159         DocumentRouteHeaderValue documentRouteHeaderValue = setupDocumentRouteHeaderValueWithRouteHeaderAssigned();
160         DocumentStatusTransition documentStatusTransition = setupDocumentStatusTransition();
161         //Modify status
162         documentRouteHeaderValue.getAppDocStatusHistory().add(documentStatusTransition);
163         documentStatusTransition.setOldAppDocStatus("R");
164 
165 
166         assertTrue("Document Status Transition saved and persisted",
167                 documentStatusTransition != null && StringUtils.isNotEmpty(
168                         documentStatusTransition.getStatusTransitionId()));
169 
170         DocumentStatusTransition fetchedVal = KRADServiceLocator.getDataObjectService().
171                 find(DocumentStatusTransition.class, documentStatusTransition.getStatusTransitionId());
172         assertTrue("DocumentStatusTransition fetched after save",fetchedVal != null &&
173                 StringUtils.equals(fetchedVal.getDocumentId(),fetchedVal.getDocumentId()));
174 
175         KRADServiceLocator.getDataObjectService().save(documentRouteHeaderValue);
176         DocumentRouteHeaderValue newHeaderVal = KRADServiceLocator.getDataObjectService().find(
177                 DocumentRouteHeaderValue.class,documentRouteHeaderValue.getDocumentId());
178 
179                 assertTrue("On fetch app doc history updated", newHeaderVal != null &&
180                 StringUtils.equals(newHeaderVal.getAppDocStatusHistory().get(0).getOldAppDocStatus(),"R"));
181     }
182 
183     @Test
184     public void testBranchState() throws Exception {
185         Branch branch = setupRouteBranch();
186         branch = setupRouteBranchState(branch);
187         assertTrue("BranchState persisted", branch != null &&
188                branch.getBranchState() != null &&
189                     StringUtils.isNotBlank(branch.getBranchState().get(0).getBranchStateId()));
190         branch= KradDataServiceLocator.getDataObjectService().find(
191                 Branch.class,branch.getBranchId());
192         assertTrue("BranchState fetched",branch != null && branch.getBranchState().get(0) != null);
193 
194     }
195 
196     @Test
197     public void testRouteHeaderInitJoinTable() throws Exception{
198         DocumentRouteHeaderValue dv = setupDocumentRouteHeaderValueWithRouteHeaderAssigned();
199         DocumentType documentType = setupDocumentType();
200         RouteNode rn = setupRouteNode(documentType);
201         RouteNodeInstance rni = setupRouteNodeInstance(rn);
202         setupInitialRouteNodeInstancesJoinTable(rni.getRouteNodeInstanceId());
203         dv = KradDataServiceLocator.getDataObjectService().find(DocumentRouteHeaderValue.class,
204                 TEST_DOC_ID);
205 
206         dv.getInitialRouteNodeInstances().add(rni);
207 
208 
209         assertTrue("DocumentRouteHeaderValue fetched correctly with joined instance",dv!= null
210                 && dv.getInitialRouteNodeInstances() != null && dv.getInitialRouteNodeInstances().get(0)!= null
211                 && StringUtils.equals(dv.getInitialRouteNodeInstances().get(0).getRouteNodeInstanceId(),
212                 rni.getRouteNodeInstanceId()));
213 
214     }
215 
216     @Test
217     public void testBranch() throws Exception {
218         Branch b = setupRouteBranch();
219         assertTrue("branch persisted correctly", b != null && StringUtils.isNotBlank(b.getBranchId())
220                 && b.getLockVerNbr() > 0);
221     }
222 
223     @Test
224     public void testNodeStates() throws Exception{
225         DocumentType documentType = setupDocumentType();
226         RouteNode rn = setupRouteNode(documentType);
227         RouteNodeInstance savedVal = setupRouteNodeInstance(rn);
228         NodeState ns = setupNodeState(savedVal);
229         savedVal.getState().add(ns);
230         KRADServiceLocator.getDataObjectService().save(savedVal);
231         assertTrue("RouteNodeInstance saved and persisted", savedVal != null && StringUtils.isNotEmpty(
232                 savedVal.getRouteNodeInstanceId()));
233 
234         savedVal = KRADServiceLocator.getDataObjectService().find(RouteNodeInstance.class,
235                 savedVal.getRouteNodeInstanceId());
236         assertTrue("NodeStates fetched correctly", savedVal.getState() != null && savedVal.getState().size() == 1);
237     }
238 
239     @Test
240     public void testRouteNodeInstance() throws Exception{
241         DocumentType documentType = setupDocumentType();
242         RouteNode rn = setupRouteNode(documentType);
243         RouteNodeInstance savedVal = setupRouteNodeInstance(rn);
244         assertTrue("DocumentRouteHeaderValue saved and persisted", savedVal != null && StringUtils.isNotEmpty(
245                 savedVal.getRouteNodeInstanceId()));
246 
247         RouteNodeInstance fetchedValue = KRADServiceLocator.getDataObjectService().
248                 find(RouteNodeInstance.class, savedVal.getRouteNodeInstanceId());
249         assertTrue("DocumentRouteHeaderValue fetched after save",fetchedValue != null &&
250                 StringUtils.equals(savedVal.getDocumentId(),fetchedValue.getDocumentId()));
251 
252     }
253 
254     @Test
255     public void testNote() throws Exception{
256         Note note = setupNote();
257         assertTrue("Note persisted correctly",note != null && StringUtils.isNotBlank(note.getNoteId()));
258         note.setNoteText("ModifiedText");
259         KRADServiceLocator.getDataObjectService().save(note);
260         note = KRADServiceLocator.getDataObjectService().find(Note.class,note.getNoteId());
261         assertTrue("Note persisted correctly",note != null && StringUtils.equals(note.getNoteText(), "ModifiedText"));
262     }
263 
264     @Test
265     public void testNoteService() throws Exception{
266         Note note = setupNote();
267         assertTrue("Note persisted correctly",note != null && StringUtils.isNotBlank(note.getNoteId()));
268         List<Note> notes = KEWServiceLocator.getNoteService().getNotesByDocumentId(TEST_DOC_ID);
269         assertTrue("getNotesByDocumentId fetched correctly",notes != null && notes.size() == 1);
270     }
271 
272     @Test
273     public void testAttachment() throws Exception {
274         Note note = setupNote();
275         Attachment attachment = setupAttachment(note);
276         note.getAttachments().add(attachment);
277 
278         assertTrue("Attachment persisted correctly", attachment != null &&
279                         StringUtils.isNotBlank(attachment.getAttachmentId()));
280         note = KEWServiceLocator.getNoteService().getNoteByNoteId(note.getNoteId());
281         assertTrue("Attachment fetched on note fetch",note != null && note.getAttachments() != null &&
282                        note.getAttachments().size() == 1 &&
283                 StringUtils.equals(note.getAttachments().get(0).getAttachmentId(),attachment.getAttachmentId()));
284     }
285 
286     @Test
287     public void testDocumentLink() throws Exception{
288         DocumentLink documentLink = setupDocumentLink(TEST_DOC_ID,"9999");
289         assertTrue("documentlink persisted correctly", documentLink != null &&
290                     StringUtils.isNotBlank(documentLink.getDocLinkId()));
291         KEWServiceLocator.getDocumentLinkService().deleteDocumentLink(documentLink);
292         documentLink = KRADServiceLocator.getDataObjectService().find(DocumentLink.class,documentLink.getDocLinkId());
293         assertTrue("documentlink was deleted",documentLink == null);
294 
295     }
296 
297     @Test
298     public void testRouteNodeServiceDeleteByRouteNodeInstance() throws Exception{
299         DocumentType documentType = setupDocumentType();
300         RouteNode rn = setupRouteNode(documentType);
301         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
302         routeNodeInstance.setRouteNode(rn);
303         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
304         assertTrue("Route node instance persisted with route node",
305                 routeNodeInstance != null && StringUtils.isNotBlank(routeNodeInstance.getRouteNodeId()));
306         String routeNodeInstanceId = routeNodeInstance.getRouteNodeInstanceId();
307         KEWServiceLocator.getRouteNodeService().deleteByRouteNodeInstance(routeNodeInstance);
308         routeNodeInstance = KradDataServiceLocator.getDataObjectService().find(RouteNodeInstance.class,
309                 routeNodeInstanceId);
310         assertTrue("RouteNodeInstanceDeleted successfully", routeNodeInstance == null);
311 
312     }
313 
314     @Test
315     public void testRouteNodeServiceGetActiveNodeInstances() throws Exception{
316         DocumentType documentType = setupDocumentType();
317         RouteNode rn = setupRouteNode(documentType);
318         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
319         routeNodeInstance.setRouteNode(rn);
320         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
321         assertTrue("Route node instance persisted with route node",
322                 routeNodeInstance != null && StringUtils.isNotBlank(routeNodeInstance.getRouteNodeId()));
323         List<RouteNodeInstance> routeNodeInstances = KEWServiceLocator.getRouteNodeService().
324                                     getActiveNodeInstances(routeNodeInstance.getDocumentId());
325         assertTrue("Route node instances found", routeNodeInstances != null && routeNodeInstances.size() == 1);
326     }
327 
328     @Test
329     public void testRouteNodeServiceGetCurrentRouteNodeNames() throws Exception{
330         DocumentType documentType = setupDocumentType();
331         RouteNode rn = setupRouteNode(documentType);
332         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
333         routeNodeInstance.setRouteNode(rn);
334         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
335         assertTrue("Route node instance persisted with route node",
336                 routeNodeInstance != null && StringUtils.isNotBlank(routeNodeInstance.getRouteNodeId()));
337         List<String> routeNodeNames = KEWServiceLocator.getRouteNodeService().
338                 getCurrentRouteNodeNames(routeNodeInstance.getDocumentId());
339         assertTrue("Route node instances found", routeNodeNames != null && routeNodeNames.size() == 1);
340 
341     }
342 
343     @Test
344     public void testRouteNodeServiceGetActiveRouteNodeNames() throws Exception{
345         DocumentType documentType = setupDocumentType();
346         RouteNode rn = setupRouteNode(documentType);
347         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
348         routeNodeInstance.setRouteNode(rn);
349         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
350         assertTrue("Route node instance persisted with route node",
351                 routeNodeInstance != null && StringUtils.isNotBlank(routeNodeInstance.getRouteNodeId()));
352         List<String> routeNodeNames = KEWServiceLocator.getRouteNodeService().
353                 getActiveRouteNodeNames(routeNodeInstance.getDocumentId());
354         assertTrue("Route node instances found", routeNodeNames != null && routeNodeNames.size() == 1);
355     }
356 
357     @Test
358     public void testRouteNodeServiceGetTerminalNodeInstances() throws Exception{
359         DocumentType documentType = setupDocumentType();
360         RouteNode rn = setupRouteNode(documentType);
361         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
362         routeNodeInstance.setActive(false);
363         routeNodeInstance.setComplete(true);
364         routeNodeInstance.setRouteNode(rn);
365         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
366         assertTrue("Route node instance persisted with route node",
367                 routeNodeInstance != null && StringUtils.isNotBlank(routeNodeInstance.getRouteNodeId()));
368         List<RouteNodeInstance> routeNodeList = KEWServiceLocator.getRouteNodeService().
369                 getTerminalNodeInstances(routeNodeInstance.getDocumentId());
370         assertTrue("Route node instances found", routeNodeList != null && routeNodeList.size() == 1);
371 
372         List<String> routeNodeNames = KEWServiceLocator.getRouteNodeService().getTerminalRouteNodeNames(
373                                     routeNodeInstance.getDocumentId());
374         assertTrue("Route node instances found", routeNodeNames != null && routeNodeNames.size() == 1);
375 
376     }
377 
378     @Test
379     public void testRouteNodeServiceGetInitialNodeInstances() throws Exception{
380         DocumentType documentType = setupDocumentType();
381         RouteNode rn = setupRouteNode(documentType);
382         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
383         routeNodeInstance.setRouteNode(rn);
384         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
385 
386         assertTrue("Route node instance persisted with route node",
387                 routeNodeInstance != null && StringUtils.isNotBlank(routeNodeInstance.getRouteNodeId()));
388         DocumentRouteHeaderValue drv = setupDocumentRouteHeaderValueWithRouteHeaderAssigned();
389         drv.getInitialRouteNodeInstances().add(routeNodeInstance);
390         KRADServiceLocator.getDataObjectService().save(drv);
391 
392         List<RouteNodeInstance> routeNodeInstances = KEWServiceLocator.getRouteNodeService().getInitialNodeInstances(
393                                                     routeNodeInstance.getDocumentId());
394         assertTrue("Route node instances found", routeNodeInstances != null && routeNodeInstances.size() == 1);
395     }
396 
397     @Test
398     public void testRouteNodeServiceFindNodeState() throws Exception{
399         DocumentType documentType = setupDocumentType();
400         RouteNode rn = setupRouteNode(documentType);
401         RouteNodeInstance routeNodeInstance = setupRouteNodeInstance(rn);
402         routeNodeInstance.setRouteNode(rn);
403         routeNodeInstance = KRADServiceLocator.getDataObjectService().save(routeNodeInstance);
404         NodeState nodeState = setupNodeState(routeNodeInstance);
405         assertTrue("Node state is persisted", nodeState != null && StringUtils.isNotBlank(nodeState.getNodeStateId()));
406         String nodeStateId = nodeState.getNodeStateId();
407         nodeState = KEWServiceLocator.getRouteNodeService().findNodeState(
408                 Long.parseLong(routeNodeInstance.getRouteNodeInstanceId()),nodeState.getKey());
409         assertTrue("Node state is found", nodeState != null && StringUtils.equals(
410                     nodeStateId,nodeState.getNodeStateId()));
411     }
412 
413     @Test
414     public void testRouteNodeServiceFindRouteNodeByName() throws Exception{
415         DocumentType documentType = setupDocumentType();
416         RouteNode rn = setupRouteNode(documentType);
417         String routeNodeId = rn.getRouteNodeId();
418         rn = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(
419                                         rn.getDocumentTypeId(),rn.getRouteNodeName());
420         assertTrue("Route node fetched correctly", rn != null && StringUtils.equals(routeNodeId,rn.getRouteNodeId()));
421 
422     }
423 
424     @Test
425     public void testRouteNodeServiceSaveRouteNodeInstance() throws Exception {
426         DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName("gooddoctype");
427         if(documentType != null){
428             KRADServiceLocator.getDataObjectService().delete(documentType);
429         }
430 
431         documentType = setupDocumentType();
432         RouteNode rn = setupRouteNode(documentType);
433         assertNotNull(rn.getRouteNodeId());
434         RouteNodeInstance rni = new RouteNodeInstance();
435         rni.setDocumentId(TEST_DOC_ID);
436         rni.setRouteNode(rn);
437         rni = KRADServiceLocator.getDataObjectService().save(rni);
438         assertNotNull(rni.getRouteNodeId());
439         assertEquals(rn.getName(), rni.getName());
440     }
441 
442     private DocumentLink setupDocumentLink(String desDocumentId, String orgDocumentId){
443         DocumentLink documentLink = new DocumentLink();
444         documentLink.setDestDocId(desDocumentId);
445         documentLink.setOrgnDocId(orgDocumentId);
446         KRADServiceLocator.getDataObjectService().save(documentLink);
447 
448         documentLink = new DocumentLink();
449         documentLink.setOrgnDocId(desDocumentId);
450         documentLink.setDestDocId(orgDocumentId);
451 
452         return KRADServiceLocator.getDataObjectService().save(documentLink);
453     }
454 
455     private NodeState setupNodeState(RouteNodeInstance routeNodeInstance){
456         NodeState nodeState = new NodeState();
457         nodeState.setKey("TST");
458         nodeState.setValue("VAL");
459         nodeState.setNodeInstance(routeNodeInstance);
460 
461         return KRADServiceLocator.getDataObjectService().save(nodeState, PersistenceOption.FLUSH);
462 
463     }
464 
465     private Note setupNote(){
466         Note note = new Note();
467         note.setNoteText(NOTE_TXT);
468         note.setNoteAuthorWorkflowId("1");
469         note.setNoteCreateDate(new Timestamp(System.currentTimeMillis()));
470         note.setDocumentId(TEST_DOC_ID);
471 
472         return KradDataServiceLocator.getDataObjectService().save(note);
473     }
474 
475     private Attachment setupAttachment(Note note){
476         Attachment attachment = new Attachment();
477         attachment.setFileLoc("/testfile");
478         attachment.setMimeType("test");
479         attachment.setFileName("test.txt");
480         attachment.setNote(note);
481         return KRADServiceLocator.getDataObjectService().save(attachment, PersistenceOption.FLUSH);
482     }
483 
484     private Branch setupRouteBranchState(Branch branch){
485         BranchState bs = new BranchState();
486         bs.setKey("KEY");
487         bs.setValue("VAL");
488         bs.setBranch(branch);
489 
490         branch.getBranchState().add(bs);
491         return KradDataServiceLocator.getDataObjectService().save(branch);
492     }
493 
494     private Branch setupRouteBranch() {
495         Branch branch = new Branch();
496         branch.setName("PRIMARY");
497 
498         return KRADServiceLocator.getDataObjectService().save(branch, PersistenceOption.FLUSH);
499     }
500 
501     private void setupInitialRouteNodeInstancesJoinTable(String routeNodeInstanceId) {
502         new JdbcTemplate(TestHarnessServiceLocator.getDataSource()).execute("insert into KREW_INIT_RTE_NODE_INSTN_T "
503                 + "values('"+TEST_DOC_ID+"','"+routeNodeInstanceId+"')");
504     }
505 
506     private DocumentRouteHeaderValueContent setupDocumentValueContent() {
507         DocumentRouteHeaderValueContent dc = new DocumentRouteHeaderValueContent();
508         dc.setDocumentId(TEST_DOC_ID);
509         dc.setDocumentContent(DOC_CNT);
510 
511         return KRADServiceLocator.getDataObjectService().save(dc);
512     }
513 
514 
515     private SearchableAttributeStringValue setupSearchAttributeStringValue() {
516         SearchableAttributeStringValue searchableAttributeValue = new SearchableAttributeStringValue();
517         searchableAttributeValue.setDocumentId(TEST_DOC_ID);
518         searchableAttributeValue.setSearchableAttributeValueId(SEARCHABLE_ATTR_ID);
519         searchableAttributeValue.setSearchableAttributeKey(SEARCHABLE_ATTR_KEY);
520         searchableAttributeValue.setSearchableAttributeValue(SEARCHABLE_ATTR_VAL);
521 
522         return KRADServiceLocator.getDataObjectService().save(searchableAttributeValue);
523     }
524 
525     private SearchableAttributeDateTimeValue setupSearchAttributeDateTimeValue() {
526         SearchableAttributeDateTimeValue searchableAttributeDateTimeValue = new SearchableAttributeDateTimeValue();
527         searchableAttributeDateTimeValue.setDocumentId(TEST_DOC_ID);
528         searchableAttributeDateTimeValue.setSearchableAttributeValueId(SEARCHABLE_ATTR_ID);
529         searchableAttributeDateTimeValue.setSearchableAttributeKey(SEARCHABLE_ATTR_KEY);
530         searchableAttributeDateTimeValue.setSearchableAttributeValue(SEARCHABLE_ATTR_VAL_DT);
531 
532         return KRADServiceLocator.getDataObjectService().save(searchableAttributeDateTimeValue);
533     }
534 
535 
536     private DocumentRouteHeaderValue setupDocumentRouteHeaderValue() {
537         DocumentRouteHeaderValue routeHeader = new DocumentRouteHeaderValue();
538         routeHeader.setAppDocId("Test");
539         routeHeader.setApprovedDate(null);
540         routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
541         routeHeader.setDocContent("test");
542         routeHeader.setDocRouteLevel(1);
543         routeHeader.setDocRouteStatus(KewApiConstants.ROUTE_HEADER_ENROUTE_CD);
544         routeHeader.setDocTitle("Test");
545         routeHeader.setDocumentTypeId("1");
546         routeHeader.setDocVersion(KewApiConstants.DocumentContentVersions.CURRENT);
547         routeHeader.setRouteStatusDate(new Timestamp(new Date().getTime()));
548         routeHeader.setDateModified(new Timestamp(new Date().getTime()));
549         routeHeader.setInitiatorWorkflowId("someone");
550 
551         return KRADServiceLocator.getDataObjectService().save(routeHeader, PersistenceOption.FLUSH);
552     }
553 
554     private DocumentRouteHeaderValue setupDocumentRouteHeaderValueWithRouteHeaderAssigned() {
555         DocumentRouteHeaderValue routeHeader = new DocumentRouteHeaderValue();
556         routeHeader.setDocumentId(TEST_DOC_ID);
557         routeHeader.setAppDocId("Test");
558         routeHeader.setApprovedDate(null);
559         routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
560         routeHeader.setDocContent("test");
561         routeHeader.setDocRouteLevel(1);
562         routeHeader.setDocRouteStatus(KewApiConstants.ROUTE_HEADER_ENROUTE_CD);
563         routeHeader.setDocTitle("Test");
564         routeHeader.setDocumentTypeId("1");
565         routeHeader.setDocVersion(KewApiConstants.DocumentContentVersions.CURRENT);
566         routeHeader.setRouteStatusDate(new Timestamp(new Date().getTime()));
567         routeHeader.setDateModified(new Timestamp(new Date().getTime()));
568         routeHeader.setInitiatorWorkflowId("someone");
569 
570         return KRADServiceLocator.getDataObjectService().save(routeHeader);
571     }
572 
573     private DocumentStatusTransition setupDocumentStatusTransition(){
574         DocumentStatusTransition documentStatusTransition = new DocumentStatusTransition();
575         documentStatusTransition.setDocumentId(TEST_DOC_ID);
576         documentStatusTransition.setNewAppDocStatus("F");
577         documentStatusTransition.setOldAppDocStatus("A");
578         documentStatusTransition.setStatusTransitionDate(new Timestamp(System.currentTimeMillis()));
579         return KRADServiceLocator.getDataObjectService().save(documentStatusTransition);
580 
581     }
582 
583     private RouteNodeInstance setupRouteNodeInstance(RouteNode routeNode){
584         RouteNodeInstance routeNodeInstance = new RouteNodeInstance();
585         routeNodeInstance.setActive(true);
586         routeNodeInstance.setComplete(true);
587         routeNodeInstance.setDocumentId(TEST_DOC_ID);
588         routeNodeInstance.setInitial(true);
589         routeNodeInstance.setRouteNode(routeNode);
590         return KRADServiceLocator.getDataObjectService().save(routeNodeInstance, PersistenceOption.FLUSH);
591     }
592 
593     private RouteNode setupRouteNode(DocumentType documentType){
594         RouteNode routeNode = new RouteNode();
595         routeNode.setDocumentType(documentType);
596         routeNode.setRouteNodeName("PreRoute");
597         routeNode.setRouteMethodName("org.kuali.rice.kew.engine.node.InitialNode");
598         routeNode.setRouteMethodCode("C");
599         routeNode.setActivationType("P");
600 
601         return KRADServiceLocator.getDataObjectService().save(routeNode, PersistenceOption.FLUSH);
602     }
603 
604 
605     private DocumentType setupDocumentType(){
606         DocumentType documentType = new DocumentType();
607         documentType.setActionsUrl("/test");
608         documentType.setActive(true);
609         documentType.setActualApplicationId("tst");
610         documentType.setActualNotificationFromAddress("blah@iu.edu");
611         documentType.setApplyRetroactively(true);
612         documentType.setAuthorizer("TestAuthorizer");
613         documentType.setBlanketApprovePolicy("GoodPolicy");
614         documentType.setBlanketApproveWorkgroupId("TestGroup");
615         documentType.setCurrentInd(true);
616         documentType.setDescription("testing descr");
617         documentType.setCustomEmailStylesheet("blah@iu.edu");
618         documentType.setDocumentId("1234");
619         documentType.setLabel("doc type stuff");
620         documentType.setName("gooddoctype");
621         documentType.setReturnUrl("returnUrl");
622         documentType.setPostProcessorName("PostProcessMe");
623         documentType.setDocTypeParentId(null);
624 
625         return KRADServiceLocator.getDataObjectService().save(documentType);
626     }
627 }