码迷,mamicode.com
首页 > 其他好文 > 详细

[Groovy]获取当前活动的Environment,获取response中节点的name和节点的value

时间:2015-06-24 10:51:47      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

import com.eviware.soapui.support.GroovyUtils
import com.eviware.soapui.support.XmlHolder
import org.w3c.dom.Node
import org.apache.commons.lang.StringUtils
import java.util.HashSet

def groovyUtils = new GroovyUtils(context)
def xmlHolder = groovyUtils.getXmlHolder(messageExchange.getResponseContent())
def activeEnv = context.expand( ‘${#Project#activeEnv}‘ )
log.info "The active environment is $activeEnv"

String[] fixClientIdArray 
if(activeEnv=="LIVE"){
 fixClientIdArray = new String[2]
 fixClientIdArray[0] =       "6e2ba3e9-68a4-4c8f-a164-f026e7239cf7"
 fixClientIdArray[1] =      "dfba4888-348a-4fb1-91f7-8a03fb6aa775" 
}

if(activeEnv=="QA"){
 fixClientIdArray = new String[3]
 fixClientIdArray[0] =      "6fe9b969-3711-4083-a8c4-186e75e6e9e7"
 fixClientIdArray[1] =      "43ec112f-cd57-4d84-a5e8-1d62e1f71244"
 fixClientIdArray[2] =      "8c8e3e6a-0cb1-41d0-a07b-ca3fff506cee"
}

def fixSet = new HashSet()

for(String clientId : fixClientIdArray){
	fixSet.add(clientId)
}

String xPath = "//clients/client"
Node[] nodeArray = xmlHolder.getDomNodes(xPath)
int actualCount = nodeArray.length
int expectedCount = context.expand(‘${#Project#ClientCount}‘).toInteger()

assert fixSet.size() == expectedCount

log.info "Actual : nodeArray.length of  "+xPath+" : "+actualCount
log.info "Expected : nodeArray.length  is : "+expectedCount
assert actualCount==expectedCount

String clientIdPath = xPath + "/@id"

String[] valueArray = xmlHolder.getNodeValues(clientIdPath)
log.info "valueArray.length of "+clientIdPath+":"+valueArray.length
assert valueArray != null && valueArray.length>0
for(String value : valueArray){
	log.info "value:"+value
	assert StringUtils.isNotBlank(value)
	assert fixSet.contains(value)

	fixSet.remove(value)
}

assert fixSet.size() == 0

 

[Groovy]获取当前活动的Environment,获取response中节点的name和节点的value

标签:

原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4596951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!