title: Spring MVC Test - multipart POST json originalFilename is required
body: <p>I use spring-boot 2.0.3.RELEASE with junit5. I have just tried to test multipart request with mockMvc.</p>
  
  <pre><code>MockMultipartFile file = new MockMultipartFile("file", "contract.pdf", MediaType.APPLICATION_PDF_VALUE, "&lt;&lt;pdf data&gt;&gt;".getBytes(StandardCharsets.UTF_8));
  MockMultipartFile metadata = new MockMultipartFile("metadata", "", MediaType.APPLICATION_JSON_VALUE, objectMapper.writeValueAsString(metadata).getBytes(StandardCharsets.UTF_8));
  this.mockMvc.perform(multipart("/documents")
          .file(file)
          .file(metadata))
          .andExpect(status().isNoContent());
  </code></pre>
  
  <p>But it is not working with part metadata (json).</p>
  
  <p><strong>I always get exception</strong> </p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: originalFilename is required.
  </code></pre>
  
  <p>What is wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My implementation is in spring integration dsl. I think that exception is invoked in <code>org.springframework.integration.http.multipart.UploadedMultipartFile</code>. How can I test multipart request with mockMvc?</p>
  
  <pre><code>@Bean
  public IntegrationFlow multipartForm() {
      return IntegrationFlows.from(Http.inboundChannelAdapter("/documents")
              .statusCodeExpression(HttpStatus.NO_CONTENT.toString())
              .requestMapping(m -&gt; m
                      .methods(HttpMethod.POST)
                      .consumes(MediaType.MULTIPART_FORM_DATA_VALUE)
              ))
              .handle(new MultipartReceiver())
              .get();
  }
  </code></pre>
  
  <p>My demo project is in github
  <a href="https://github.com/bulalak/demo-spring-integration-http" rel="nofollow noreferrer">https://github.com/bulalak/demo-spring-integration-http</a></p>