Search in sources :

Example 11 with MockMultipartHttpServletRequest

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());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) Test(org.junit.Test)

Example 12 with MockMultipartHttpServletRequest

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'"));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) InputStream(java.io.InputStream) ModelAndView(org.springframework.web.servlet.ModelAndView) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 13 with MockMultipartHttpServletRequest

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");
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) MockPart(org.springframework.mock.web.MockPart) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockMultipartHttpServletRequest (org.springframework.mock.web.MockMultipartHttpServletRequest)13 File (java.io.File)5 Test (org.junit.Test)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)4 Test (org.junit.jupiter.api.Test)4 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ResponseCodeView (com.thoughtworks.go.server.web.ResponseCodeView)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 Parameter (nl.nn.adapterframework.parameters.Parameter)2 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2