import com.app.util.EncryptUtil;
import com.juyun.test.util.Java2Xml;
import com.juyun.test.util.XmlUtil;
public class TestgetKeyword {
****
BufferedReader reader=null;
@Before
public void setUpBeforeEveryTime() throws Exception{
// flushCache.FlushAll(host, port);
System.out.println("+++setUpBefore");
System.out.println("flush cache...");
System.out.println("===========================");
}
@Test
public void testGetVersion() throws Exception {
httpClient = new HttpClient();
EntityEnclosingMethod postMethod = new PostMethod();
// String string = xUtil.xmltoString(file);
String string = getDocument();
byte[] request = string.getBytes("UTF-8");
byte[] requestcode =EncryptUtil.getInstance().encode(request);
RequestEntity requestEntity = new ByteArrayRequestEntity(requestcode);
postMethod.setRequestEntity(requestEntity);
postMethod.setPath(url);
postMethod.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30*1000);
httpClient.executeMethod(postMethod);
byte[] responsecode =postMethod.getResponseBody();
byte[] response =EncryptUtil.getInstance().decode(responsecode);
ByteArrayEntity byteArrayEntity = new ByteArrayEntity(response) ;
reader = new BufferedReader(new InputStreamReader(byteArrayEntity.getContent()));
String xml = reader.readLine();
Document document =xUtil.StringtoXml(xml);
// System.out.println(document.asXML());
assertEquals("<result_code>1</result_code>", document.selectSingleNode("//result_code").asXML());
// assertEquals("<appid>894</appid>", document.selectSingleNode("//entry_total/appid").asXML());
}
@AfterClass //执行一次
public static void tearDownAfterClassOnce() throws Exception {
System.out.println("===========================");
System.out.println("tearDownAfterClass");
}
}
直接对document 进行内容选取,再对相关节点断言判断,以此来测试接口下发正确性