找不到com.eviware.soapui.support.XmlHolder(java.io.StringWriter)的匹配构造函数

时间:2017-07-12 19:26:41

标签: arrays json xml groovy soapui

我正在尝试将数据库值与soapui上的API值进行比较,相同的测试用例但步骤不同。

第一步存储数据库中的列表,第二步将值与API

进行比较

数据库响应:

<Results>
   <ResultSet fetchSize="128">
      <Row rowNumber="1">
         <PortalId>87776</PortalId>
         <ItemKey>Asset</ItemKey>
         <ItemValue>Customer Equipment</ItemValue>
         <ItemPluralValue>Customer Equipment</ItemPluralValue>
      </Row>
      <Row rowNumber="2">
         <PortalId>87776</PortalId>
         <ItemKey>AssignedBy</ItemKey>
         <ItemValue>Assigned By</ItemValue>
         <ItemPluralValue>Assigned By</ItemPluralValue>
      </Row>
      <Row rowNumber="3">
         <PortalId>87776</PortalId>
         <ItemKey>AssignedTo</ItemKey>
         <ItemValue>Assign/Appointment</ItemValue>
         <ItemPluralValue>Assign/Appointment</ItemPluralValue>
      </Row>
   </ResultSet>
</Results>

保存数据库响应的脚本:

import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase

//Create the xml holder object for the jdbc response
def holder = new XmlHolder(messageExchange.responseContent)


def nodes = holder.getDomNodes( "//Row" )

// create list of XML strings
def list = []

for( node in nodes )
{
   java.io.StringWriter writer = new java.io.StringWriter()
   com.eviware.soapui.support.xml.XmlUtils.serialize( node, writer )
   list.add( writer )
}

// store in context for later access
//this is really hacky
WsdlTestCase.metaClass.myList = list

这可以按预期工作

然后编写脚本以比较其他步骤中的值

JSON回复:

{
   "totalRows": 32,
   "results":    [
            {
         "key": "Asset",
         "value": "Customer Equipment",
         "pluralValue": "Customer Equipment",
         "portalId": 87776
      },
            {
         "key": "AssignedBy",
         "value": "Assigned By",
         "pluralValue": "Assigned By",
         "portalId": 87776
      },
            {
         "key": "AssignedTo",
         "value": "Assign/Appointment",
         "pluralValue": "Assign/Appointment",
         "portalId": 87776
      }]
}

第二个脚本;

import com.eviware.soapui.support.XmlHolder
import net.sf.json.groovy.JsonSlurper

//get dictList from previous step
def dictList = context.testCase.myList

//get json from response
def jsonResponse = new JsonSlurper().parseText(messageExchange.responseContent)

//put json response to an array
def list = jsonResponse.results 

//enumarate the array
list.eachWithIndex { item, index ->

        def dict = dictList[index]
        def obj = item

    //put the dict xml to a var
    def holder = new XmlHolder(dict)

    //compare the database values to API Values
    assert obj.key == holder.getNodeValue('//*:ItemKey') 
    assert obj.value == holder.getNodeValue('//*:ItemValue') 
    assert obj.pluralValue == holder.getNodeValue('//*:ItemPluralValue') 
    assert obj.portalId.toString() == holder.getNodeValue('//*:PortalId')
}

现在两个脚本都有 import com.eviware.soapui.support.XmlHolder

但是第二个脚本失败并出现以下错误:

  

无法找到com.eviware.soapui.support.XmlHolder(java.io.StringWriter)的匹配构造函数

为什么?

2 个答案:

答案 0 :(得分:1)

以下是Json测试步骤的脚本断言。

请按照在线评论了解更多详情。

//Script Assertion for the Json Step
assert context.response, 'Response is empty or null'

//Replace the JdbcStepName in the below
def parsedXml = new XmlSlurper().parseText(context.testCase.testSteps['JdbcStepName'].responseContent)

//Json response - which is current step
def parsedJson = new groovy.json.JsonSlurper().parseText(context.response)

//Sort the list of maps using below criteria
def sortByKey = {a, b -> a.key <=> b.key }

//Create the list from jdbc xml response and sort it
def buildXmlDataList = {
    parsedXml.'**'.findAll{ it.name() == 'Row'}.collect{ [key: it.ItemKey.text(), value: it.ItemValue.text(), pluralValue: it.ItemPluralValue.text(), portalId: it.PortalId.text() as Integer]}.sort(sortByKey)
} 

//Create the list from json response and sort it
def buildJsonDataList = {
    parsedJson.results.sort(sortByKey)
}

//Pring it; if using in soapui then use log.info instead of println
println buildXmlDataList()
println buildJsonDataList()

//Assert both the data
assert buildXmlDataList() == buildJsonDataList()

请注意,上面的脚本确实直接读取了Jdbc Xml Response,而不是使用metaClass将其存储在WsdlTestCase,而这并不是真正需要的。

答案 1 :(得分:0)

在第一个脚本中

创建NO flex-wrap: wrap, so it not respects the flex 33% <br/> <header class="horizontal-layout"> <span class="button">A</span> <span class="app-name">B</span> <span class="button">C</span> <span class="button">D</span> </header> <br/><br/> WITH flex-wrap: wrap : I expect to have 3 boxes in first row and D box in a down<br/> <header id="with-border-padding" class="horizontal-layout"> <span class="button">A</span> <span class="app-name">B</span> <span class="button">C</span> <span class="button">D</span> </header>列表 并将其存储到new java.io.StringWriter()

在第二个脚本中,您尝试为myList的每个项创建com.eviware.soapui.support.XmlHolder,并且此类中没有此类构造函数接受StringWriter作为参数。

只需在第一行中更改此行:

myList

到这个

list.add( writer )