XMLファイルをサーバーに送信する必要があるPOSTテストを作成しようとしています(PLay!フレームワークを使用)。しかし、私は何か間違ったことをしなければなりません。実行すると、コントローラーに「データ」がありません。
これは私のコードです: ルート:
POST /server/? Server.index(format:'xml')
コントローラ:
public static void index(Upload data) {
if (data != null){
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document xmlDoc = builder.parse(data.asStream());
}
etc..
}
テスト:
File f = new File("request.xml");
TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(f);
transformer.transform(source, result);
Map<String,String> map = new HashMap<String,String>();
//map.put("data", xmlString);
Map<String,File> files = new HashMap<String,File>();
files.put("request.xml", f);
Http.Response response = POST("/server/", map, files);
assertIsOk(response);
f.delete();
StringReader reader = new StringReader(response.out.toString());
InputSource inputSource = new InputSource( reader );
Document xmlDoc = builder.parse( inputSource );
reader.close();