एकीकरण परीक्षण के लिए की तरह मैं क्या आप अपाचे DefaultHttpCLient उपयोग कर सकते हैं:
@Test
public void addFileItem() throws Exception {
File testFile = File.createTempFile("test","xml");
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost method = new HttpPost(URL_HOST + "/api/v1/items/file");
MultipartEntity entity = new MultipartEntity();
entity.addPart("description", new StringBody("This is my file",Charset.forName("UTF-8")));
entity.addPart(Constants.ITEMTYPE_KEY, new StringBody("FILE", Charset.forName("UTF-8")));
FileBody fileBody = new FileBody(testFile);
entity.addPart("file", fileBody);
method.setEntity(entity);
HttpResponse response = httpclient.execute(method);
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(CREATED);
}
यह जरूरी है कि आप अपने परीक्षण में एक सर्वर शुरू:
public static FakeApplication app;
public static TestServer testServer;
@BeforeClass
public static void startApp() throws IOException {
app = Helpers.fakeApplication();
testServer = Helpers.testServer(PORT, app);
Helpers.start(testServer);
}
@AfterClass
public static void stopApp() {
Helpers.stop(testServer);
}
इसके अलावा ऐसा करने के तरीके पर एक उदाहरण के लिए देख रहा । – MartinGrotzke