01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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 edu.iu.uis.eden.notes;
18:
19: import java.io.FileReader;
20: import java.io.StringWriter;
21: import java.sql.Timestamp;
22: import java.util.Date;
23:
24: import org.junit.Test;
25: import org.kuali.workflow.test.WorkflowTestCase;
26:
27: import edu.iu.uis.eden.KEWServiceLocator;
28: import edu.iu.uis.eden.test.TestUtilities;
29:
30: public class NoteServiceTest extends WorkflowTestCase {
31:
32: @Test
33: public void testAttachmentSave() throws Exception {
34: Note note = new Note();
35: note.setNoteAuthorWorkflowId("fakeyUser");
36: note.setRouteHeaderId(new Long(2));
37: note.setNoteCreateDate(new Timestamp(new Date().getTime()));
38: note.setNoteText("i like notes");
39:
40: Attachment attachment = new Attachment();
41: attachment.setNote(note);
42: attachment.setMimeType("mimeType");
43: attachment.setFileName("attachedFile.txt");
44: attachment.setAttachedObject(TestUtilities.loadResource(this
45: .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
53: .getLockVerNbr());
54:
55: assertNotNull("Attachment should have a id", attachment
56: .getAttachmentId());
57: assertNotNull("Attachment should have version number",
58: attachment.getLockVerNbr());
59: assertNotNull(
60: "Attachment file loc should reflect file system location",
61: attachment.getFileLoc());
62:
63: FileReader fileReader = new FileReader(noteService
64: .findAttachmentFile(attachment));
65: StringWriter stringWriter = new StringWriter();
66: int c;
67: while ((c = fileReader.read()) != -1) {
68: stringWriter.write(c);
69: }
70: //i'm being lazy and knowing what's in the source file
71: assertEquals(
72: "Attached file content should equal source file content",
73: "I'm an attached file", stringWriter.getBuffer()
74: .toString());
75: }
76: }
|