@Test public void testAttachmentContents() throws Exception { try { FileWriter out = new FileWriter("dummy.txt"); out.write("Hello testAttachmentContent"); out.close(); File dummyFile = new File("dummy.txt"); Note dummyNote = new Note(); InputStream inStream = new FileInputStream("dummy.txt"); GlobalVariables.setUserSession(new UserSession("quickstart")); Person kualiUser = GlobalVariables.getUserSession().getPerson(); PersistableBusinessObject parentNote = KRADServiceLocator.getNoteService() .createNote(dummyNote, dummyAttachment, kualiUser.getPrincipalId()); dummyAttachment = KRADServiceLocator.getAttachmentService() .createAttachment( parentNote, "dummy.txt", "MimeTypeCode", (int) (long) dummyFile.length(), inStream, "AttachmentTypeCode"); String result = ""; DataInputStream in = new DataInputStream(dummyAttachment.getAttachmentContents()); while (in.available() != 0) { result += in.readLine(); } inStream.close(); assertEquals( "Testing attachmentContents in AttachmentTest", "Hello testAttachmentContent", result); } finally { new File("dummy.txt").delete(); } }