ngrinder groovy POST XML请求
XML 请求 post Groovy
2023-09-14 08:59:26 时间
import static net.grinder.script.Grinder.grinder import static org.junit.Assert.* import static org.hamcrest.Matchers.* import net.grinder.plugin.http.HTTPRequest import net.grinder.plugin.http.HTTPPluginControl import net.grinder.script.GTest import net.grinder.script.Grinder import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread // import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3 import org.junit.Before import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith import java.util.Date import java.util.List import java.util.ArrayList import HTTPClient.Cookie import HTTPClient.CookieModule import HTTPClient.HTTPResponse import HTTPClient.NVPair import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类 import groovy.sql.Sql @RunWith(GrinderRunner) class TestRunner { public static GTest test public static HTTPRequest request public static NVPair[] headers = [] public static NVPair[] params = [] public static Cookie[] cookies = [] public static List<String> LineList //存放参数文件记录 @BeforeProcess public static void beforeProcess() { HTTPPluginControl.getConnectionDefaults().timeout = 6000 test = new GTest(1, "10.248.64.58") request = new HTTPRequest() // 设置请求头header List<NVPair> headerList = new ArrayList<NVPair>() headerList.add(new NVPair("Content-Type", "text/xml")) headers = headerList.toArray() //连接数据库 Sql db= Sql.newInstance( "jdbc:oracle:thin:@10.248.46.46:1521:databaseName", "user", "password", "oracle.jdbc.driver.OracleDriver"); //获取查询数据 LineList= db.rows("select CUSTOMER_ID from cc_customer where create_time >= to_date('20220518','yyyy/mm/dd')").CUSTOMER_ID; grinder.logger.info("LineList_length={}",LineList.size()); grinder.logger.info("before process."); } @BeforeThread public void beforeThread() { test.record(this, "test") grinder.statistics.delayReports=true; grinder.logger.info("before thread."); } @Before public void before() { request.setHeaders(headers) cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) } grinder.logger.info("before thread. init headers and cookies"); } @Test public void test(){ def gtime=new Date().format('yyyyMMddHHmmssSSS')//生成17位时间戳 int totalAgents=grinder.getProperties().getInt("grinder.agents",1); //总代理数 int total_processes=grinder.getProperties().getInt("grinder.processes",1); //总进程数 int total_threads=grinder.getProperties().getInt("grinder.threads",1); //总线程数 int Listindex=grinder.agentNumber*total_processes*total_threads + grinder.processNumber*total_threads + grinder.threadNumber + totalAgents * total_processes * total_threads * grinder.runNumber String customerID = LineList.get(Listindex).toString() //定义请求报文 String xmlbody="<CustomerID>${customerID}</CustomerID>" HTTPResponse result = request.POST("http://10.248.66.11:30051/csf_web", xmlbody.getBytes())//发起请求 grinder.logger.info("响应报文={}",result.getText()) //设置断言 if(result.StatusCode == 200){ assertThat(result.getText(), containsString("<RspCode>0000</RspCode><RspDesc>Success</RspDesc>")); }else{ assertThat(result.statusCode, is(200)); } } }
关键脚本:
// 设置请求头header List<NVPair> headerList = new ArrayList<NVPair>() headerList.add(new NVPair("Content-Type", "text/xml")) headers = headerList.toArray()
String xmlbody="<CustomerID>${customerID}</CustomerID>" HTTPResponse result = request.POST("http://10.248.66.11:30051/csf_web", xmlbody.getBytes())//发起请求
相关文章
- java解析xml element_java解析XML Node与Element的区别(推荐)「建议收藏」
- linux c语言xml解析xml,纯C语言XML解析器
- 【目标检测】小脚本:Xml标签可视化
- XML建模
- 一个kvm虚拟机的xml文件
- ORA-30987: XML Index on XML DB repository does not exist ORACLE 报错 故障修复 远程处理
- ORA-30997: XSL processing of XML failed with error LPX-string ORACLE 报错 故障修复 远程处理
- ORA-19032: Expected XML tag string got string ORACLE 报错 故障修复 远程处理
- HDFS For core-site.xml详解大数据
- Oracle存储XML数据的解决方案(oracle存储xml)
- 应用Xml.Linq读xml文件详解编程语言
- Linux下XML解析的实现方法(linux解析xml)
- MySQL与XML的查询有哪些方法?(mysqlxml查询)
- MSSQL妙用:用XML解析精彩世界(mssql 解析 xml)
- 使用MySQL替换XML数据一种高效的方法(mysql xml替换)
- MySQL数据库如何使用XML文件进行数据存储与交换(mysql xml文件)
- MySQL与XML实现数据分页(mysql xml分页)
- Oracle中高效处理XML的方法(oracle中处理xml)
- 利用Oracle XML组件让数据处理更高效(oracle xml组件)
- 装Oracle XML的包装简化数据交换流程(oracle xml的包)
- JavaScript生成xml
- 基于XML的购物车的实现
- 用Flash和XML来构造一个聊天室
- jsp读取大对象CLOB并生成xml文件示例
- 读写xml文件的2个小函数
- XML中显示HTML的小技巧
- 怎样打开XML文件?xml文件如何打开?
- java操作XML实例代码