View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.notes;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.junit.Test;
23  import org.kuali.rice.kew.dto.NetworkIdDTO;
24  import org.kuali.rice.kew.dto.NoteDTO;
25  import org.kuali.rice.kew.service.WorkflowDocument;
26  import org.kuali.rice.kew.test.KEWTestCase;
27  
28  
29  public class NoteWebServiceTest extends KEWTestCase {
30  	
31  	@Test public void testNotesClient() throws Exception {
32  		NoteDTO testNoteVO;
33  		WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), "TestDocumentType");
34  		//Test add notes
35  		testNoteVO = new NoteDTO();
36  		testNoteVO.setNoteAuthorWorkflowId("andlee");
37  		testNoteVO.setNoteText("first added note");
38  		doc.updateNote(testNoteVO);
39  		
40  		testNoteVO = new NoteDTO();
41  		testNoteVO.setNoteAuthorWorkflowId("rou");
42  		testNoteVO.setNoteText("second added note");
43  		doc.updateNote(testNoteVO);
44  		
45  		List notesList = doc.getNoteList();
46  		
47          assertEquals ("Two notes are added.", 2, notesList.size());
48         /* int i = 0;
49          for (Iterator it= notesList.iterator(); it.hasNext();){
50          	NoteVO displayNoteVO = (NoteVO)it.next();
51          	System.out.println("i=" + i);
52          	System.out.println(displayNoteVO.getNoteAuthorWorkflowId());
53          	System.out.println(displayNoteVO.getNoteText());
54          	if (i ==0){
55          		assertEquals("The first note Text is equals 'first added note", "first added note", displayNoteVO.getNoteText());
56          	}
57          	i++;
58          }*/
59          
60          doc.saveRoutingData();
61          
62          int i = 0;
63          notesList = doc.getNoteList();
64          assertEquals("Note List size changed",2,notesList.size());
65          for (Iterator iter = notesList.iterator(); iter.hasNext();) {
66  			NoteDTO noteVO = (NoteDTO) iter.next();
67  			assertNotNull("Note saved through workflow document", noteVO.getNoteId());
68  			System.out.println("Note ID is:" + noteVO.getNoteId());
69  			i++;
70  			if (i ==1) {
71  				assertEquals("text altered during save", "first added note", noteVO.getNoteText());
72  				assertEquals("note user associated with saved note", "andlee", noteVO.getNoteAuthorWorkflowId());
73  			}
74  			if (i ==2) {
75  				assertEquals("text altered during save", "second added note", noteVO.getNoteText());
76  				assertEquals("note user associated with saved note", "rou", noteVO.getNoteAuthorWorkflowId());
77  			}
78  			
79  		}
80          
81          /*List notesFromDB = SpringServiceLocator.getNoteService().getNotesByRouteHeaderId(doc.getRouteHeaderId());
82          for (Iterator iter = notesFromDB.iterator(); iter.hasNext();) {
83  			Note note = (Note) iter.next();
84  			System.out.println(note.getNoteText());
85  		}*/
86          
87          notesList = doc.getNoteList();
88          testNoteVO = (NoteDTO)notesList.get(0);
89          doc.deleteNote(testNoteVO);
90          
91          testNoteVO = (NoteDTO)notesList.get(1);
92          testNoteVO.setNoteText("Update second note text");
93          doc.updateNote(testNoteVO);
94          
95          doc.saveRoutingData();
96          i = 0;
97          notesList = doc.getNoteList();
98          assertEquals("Note List size changed",1,notesList.size());
99          for (Iterator iter = notesList.iterator(); iter.hasNext();) {
100 			NoteDTO noteVO = (NoteDTO) iter.next();
101 			assertNotNull("Note saved through workflow document", noteVO.getNoteId());
102 			System.out.println("Note ID is:" + noteVO.getNoteId());
103 			i++;
104 			if (i ==1) {
105 				assertEquals("text altered during save", "Update second note text", noteVO.getNoteText());
106 				assertEquals("note user associated with saved note", "rou", noteVO.getNoteAuthorWorkflowId());
107 			}
108 		}
109 		
110 	}
111 }