use of org.springframework.mock.web.MockMultipartHttpServletRequest in project iaf by ibissource.
the class StreamPipeTest method doPipeHttpRequestAntiVirusTest.
@Test
public void doPipeHttpRequestAntiVirusTest() throws Exception {
MockMultipartHttpServletRequest request = createMultipartHttpRequest(pipe, true);
pipe.addParameter(createHttpRequestParameter(request, session));
pipe.configure();
pipe.start();
PipeRunResult pipeRunResult = doPipe(pipe, "", session);
assertEquals("success", pipeRunResult.getPipeForward().getName());
String expectedResult = "<parts>" + "<part type=\"string\" name=\"string1\" sessionKey=\"part_string\" size=\"19\"/>" + "<part type=\"file\" name=\"doc001.pdf\" sessionKey=\"part_file\" size=\"26358\" mimeType=\"application/octet-stream\"/>" + "<part type=\"string\" name=\"antivirus_rc\" sessionKey=\"part_string2\" size=\"4\"/>" + "<part type=\"file\" name=\"doc002.pdf\" sessionKey=\"part_file2\" size=\"25879\" mimeType=\"application/octet-stream\"/>" + "<part type=\"string\" name=\"antivirus_rc\" sessionKey=\"part_string3\" size=\"4\"/>" + "</parts>";
assertEquals(expectedResult, pipeRunResult.getResult().asString());
}
use of org.springframework.mock.web.MockMultipartHttpServletRequest in project gocd by gocd.
the class ArtifactsControllerTest method shouldReturnHttpErrorCodeWhenChecksumFileSaveFails.
@Test
public void shouldReturnHttpErrorCodeWhenChecksumFileSaveFails() throws Exception {
File artifactFile = new File("junk");
JobIdentifier jobIdentifier = new JobIdentifier("pipeline-1", 1, "1", "stage-1", "2", "job-1", 122l);
when(restfulService.findJob("pipeline-1", "1", "stage-1", "2", "job-1", 122l)).thenReturn(jobIdentifier);
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.MockMultipartHttpServletRequest in project spring-framework by spring-projects.
the class MockMultipartHttpServletRequestBuilderTests method addFileAndParts.
// gh-26166
@Test
void addFileAndParts() throws Exception {
MockMultipartHttpServletRequest mockRequest = (MockMultipartHttpServletRequest) new MockMultipartHttpServletRequestBuilder("/upload").file(new MockMultipartFile("file", "test.txt", "text/plain", "Test".getBytes(UTF_8))).part(new MockPart("name", "value".getBytes(UTF_8))).buildRequest(new MockServletContext());
assertThat(mockRequest.getFileMap()).containsOnlyKeys("file");
assertThat(mockRequest.getParameterMap()).containsOnlyKeys("name");
assertThat(mockRequest.getParts()).extracting(Part::getName).containsExactly("name");
}
Aggregations