use of org.springframework.mock.web.MockMultipartFile in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWrapped.
// SPR-13317
@Test
public void multipartRequestWrapped() throws Exception {
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
Filter filter = new RequestWrappingFilter();
MockMvc mockMvc = standaloneSetup(new MultipartController()).addFilter(filter).build();
Map<String, String> jsonMap = Collections.singletonMap("name", "yeeeah");
mockMvc.perform(multipart("/test-json").file(jsonPart)).andExpect(model().attribute("json", jsonMap));
}
use of org.springframework.mock.web.MockMultipartFile in project gocd by gocd.
the class ArtifactsControllerIntegrationTest method shouldSaveChecksumFileInTheCruiseOutputFolder.
@Test
public void shouldSaveChecksumFileInTheCruiseOutputFolder() throws Exception {
File fooFile = createFile(artifactsRoot, "/tmp/foobar.html");
FileUtils.writeStringToFile(fooFile, "FooBarBaz...");
File checksumFile = createFile(artifactsRoot, "/tmp/foobar.html.checksum");
FileUtils.writeStringToFile(checksumFile, "baz/foobar.html:FooMD5\n");
MockMultipartFile artifactMultipart = new MockMultipartFile("file", new FileInputStream(fooFile));
MockMultipartFile checksumMultipart = new MockMultipartFile("file_checksum", new FileInputStream(checksumFile));
request.addHeader("Confirm", "true");
StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request, artifactMultipart, checksumMultipart);
postFileWithChecksum("baz/foobar.html", multipartRequest);
assertThat(file(artifactsRoot, "baz/foobar.html"), exists());
File uploadedChecksumFile = file(artifactsRoot, "cruise-output/md5.checksum");
assertThat(uploadedChecksumFile, exists());
assertThat(FileUtils.readLines(uploadedChecksumFile).get(0).toString(), is("baz/foobar.html:FooMD5"));
}
use of org.springframework.mock.web.MockMultipartFile in project gocd by gocd.
the class ArtifactsControllerIntegrationTest method shouldAppendChecksumInTheCruiseOutputFolder.
@Test
public void shouldAppendChecksumInTheCruiseOutputFolder() throws Exception {
File fooFile = createFileWithContent(artifactsRoot, "/tmp/foobar.html", "FooBarBaz...");
createFileWithContent(artifactsRoot, "cruise-output/md5.checksum", "oldbaz/foobar.html:BazMD5\n");
File checksumFile = createFileWithContent(artifactsRoot, "/tmp/foobar.html.checksum", "baz/foobar.html:FooMD5\n");
MockMultipartFile artifactMultipart = new MockMultipartFile("file", new FileInputStream(fooFile));
MockMultipartFile checksumMultipart = new MockMultipartFile("file_checksum", new FileInputStream(checksumFile));
request.addHeader("Confirm", "true");
StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request, artifactMultipart, checksumMultipart);
postFileWithChecksum("baz/foobar.html", multipartRequest);
assertThat(file(artifactsRoot, "baz/foobar.html"), exists());
File uploadedChecksumFile = file(artifactsRoot, "cruise-output/md5.checksum");
assertThat(uploadedChecksumFile, exists());
List list = FileUtils.readLines(uploadedChecksumFile);
assertThat(list.size(), is(2));
assertThat(list.get(0).toString(), is("oldbaz/foobar.html:BazMD5"));
assertThat(list.get(1).toString(), is("baz/foobar.html:FooMD5"));
}
use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class StudyFileServiceTest method testUploadWithFile.
@Test
public void testUploadWithFile() 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", "Some study details".getBytes());
studyFileService.upload(file, STUDY_ID);
assertThat(studyFileService.getStudyFiles(STUDY_ID)).isNotEmpty();
assertThat(studyFileService.getStudyFiles(STUDY_ID)).hasSize(1);
assertThat(studyFileService.getStudyFiles(STUDY_ID)).hasOnlyElementsOfType(StudyFileSummary.class);
assertThat(studyFileService.getStudyFiles(STUDY_ID)).extracting("fileName").contains("filename.txt");
}
use of org.springframework.mock.web.MockMultipartFile in project goci by EBISPOT.
the class AssociationUploadServiceTest method uploadMissingFile.
@Test(expected = IOException.class)
public void uploadMissingFile() throws Exception {
MockMultipartFile file = new MockMultipartFile("data", "filename.txt", "text/plain", "Blank file".getBytes());
// Stubbing
when(studyFileService.getFileFromFileName(STUDY.getId(), file.getOriginalFilename())).thenThrow(new FileNotFoundException());
associationUploadService.upload(file, STUDY, SECURE_USER);
}
Aggregations