接口测试中 对xml下发内容的解析断言
2012-08-07 22:24
393 查看
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 进行内容选取,再对相关节点断言判断,以此来测试接口下发正确性
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 进行内容选取,再对相关节点断言判断,以此来测试接口下发正确性
相关文章推荐
- 实例教程四:采用Pull解析器解析和生成XML内容
- Java框架组件-XML、JSON解析,日志,测试,文档,注释
- Android 采用Pull解析器解析和生成XML内容
- 使用DOM方法实现xml文档内容的解析与写入
- Java解析Xml文件—判断Xml文件的节点是否存在子节点_以及对节点下不同子节点的内容解析方式
- 采用Pull解析器解析和生成XML内容
- 接口测试-工作心得记录七(使用assertpy库断言和利用assertpy库改写接口response的check方法)
- Android 采用DOM解析XML内容 【学习记录】
- Java解析Xml文件—判断Xml文件的节点是否存在子节点_以及对节点下不同子节点的内容解析方式
- 【慕课笔记】3-4 应用SAX方式解析XML—使用SAX解析将XML的内容和结构存入JAVA对象
- 《jbpm5-eclipse插件ant安装失败时》---将build.xml文件改为以下文件内容(经测试,该文章用firefox打开最佳)
- 实例教程四:采用Pull解析器解析和生成XML内容
- DOM生成XML文档与解析XML文档(JUNIT测试)
- android xml解析,没实际测试,顺手转来
- php的SimpleXML方法读写XML接口文件实例解析
- vtk实战(十四)——解析vtk XML 文件的内容
- mapper.xml内容解析
- 在SQL2005里直接读取XML并解析其内容
- 四种 XML 解析技术之不完全测试
- Java中四种XML解析技术之不完全测试(转载)