1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.notes;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20
21 import java.io.FileReader;
22 import java.io.StringWriter;
23 import java.sql.Timestamp;
24 import java.util.Date;
25
26 import org.junit.Test;
27 import org.kuali.rice.kew.notes.service.NoteService;
28 import org.kuali.rice.kew.service.KEWServiceLocator;
29 import org.kuali.rice.kew.test.KEWTestCase;
30 import org.kuali.rice.kew.test.TestUtilities;
31
32 public class NoteServiceTest extends KEWTestCase {
33
34 @Test public void testAttachmentSave() throws Exception {
35 Note note = new Note();
36 note.setNoteAuthorWorkflowId("fakeyUser");
37 note.setDocumentId("2");
38 note.setNoteCreateDate(new Timestamp(new Date().getTime()));
39 note.setNoteText("i like notes");
40
41 Attachment attachment = new Attachment();
42 attachment.setNote(note);
43 attachment.setMimeType("mimeType");
44 attachment.setFileName("attachedFile.txt");
45 attachment.setAttachedObject(TestUtilities.loadResource(this.getClass(), "attachedFile.txt"));
46
47 note.getAttachments().add(attachment);
48
49 NoteService noteService = KEWServiceLocator.getNoteService();
50 noteService.saveNote(note);
51 assertNotNull("Note should have a id", note.getNoteId());
52 assertNotNull("Note should have a version number", note.getLockVerNbr());
53
54 assertNotNull("Attachment should have a id", attachment.getAttachmentId());
55 assertNotNull("Attachment should have version number", attachment.getLockVerNbr());
56 assertNotNull("Attachment file loc should reflect file system location", attachment.getFileLoc());
57
58 FileReader fileReader = new FileReader(noteService.findAttachmentFile(attachment));
59 StringWriter stringWriter = new StringWriter();
60 int c;
61 while ((c = fileReader.read()) != -1) {
62 stringWriter.write(c);
63 }
64
65 assertEquals("Attached file content should equal source file content", "I'm an attached file", stringWriter.getBuffer().toString());
66 }
67
68 }