private void syncNewFiles(List<SubAwardAttachments> attachments) { assert attachments != null : "the attachments was null"; for (SubAwardAttachments attachment : attachments) { if (SubAwardAttachmentFormBean.doesNewFileExist(attachment)) { final AttachmentFile newFile = AttachmentFile.createFromFormFile(attachment.getNewFile()); // setting the sequence number to the old file sequence number if (attachment.getFile() != null) { newFile.setSequenceNumber(attachment.getFile().getSequenceNumber()); } attachment.setFile(newFile); } } }
protected void syncNewFiles(List<CoiDisclosureAttachment> coiDisclosureAttachments) { assert coiDisclosureAttachments != null : "the attachments was null"; for (final CoiDisclosureAttachment attachment : coiDisclosureAttachments) { if (CoiNotesAndAttachmentsHelper.doesNewFileExist(attachment)) { final AttachmentFile newFile = AttachmentFile.createFromFormFile(attachment.getNewFile()); // setting the sequence number to the old file sequence number if (attachment.getFile() != null) { newFile.setSequenceNumber(attachment.getFile().getSequenceNumber()); } attachment.setFile(newFile); // set to null, so the subsequent post will not creating new file again attachment.setNewFile(null); } } }
/** * Tests that the factory method works correctly with normal input. * * @throws Exception if bad happens. */ @Test public void createFromFormFileBasic() throws Exception { final String fileName = "fileName"; final String fileType = "fileType"; final byte[] data = new byte[] { 1, }; FormFile formFile = createMockFormFileWithExpectations(fileName, fileType, data); AttachmentFile file = AttachmentFile.createFromFormFile(formFile); this.context.assertIsSatisfied(); Assert.assertThat(file.getName(), is(fileName)); Assert.assertThat(file.getType(), is(fileType)); Assert.assertThat(file.getData(), is(data)); }
/** * Test that confirms proper handling of long file names. * * @throws Exception if bad happens. */ @Test public void createFromFormFileLongName() throws Exception { final String fileName = "fileNamethrows Exceptionthrows Exceptionthrows Exceptionthrows Exceptionthrows Exceptionthrows Exceptionthrows Exceptionthrows Exceptionthrows Exceptionthrows Exception"; final String fileType = "fileType"; final byte[] data = new byte[] { 1, }; FormFile formFile = createMockFormFileWithExpectations(fileName, fileType, data); AttachmentFile file = AttachmentFile.createFromFormFile(formFile); this.context.assertIsSatisfied(); Assert.assertThat( file.getName(), is(fileName.substring(fileName.length() - AttachmentFile.MAX_FILE_NAME_LENGTH))); Assert.assertThat(file.getType(), is(fileType)); Assert.assertThat(file.getData(), is(data)); }
/** * Tests that IOExceptions are properly handled by wrapping in a CreateException. * * @throws Exception if bad happens. */ @Test(expected = CreateException.class) public void testCreateException() throws Exception { final FormFile formFile = this.context.mock(FormFile.class); final String fileName = "fileName"; final String fileType = "fileType"; this.context.checking( new Expectations() { { one(formFile).getFileName(); will(returnValue(fileName)); one(formFile).getContentType(); will(returnValue(fileType)); one(formFile).getFileData(); will(throwException(new IOException())); } }); AttachmentFile.createFromFormFile(formFile); this.context.assertIsSatisfied(); }
/** Tests that factory method properly handles a null form file. */ @Test(expected = IllegalArgumentException.class) public void createFromFormFileNullFormFile() { AttachmentFile.createFromFormFile(null); }