我想为此功能编写 JUNIT 测试
public static int creerFichierXml(TextField titre_projet,TextField description1,TextField svn,TextField planning1,TextField planning2,TextField goals,TextField mail){
//Créer le fichier XML et l'envoyer au serveur
int returnCode = 0;
ParseToXML j=new ParseToXML();
try {
j.main(description1, svn, planning1, planning2, goals,mail);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod("http://localhost:8080/createItem?name="+titre_projet.toString());
postMethod.setRequestHeader("Content-type", "application/xml; charset=ISO-8859-1");
try {
postMethod.setRequestBody(new FileInputStream(new File("C:/integrationContinue/src/main/resources/config.xml")));
returnCode = client.executeMethod(postMethod);
System.out.println("*********************************************"+returnCode);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return returnCode;
}
此代码用于创建一个 xml 文件,然后使用 postMethod 将其发送到服务器
Junit 必须测试 http 连接,解析为 Xml 并调用 main 函数