我想在我的应用程序中测试文件上传。上传本身按部分中所述的方式进行处理。直接文件上传在http://www.playframework.org/documentation/2.0/JavaFileUpload上。测试AJAX文件上传
我使用的是最新的Play20版本,并按here所述构建。
我当前的代码看起来是这样,但显然部分缺失增加了一个测试文件的要求:
Test.java
FakeRequest request = fakeRequest(POST, "/measurement/123/file");
// how to append test file to this request?
Result result = routeAndCall(request);
assertOK(result);
Controller.java
public static uploadFile() {
RequestBody body = request().body();
if (body != null) {
RawBuffer rawBuffer = body.asRaw();
if (rawBuffer != null) {
File uploadedFile = rawBuffer.asFile();
// ...
}
}
return ok();
}
你可以举一个例子如何做到这一点? – pangratz 2012-04-18 10:21:18