title: Create fakeRequest for MultipartFormData java Play Framework 2
body: <p>I want to test my upload routine. But nothing works. Is there a way to test the upload of an MultipartFormData upload in Java?</p>
  
  <p>My approaches:
  The first one, but that do not work...withFormURLEncodedBody only accepts a  map.</p>
  
  <pre class="lang-java prettyprint-override"><code>    // generate fake cookie
      Cookie fakeCookie = Utils.fakeCookie(userInfo.getName());
      // create a fake request
      FakeRequest fakeRequest = new FakeRequest("POST", "/restricted/upload");
      // create an Hashmap for data
      Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
      File file = new File(
              RootPathConstant.TEST_FILES_PATH.concat(File.separator
                      .concat("test.nt")));
      data.put("file", file);
      // call an action with some parameters and receive results
      Result result = Helpers.callAction(controllers.routes.ref.UserOptions
              .uploadDataset(),fakeRequest.withFormUrlEncodedBody(data)
              .withCookies(fakeCookie));
  </code></pre>
  
  <p>My second approach ist like this:</p>
  
  <p><a href="https://stackoverflow.com/questions/10890381/test-multipartformdata-in-play-2-0-fakerequest">Test MultipartFormData in Play 2.0 FakeRequest</a>
  But it don't initiate any save actions after the post was executed. The site can be accessed but it seems that the post controlleraction was not called</p>
  
  <p>Have anyone an idea to solve this?</p>