接口测试中 对xml下发内容的解析断言



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 进行内容选取,再对相关节点断言判断,以此来测试接口下发正确性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值