博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[SoapUI] 比较两个不同环境下的XML Response, 从外部文件读取允许的偏差值,输出结果到文本文件...
阅读量:4576 次
发布时间:2019-06-08

本文共 6754 字,大约阅读时间需要 22 分钟。

1. 获取TP和Live的xml response

2. 以其中一个数据点 ticker 为基准进行比较,ticker相同才进行比对

3. 从外部文件读取各个数据点允许的偏差值,偏差范围以内的不同认为是正常

4. API中的数据点提供的是Data ID, 而用户希望错误日志以UI上的Data Name进行打印,因此需要从外部文件读取Data ID和Data Name的映射关系

5. 计算Data point失败的比例

6. 将错误日志输出到本地的文本文件

import static  java.lang.Math.* import com.eviware.soapui.support.GroovyUtilsimport com.eviware.soapui.support.XmlHolderimport org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;// The parameter allowableDeviation means the allowable deviation can be ? percent, e.g. allowableDeviation = 0.03 , the allowable deviation is 3%def allowableDeviation// Fail messageArrayList failMessageList = new ArrayList()String failMessage//  Get test stepsdef currentStepIndex = context.currentStepIndexString currentStepName = testRunner.testCase.getTestStepAt(currentStepIndex).nameString previousStepName = testRunner.testCase.getTestStepAt(currentStepIndex-1).nameString prePreStepName = testRunner.testCase.getTestStepAt(currentStepIndex-2).name//  File pathString testDataPath = testRunner.testCase.testSuite.project.getPropertyValue( "testDataPath" )String dataIdMappingFile = testDataPath+"\\DataIdMappingPA.xml"String dataDeviationFile = testDataPath+"\\RTQDataAllowableDeviation.xlsx"String testResultPath = testRunner.testCase.testSuite.project.getPropertyValue( "testResultPath" )//  Get allowable deviationHashMap dataDeviationMap = getAllowableDeviation(dataDeviationFile)// Get responsedef groovyUtils = new GroovyUtils( context )def xmlHolderLive = groovyUtils.getXmlHolder( prePreStepName+"#ResponseAsXml" )def xmlHolderTP = groovyUtils.getXmlHolder( previousStepName+"#ResponseAsXml" )// Get recordsdef nodesArrayLive = xmlHolderLive.getDomNodes("//B/I" )def nodesArrayTP =xmlHolderTP.getDomNodes("//B/I")List nodesListLive = nodesArrayLive.toList()List nodesListTP = nodesArrayTP.toList()int recordsNumberLive = nodesListLive.size()int recordsNumberTP = nodesListTP.size()log.info "Total Records Number on Live = "+recordsNumberLivelog.info "Total Records Number on TP = "+recordsNumberTP// Failed recordsint failedRecordsNumber=0// Get Map of Data ID and Data NamegetMapOfDataIdAndNameFromExternelFile(dataIdMappingFile)HashMap dataIDAndNameMap = new HashMap()dataIDAndNameMap = getMapOfDataIdAndNameFromExternelFile(dataIdMappingFile)def attributesNumber = nodesListLive.get(0).attributes.getLength()// Get Map of Data Name and Data ValueHashMap  recordMapLive = new HashMap()HashMap  recordMapTP = new HashMap()def dataNamedef dataValuerecordMapLive = getRecordMap(nodesListLive,recordsNumberLive,attributesNumber,dataIDAndNameMap,recordMapLive)recordMapTP = getRecordMap(nodesListTP,recordsNumberTP,attributesNumber,dataIDAndNameMap,recordMapTP)// Compare data value on TP and Live based on tickerIterator iter = recordMapLive.entrySet().iterator()while (iter.hasNext()) {	Map.Entry entry = (Map.Entry) iter.next()	def ticker = entry.getKey()	HashMap dataMapLive = entry.getValue()	HashMap dataMapTP =recordMapTP.get(ticker)	Iterator iter2 = dataMapLive.entrySet().iterator()	while (iter2.hasNext()) {		Map.Entry entry2 = (Map.Entry) iter2.next()		def dataNameLive = entry2.getKey()		def dataValueLive = entry2.getValue()		def dataValueTP = dataMapTP.get(dataNameLive)		if(dataValueTP==null){			failMessage = "Ticker = "+ticker+" , Data Point = "+dataNameLive+" , TP = "+"Not Exist"+" , Live = "+dataValueLive  			failMessageList.add(failMessage)		}				if(dataValueLive != dataValueTP){			 if(((dataValueTP=="")&&(dataValueTP!=""))||((dataValueTP!="")&&(dataValueTP==""))){	        		failMessage = "Ticker = "+ticker+" , Data Point = "+dataNameLive+" , TP = "+dataValueTP+" , Live = "+dataValueLive       			failMessageList.add(failMessage)	    		}	    					if(dataValueLive.isFloat()&&dataValueTP.isFloat()){				allowableDeviation = dataDeviationMap.get(dataNameLive)				if(allowableDeviation==null){					allowableDeviation=0				}				addFailMessageAboutFloatDiff(failMessageList,ticker,dataNameLive,dataValueTP,dataValueLive, allowableDeviation)			}			else{				failMessage = "Ticker = "+ticker+" , Data Point = "+dataNameLive+" , TP = "+dataValueTP+" , Live = "+dataValueLive       			failMessageList.add(failMessage)			}		}	}}	// Get total data points numberint totalDataPointsNumber = recordsNumberLive*attributesNumberlog.info "Total Data Points Number = "+totalDataPointsNumber// Get failed data points numberint failedDataPointsNumber = failMessageList.size()log.info "Failed Data Points Number = "+failedDataPointsNumberdef failedPercentage = failedDataPointsNumber/totalDataPointsNumberlog.error "Failed Data Points Percentage = "+((int)(failedPercentage*10000))/100+"%"// Print out all failed data pointsif(failedDataPointsNumber>0){	def testResultFile = new File(testResultPath+ currentStepName+".txt")       if (testResultFile.exists()) {		 testResultFile.delete()     }	for(j=0; j
allowableDeviation){ failMessage ="Ticker = "+ticker+" , Data Point = "+dataName+" , TP = "+dataValueTP+" , Live = "+dataValueLive+" , Allowable Deviation = "+allowableDeviation failMessageList.add(failMessage) }}// Get allowable deviation from externel filedef getAllowableDeviation(String dataDeviationFile){ HashMap map = new HashMap() File file = new File(dataDeviationFile) try{ XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(dataDeviationFile)) XSSFSheet sheet = wb.getSheetAt(0) Row row Cell cellDataName Cell cellDataDeviation int rows = sheet.physicalNumberOfRows def dataName def dataDeviation (1..
row = sheet.getRow(r) if (row != null){ cellDataName = row.getCell(1) cellDataDeviation = row.getCell(2) if (cellDataName != null){ dataName = cellDataName.getStringCellValue() } if (cellDataDeviation != null){ switch (cellDataDeviation.getCellType()){ case cellDataDeviation.CELL_TYPE_NUMERIC: dataDeviation = cellDataDeviation.getNumericCellValue() break case cellDataDeviation.CELL_TYPE_STRING: dataDeviation = cellDataDeviation.getStringCellValue() break case cellDataDeviation.CELL_TYPE_BLANK: break default: break } } } map.put(dataName,dataDeviation) } return map } catch (Exception e){ log.info "Exception :" + e.getMessage() }}

  

 

转载于:https://www.cnblogs.com/MasterMonkInTemple/p/4635721.html

你可能感兴趣的文章
向后兼容,向前兼容
查看>>
C++ activemq CMS 学习笔记
查看>>
Linux tcpdump命令详解
查看>>
移动端标签
查看>>
移动端开发的一些技巧总结(1)
查看>>
dubbo 面试题
查看>>
android应用proguard混淆打包
查看>>
Laravel Create Facade
查看>>
【iOS系列】-UIButton的非常规使用
查看>>
理解PHP面向对象三大特性
查看>>
json学习系列(6)JSONObject和JSONArray是JDK的集合部分延伸
查看>>
TPS和QPS的区别
查看>>
day 016 面向对象---类与类的关系
查看>>
Java处理乱码问题
查看>>
冒泡排序
查看>>
常用NFS mount选项介绍
查看>>
Nand Flash与Nor
查看>>
一个非常好用的前端JS框架-AngularJS(一)
查看>>
Java EE 学习(7):IDEA + maven + spring 搭建 web(3)- 配置数据库
查看>>
webpack打包时修改package.json的版本号,并输出相关版本
查看>>