I want to test my upload routine. But nothing works. Is there a way to test the upload of an MultipartFormData upload in Java?
My approaches: The first one, but that do not work...withFormURLEncodedBody only accepts a map.
// 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<String, Object> data = new HashMap<String, Object>();
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));
My second approach ist like this:
Test MultipartFormData in Play 2.0 FakeRequest 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
Have anyone an idea to solve this?