use of org.springframework.mock.web.MockMultipartFile in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequest.
@Test
public void multipartRequest() throws Exception {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
MockMultipartFile filePart = new MockMultipartFile("file", "orig", null, fileContent);
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
standaloneSetup(new MultipartController()).build().perform(multipart("/test-multipartfile").file(filePart).file(jsonPart)).andExpect(status().isFound()).andExpect(model().attribute("fileContent", fileContent)).andExpect(model().attribute("jsonContent", Collections.singletonMap("name", "yeeeah")));
}
use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class StudyFileServiceTest method testUploadWithEmptyFile.
@Test(expected = FileUploadException.class)
public void testUploadWithEmptyFile() throws Exception {
// Create our study dir , it should be empty
studyFileService.createStudyDir(STUDY_ID);
assertThat(studyFileService.getStudyFiles(STUDY_ID)).isEmpty();
// Mock a file coming in via the controller
MockMultipartFile file = new MockMultipartFile("data", "filename.txt", "text/plain", "".getBytes());
studyFileService.upload(file, STUDY_ID);
}
use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class AssociationUploadServiceTest method uploadBlankFile.
@Test(expected = FileUploadException.class)
public void uploadBlankFile() throws Exception {
MockMultipartFile blankFile = new MockMultipartFile("data", "filename.txt", "text/plain", "".getBytes());
doThrow(new FileUploadException()).when(studyFileService).upload(blankFile, STUDY.getId());
associationUploadService.upload(blankFile, STUDY, SECURE_USER);
}
use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class AssociationUploadServiceTest method uploadFileValidationErrors.
@Test
public void uploadFileValidationErrors() throws Exception {
MockMultipartFile uploadedFile = new MockMultipartFile("data", "filename.txt", "text/plain", "Test file".getBytes());
File file = new File(uploadedFile.getOriginalFilename());
// Return validation summary with no errors
when(studyFileService.getFileFromFileName(STUDY.getId(), uploadedFile.getOriginalFilename())).thenReturn(file);
when(associationFileUploadService.processAndValidateAssociationFile(file, "full")).thenReturn(VALIDATION_SUMMARY_ASS_ERRORS);
// Test and verify
assertThat(associationUploadService.upload(uploadedFile, STUDY, SECURE_USER)).hasSize(1);
verify(studyFileService, times(1)).getFileFromFileName(STUDY.getId(), uploadedFile.getOriginalFilename());
verify(associationFileUploadService, times(1)).processAndValidateAssociationFile(file, "full");
verify(studyFileService, times(1)).deleteFile(STUDY.getId(), uploadedFile.getOriginalFilename());
}
use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class AssociationUploadServiceTest method uploadFileNoErrors.
@Test
public void uploadFileNoErrors() throws Exception {
MockMultipartFile uploadedFile = new MockMultipartFile("data", "filename.txt", "text/plain", "Test file".getBytes());
File file = new File(uploadedFile.getOriginalFilename());
// Return validation summary with no errors
when(studyFileService.getFileFromFileName(STUDY.getId(), uploadedFile.getOriginalFilename())).thenReturn(file);
when(associationFileUploadService.processAndValidateAssociationFile(file, "full")).thenReturn(VALIDATION_SUMMARY_NO_ERRORS);
// Test and verify
assertThat(associationUploadService.upload(uploadedFile, STUDY, SECURE_USER)).hasSize(0);
verify(studyFileService, times(1)).getFileFromFileName(STUDY.getId(), uploadedFile.getOriginalFilename());
verify(associationFileUploadService, times(1)).processAndValidateAssociationFile(file, "full");
// Verify batch upload event
verify(trackingOperationService, times(1)).update(STUDY, SECURE_USER, "ASSOCIATION_BATCH_UPLOAD", "1 associations created from upload of 'filename.txt'");
verify(studyRepository, times(1)).save(STUDY);
verify(associationOperationsService, times(1)).saveAssociation(ASSOCIATION, STUDY, ASSOCIATION_SUMMARY_NO_ERROR.getErrors());
verify(associationOperationsService, times(1)).createAssociationCreationEvent(ASSOCIATION, SECURE_USER);
//verify(associationOperationsService, times(1)).runMapping(STUDY.getHousekeeping().getCurator(),
// ASSOCIATION,
// SECURE_USER);
}
Aggregations