Çok parçalı form verilerini girdi olarak alan bir Play 2 kontrol cihazı için bir fonksiyon testi oluşturmaya çalışıyorum. Çok parçalı form POST'u desteklemek için şu anda FakeRequest'te herhangi bir yöntem yoktur. Bu denetleyiciyi test etmenin başka yolları nelerdir? Oyun 2.0'daki MultipartFormData Testi FakeRequest
Map<String, Object> map = new HashMap<String, Object>();
map.put("param1", "test-1");
map.put("param2", "test-2");
map.put("file", file)
Result result = routeAndCall(fakeRequest(POST, "/register").withFormUrlEncodedBody(map));// NO SUCH METHOD
DÜZENLEME
: Bu benim multipart test etmek yaptılar çözümdür.HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:3333/blobupload");
FileBody imageFile = new FileBody(new File("test/resources/test-1.jpg"));
StringBody guid1 = null;
StringBody guid2 = null;
try {
guid1 = new StringBody("GUID-1");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("key1", imageFile);
reqEntity.addPart("key2", guid1);
httppost.setEntity(reqEntity);
HttpResponse response;
try {
response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
? routeAndCall da çalışmalıdır. routeAndCall (fakeRequest (POST, "/route").withFormUrlEncodedBody(map)); – angelokh
Mutlipartformdata, sizlerle birlikte scala için çalışabilir. Ancak, java içinFormUrlEncodedBody, Object türünde bir değere sahip bir haritaya izin vermez. – angelokh
Java aromasında callAction'ın neden gerekli olduğunu bilmiyorum, ancak callAction ile sadece fakeRequest(). WithFormUrlEncodeBody'i çağırabilirsiniz gibi görünüyorsunuz, Java dilini çok bilmiyorum, böylece tamamen yanlış olabilirim. Ben multipartı test etmek için withFormUrlEncodedBody kullanmanız gerektiğini düşünmüyorum, sadece doğru POST isteğini oluşturmalısınız. – DamnWidget