use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class AssociationUploadServiceTest method uploadFileRowErrors.
@Test
public void uploadFileRowErrors() 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_ROW_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 uploadIncorrectlyFormattedFile.
@Test(expected = SheetProcessingException.class)
public void uploadIncorrectlyFormattedFile() throws Exception {
MockMultipartFile incorrectlyFormattedFile = new MockMultipartFile("data", "filename.txt", "text/plain", "Not an Excel file".getBytes());
File file = new File(incorrectlyFormattedFile.getOriginalFilename());
// Stubbing
when(studyFileService.getFileFromFileName(STUDY.getId(), incorrectlyFormattedFile.getOriginalFilename())).thenReturn(file);
when(associationFileUploadService.processAndValidateAssociationFile(file, "full")).thenThrow(new SheetProcessingException());
associationUploadService.upload(incorrectlyFormattedFile, STUDY, SECURE_USER);
}
use of org.springframework.mock.web.MockMultipartFile in project gocd by gocd.
the class ArtifactsControllerIntegrationTest method postFile.
private ModelAndView postFile(String requestFilename, String multipartFilename, InputStream stream, MockHttpServletResponse response) throws Exception {
MockMultipartFile multipartFile = new MockMultipartFile(multipartFilename, stream);
request.addHeader("Confirm", "true");
StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request, multipartFile);
return artifactsController.postArtifact(pipelineName, pipeline.getLabel(), "stage", "LATEST", "build", buildId, requestFilename, null, multipartRequest);
}
use of org.springframework.mock.web.MockMultipartFile in project gocd by gocd.
the class ArtifactsControllerTest method shouldReturnHttpErrorCodeWhenChecksumFileSaveFails.
@Test
public void shouldReturnHttpErrorCodeWhenChecksumFileSaveFails() throws Exception {
File artifactFile = new File("junk");
when(artifactService.findArtifact(any(JobIdentifier.class), eq("some-path"))).thenReturn(artifactFile);
when(artifactService.saveFile(any(File.class), any(InputStream.class), eq(false), eq(1))).thenReturn(true);
when(artifactService.saveOrAppendFile(any(File.class), any(InputStream.class))).thenReturn(false);
MockMultipartHttpServletRequest mockMultipartHttpServletRequest = new MockMultipartHttpServletRequest();
mockMultipartHttpServletRequest.addFile(new MockMultipartFile(REGULAR_MULTIPART_FILENAME, "content".getBytes()));
mockMultipartHttpServletRequest.addFile(new MockMultipartFile(CHECKSUM_MULTIPART_FILENAME, "checksum-content".getBytes()));
ModelAndView modelAndView = artifactsController.postArtifact("pipeline-1", "1", "stage-1", "2", "job-1", 122L, "some-path", 1, mockMultipartHttpServletRequest);
ResponseCodeView view = (ResponseCodeView) modelAndView.getView();
assertThat(view.getStatusCode(), is(SC_INTERNAL_SERVER_ERROR));
assertThat(view.getContent(), is("Error saving checksum file for the artifact at path 'some-path'"));
}
use of org.springframework.mock.web.MockMultipartFile in project spring-mvc-showcase by spring-projects.
the class FileUploadControllerTests method readString.
@Test
public void readString() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "orig", null, "bar".getBytes());
webAppContextSetup(this.wac).build().perform(fileUpload("/fileupload").file(file)).andExpect(model().attribute("message", "File 'orig' uploaded successfully"));
}
Aggregations