本記事の概要
Webサービス(SOAP編)その3ではSoapUIのGroovy Scriptでログ出力プログラムを作成します。
【前提条件】
- Webサービス(SOAP編)その2 まで実施済みであること。
プログラム作成
以下の Groovy Script を作成します。
LoggerXml
SOAPリクエスト情報とレスポンス情報をログファイルとして出力するスクリプトのサンプルとなります。
// TestCaseName
def testCaseName = testRunner.testCase.name
// Date format
def fileNameDate = new Date().format("yyyyMMddHHmmss")
def resultListFileNameDate = new Date().format("yyyyMMddHH")
// TestTime
def testTime = new Date()
// Log File Path
def dir = testRunner.testCase.testSuite.project.getPropertyValue("outLogPath")
// Log File Name
def fileName = "${testCaseName}_${fileNameDate}.log"
def testCaseFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("resultListFilePrefix")
def testResultListCsvFileName = "${testCaseFIlePrefix}_${resultListFileNameDate}.csv"
def testAssertionFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("assertionListFilePrefix")
def testAssertionListCsvFileName = "${testAssertionFIlePrefix}_${resultListFileNameDate}.csv"
// Output File
def outputFile = new File(dir, fileName)
def testResultListFile = new File(dir, testResultListCsvFileName)
def testAssertionListFile = new File(dir, testAssertionListCsvFileName)
// Log title
outputFile.append("########################################\n")
outputFile.append("# " + testCaseName + "\n")
outputFile.append("########################################\n")
// Test time
outputFile.append("Test time: " + testTime + "\n")
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -1 )
outputFile.append("\n")
// Request message
outputFile.append("### Request message ###\n")
if(previousStep.testRequest.getRequestContent() != null){
outputFile.append(new String(previousStep.testRequest.getRequestContent()))
}
outputFile.append("\n\n")
// Response message
outputFile.append("### Response message ###\n")
if(previousStep.testRequest.getResponse() != null){
outputFile.append(previousStep.testRequest.getResponse().getResponseHeaders())
outputFile.append(previousStep.testRequest.getResponse().getContentAsXml())
}
//def resXmlStr = new String(previousStep.testRequest.messageExchange.rawResponseData)
//outputFile.append(resXmlStr.replaceAll(/>,">\n<"))
outputFile.append("\n")
// Step Index
def stepIdx = 0
// Assertion Index
def assertionIdx = 0
// testRunner size
def resCount = testRunner.results.size()
// Test Target
def testTarget = ""
// Get testCase result
for (testCaseResult in testRunner.results){
// Step Index
stepIdx = stepIdx +1
// Judge Test Target
if (resCount==stepIdx){
testTarget = "Target"
} else {
testTarget = "NotTarget"
}
testResultListFile.append("${testCaseName}")
testResultListFile.append(","+stepIdx)
testResultListFile.append(","+testTarget)
testResultListFile.append(","+testCaseResult.getStatus().toString())
testResultListFile.append("\n")
// Initialize Assertion Index
assertionIdx = 0
// Get Assertion List
for (assertion in testCaseResult.getTestStep().getAssertionList()) {
// Increment
assertionIdx = assertionIdx +1
// Assertion Result
testAssertionListFile.append("${testCaseName}")
testAssertionListFile.append(","+stepIdx)
testAssertionListFile.append(","+testTarget)
testAssertionListFile.append(","+assertionIdx)
testAssertionListFile.append(","+testCaseResult.getTestStep().name)
testAssertionListFile.append(","+assertion.getLabel())
testAssertionListFile.append(","+assertion.getStatus())
testAssertionListFile.append(","+assertion.getErrors())
testAssertionListFile.append("\n")
}
}
SaveResponse
SOAPレスポンス情報をSoapUIのプロパティに保存するサンプルです。
import com.eviware.soapui.support.XmlHolder
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -2 )
// Response message
def resXml = previousStep.testRequest.getResponse().getContentAsXml()
XmlHolder holder = new XmlHolder(resXml)
holder.declareNamespace('ns2',"http://jaxws.example/")
def answer = holder.getNodeValue('//ns2:addResponse/return/calcRes/answer')
// Save Response
if (answer != "0") {
testRunner.testCase.testSuite.setPropertyValue("answer",answer)
}
SoapUIプロジェクト定義(サンプル)
Calculator-soapui-project.xml
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project id="a3087123-a584-4ff4-a6b0-e26b9ec6c212" activeEnvironment="Default" name="Calculator" resourceRoot="" soapui-version="5.5.0" abortOnError="false" runType="SEQUENTIAL" xmlns:con="http://eviware.com/soapui/config"><con:settings/><con:interface xsi:type="con:WsdlInterface" id="c9ae9265-0595-4203-9a65-84d677790dab" wsaVersion="NONE" name="CalculatorPortBinding" type="wsdl" bindingName="{http://jaxws.example/}CalculatorPortBinding" soapVersion="1_1" anonymous="optional" definition="http://localhost:8080/Calculator?wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:settings/><con:definitionCache type="TEXT" rootPart="http://localhost:8080/Calculator?wsdl"><con:part><con:url>http://localhost:8080/Calculator?wsdl</con:url><con:content><![CDATA[<!--Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.-->
<!--Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.-->
<definitions targetNamespace="http://jaxws.example/" name="CalculatorService" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://jaxws.example/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema>
<xsd:import namespace="http://jaxws.example/" schemaLocation="http://localhost:8080/Calculator?xsd=1"/>
</xsd:schema>
</types>
<message name="add">
<part name="parameters" element="tns:add"/>
</message>
<message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
<message name="sub">
<part name="parameters" element="tns:sub"/>
</message>
<message name="subResponse">
<part name="parameters" element="tns:subResponse"/>
</message>
<message name="mul">
<part name="parameters" element="tns:mul"/>
</message>
<message name="mulResponse">
<part name="parameters" element="tns:mulResponse"/>
</message>
<message name="div">
<part name="parameters" element="tns:div"/>
</message>
<message name="divResponse">
<part name="parameters" element="tns:divResponse"/>
</message>
<portType name="Calculator">
<operation name="add">
<input wsam:Action="http://jaxws.example/Calculator/addRequest" message="tns:add"/>
<output wsam:Action="http://jaxws.example/Calculator/addResponse" message="tns:addResponse"/>
</operation>
<operation name="sub">
<input wsam:Action="http://jaxws.example/Calculator/subRequest" message="tns:sub"/>
<output wsam:Action="http://jaxws.example/Calculator/subResponse" message="tns:subResponse"/>
</operation>
<operation name="mul">
<input wsam:Action="http://jaxws.example/Calculator/mulRequest" message="tns:mul"/>
<output wsam:Action="http://jaxws.example/Calculator/mulResponse" message="tns:mulResponse"/>
</operation>
<operation name="div">
<input wsam:Action="http://jaxws.example/Calculator/divRequest" message="tns:div"/>
<output wsam:Action="http://jaxws.example/Calculator/divResponse" message="tns:divResponse"/>
</operation>
</portType>
<binding name="CalculatorPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="add">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sub">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="mul">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="div">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CalculatorService">
<port name="CalculatorPort" binding="tns:CalculatorPortBinding">
<soap:address location="http://localhost:8080/Calculator"/>
</port>
</service>
</definitions>]]></con:content><con:type>http://schemas.xmlsoap.org/wsdl/</con:type></con:part><con:part><con:url>http://localhost:8080/Calculator?xsd=1</con:url><con:content><![CDATA[<!--Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.-->
<xs:schema version="1.0" targetNamespace="http://jaxws.example/" xmlns:tns="http://jaxws.example/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="add" type="tns:add"/>
<xs:element name="addResponse" type="tns:addResponse"/>
<xs:element name="calcReq" type="tns:calcReq"/>
<xs:element name="calcRes" type="tns:calcRes"/>
<xs:element name="div" type="tns:div"/>
<xs:element name="divResponse" type="tns:divResponse"/>
<xs:element name="mul" type="tns:mul"/>
<xs:element name="mulResponse" type="tns:mulResponse"/>
<xs:element name="request" type="tns:reqIF"/>
<xs:element name="result" type="tns:resIF"/>
<xs:element name="sub" type="tns:sub"/>
<xs:element name="subResponse" type="tns:subResponse"/>
<xs:complexType name="sub">
<xs:sequence>
<xs:element name="arg0" type="tns:reqIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="reqIF">
<xs:sequence>
<xs:element name="calcReq" type="tns:calcReq" minOccurs="0"/>
<xs:element name="precision" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="calcReq">
<xs:sequence>
<xs:element name="param1" type="xs:string" minOccurs="0"/>
<xs:element name="param2" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="subResponse">
<xs:sequence>
<xs:element name="return" type="tns:resIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="resIF">
<xs:sequence>
<xs:element name="returnCd" type="xs:int"/>
<xs:element name="calcRes" type="tns:calcRes" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="calcRes">
<xs:sequence>
<xs:element name="answer" type="xs:string" minOccurs="0"/>
<xs:element name="remainder" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="add">
<xs:sequence>
<xs:element name="arg0" type="tns:reqIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addResponse">
<xs:sequence>
<xs:element name="return" type="tns:resIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="div">
<xs:sequence>
<xs:element name="arg0" type="tns:reqIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="divResponse">
<xs:sequence>
<xs:element name="return" type="tns:resIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="mul">
<xs:sequence>
<xs:element name="arg0" type="tns:reqIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="mulResponse">
<xs:sequence>
<xs:element name="return" type="tns:resIF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>]]></con:content><con:type>http://www.w3.org/2001/XMLSchema</con:type></con:part></con:definitionCache><con:endpoints><con:endpoint>http://localhost:8080/Calculator</con:endpoint></con:endpoints><con:operation id="0c6184d5-f956-4d40-ada3-af1040ea0d33" isOneWay="false" action="" name="add" bindingOperationName="add" type="Request-Response" inputName="" receivesAttachments="false" sendsAttachments="false" anonymous="optional"><con:settings/><con:call id="24a793ab-04ff-4787-bd99-21d945f0c535" name="Request 1"><con:settings/><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:add>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>?</param1>\r
<!--Optional:-->\r
<param2>?</param2>\r
</calcReq>\r
<precision>?</precision>\r
</arg0>\r
</jax:add>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://jaxws.example/Calculator/addRequest"/></con:call></con:operation><con:operation id="c187ad76-806a-4531-af55-16a271b69a78" isOneWay="false" action="" name="div" bindingOperationName="div" type="Request-Response" inputName="" receivesAttachments="false" sendsAttachments="false" anonymous="optional"><con:settings/><con:call id="5c3a4411-ec7f-476b-b390-a75beffe5fb7" name="Request 1"><con:settings/><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:div>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>?</param1>\r
<!--Optional:-->\r
<param2>?</param2>\r
</calcReq>\r
<precision>?</precision>\r
</arg0>\r
</jax:div>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://jaxws.example/Calculator/divRequest"/></con:call></con:operation><con:operation id="eb86274e-bd37-4e96-83b0-c96d33dbe0bc" isOneWay="false" action="" name="mul" bindingOperationName="mul" type="Request-Response" inputName="" receivesAttachments="false" sendsAttachments="false" anonymous="optional"><con:settings/><con:call id="c7e07943-cce1-492b-8c33-9c229141ee56" name="Request 1"><con:settings/><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:mul>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>?</param1>\r
<!--Optional:-->\r
<param2>?</param2>\r
</calcReq>\r
<precision>?</precision>\r
</arg0>\r
</jax:mul>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://jaxws.example/Calculator/mulRequest"/></con:call></con:operation><con:operation id="b9c2a590-4af8-4a71-9ce5-f66b6889e006" isOneWay="false" action="" name="sub" bindingOperationName="sub" type="Request-Response" inputName="" receivesAttachments="false" sendsAttachments="false" anonymous="optional"><con:settings/><con:call id="16124bbd-4d1e-43fd-aa54-f2525ac04279" name="Request 1"><con:settings/><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:sub>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>?</param1>\r
<!--Optional:-->\r
<param2>?</param2>\r
</calcReq>\r
<precision>?</precision>\r
</arg0>\r
</jax:sub>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://jaxws.example/Calculator/subRequest"/></con:call></con:operation></con:interface><con:testSuite id="72dd14c5-9fa2-4449-841a-7cc3a0adf575" name="CalculatorPortBinding TestSuite"><con:settings/><con:runType>SEQUENTIAL</con:runType><con:testCase id="015d0b4e-1945-4da0-a804-b4e9d5527b5d" failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="add TestCase" searchProperties="true"><con:settings/><con:testStep type="request" id="ad87cb25-9072-4fdf-9aba-475506db690f" name="add"><con:settings/><con:config xsi:type="con:RequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:interface>CalculatorPortBinding</con:interface><con:operation>add</con:operation><con:request name="add" id="76033630-9185-4cb6-8c0c-f0655a8935dd"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:add>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>3</param1>\r
<!--Optional:-->\r
<param2>7</param2>\r
</calcReq>\r
<precision>0</precision>\r
</arg0>\r
</jax:add>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:assertion type="XPath Match" id="d49c1f0a-237a-4089-8de5-47ca8019a7c6" name="XPath Match returnCd"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:addResponse/return/returnCd</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="5cde18b4-a639-47b2-86a3-63e63c2a6a9a" name="XPath Match calcRes.answer"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:addResponse/return/calcRes/answer</path><content>10</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="7f098967-2a2c-4c7a-a132-0feea90c17d8" name="XPath Match calcRes.remainder"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:addResponse/return/calcRes/remainder</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig action="http://jaxws.example/Calculator/addRequest" mustUnderstand="NONE" version="200508"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:testStep type="groovy" name="LoggerXml" id="af448159-845f-4823-9846-b1f8f24bc4a0"><con:settings/><con:config><script>// TestCaseName
def testCaseName = testRunner.testCase.name
// Date format
def fileNameDate = new Date().format("yyyyMMddHHmmss")
def resultListFileNameDate = new Date().format("yyyyMMddHH")
// TestTime
def testTime = new Date()
// Log File Path
def dir = testRunner.testCase.testSuite.project.getPropertyValue("outLogPath")
// Log File Name
def fileName = "${testCaseName}_${fileNameDate}.log"
def testCaseFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("resultListFilePrefix")
def testResultListCsvFileName = "${testCaseFIlePrefix}_${resultListFileNameDate}.csv"
def testAssertionFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("assertionListFilePrefix")
def testAssertionListCsvFileName = "${testAssertionFIlePrefix}_${resultListFileNameDate}.csv"
// Output File
def outputFile = new File(dir, fileName)
def testResultListFile = new File(dir, testResultListCsvFileName)
def testAssertionListFile = new File(dir, testAssertionListCsvFileName)
// Log title
outputFile.append("########################################\n")
outputFile.append("# " + testCaseName + "\n")
outputFile.append("########################################\n")
// Test time
outputFile.append("Test time: " + testTime + "\n")
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -1 )
outputFile.append("\n")
// Request message
outputFile.append("### Request message ###\n")
if(previousStep.testRequest.getRequestContent() != null){
outputFile.append(new String(previousStep.testRequest.getRequestContent()))
}
outputFile.append("\n\n")
// Response message
outputFile.append("### Response message ###\n")
if(previousStep.testRequest.getResponse() != null){
outputFile.append(previousStep.testRequest.getResponse().getResponseHeaders())
outputFile.append(previousStep.testRequest.getResponse().getContentAsXml())
}
//def resXmlStr = new String(previousStep.testRequest.messageExchange.rawResponseData)
//outputFile.append(resXmlStr.replaceAll(/></,">\n<"))
outputFile.append("\n")
// Step Index
def stepIdx = 0
// Assertion Index
def assertionIdx = 0
// testRunner size
def resCount = testRunner.results.size()
// Test Target
def testTarget = ""
// Get testCase result
for (testCaseResult in testRunner.results){
// Step Index
stepIdx = stepIdx +1
// Judge Test Target
if (resCount==stepIdx){
testTarget = "Target"
} else {
testTarget = "NotTarget"
}
testResultListFile.append("${testCaseName}")
testResultListFile.append(","+stepIdx)
testResultListFile.append(","+testTarget)
testResultListFile.append(","+testCaseResult.getStatus().toString())
testResultListFile.append("\n")
// Initialize Assertion Index
assertionIdx = 0
// Get Assertion List
for (assertion in testCaseResult.getTestStep().getAssertionList()) {
// Increment
assertionIdx = assertionIdx +1
// Assertion Result
testAssertionListFile.append("${testCaseName}")
testAssertionListFile.append(","+stepIdx)
testAssertionListFile.append(","+testTarget)
testAssertionListFile.append(","+assertionIdx)
testAssertionListFile.append(","+testCaseResult.getTestStep().name)
testAssertionListFile.append(","+assertion.getLabel())
testAssertionListFile.append(","+assertion.getStatus())
testAssertionListFile.append(","+assertion.getErrors())
testAssertionListFile.append("\n")
}
}
</script></con:config></con:testStep><con:testStep type="groovy" name="SaveResponse" id="17a973f2-3ad7-46d1-bb84-c4dee03e7e7f"><con:settings/><con:config><script>import com.eviware.soapui.support.XmlHolder
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -2 )
// Response message
def resXml = previousStep.testRequest.getResponse().getContentAsXml()
XmlHolder holder = new XmlHolder(resXml)
holder.declareNamespace('ns2',"http://jaxws.example/")
def answer = holder.getNodeValue('//ns2:addResponse/return/calcRes/answer')
// Save Response
if (answer != "0") {
testRunner.testCase.testSuite.setPropertyValue("answer",answer)
}
</script></con:config></con:testStep><con:properties/></con:testCase><con:testCase id="35bcf2d5-b4dc-4cef-a1dc-2941e37f6c3c" failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="div TestCase" searchProperties="true"><con:settings/><con:testStep type="request" id="b9c6cf7d-cc4f-4438-bdde-79ee9bd76c16" name="div"><con:settings/><con:config xsi:type="con:RequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:interface>CalculatorPortBinding</con:interface><con:operation>div</con:operation><con:request name="div" id="e6127ba3-1044-40f0-84a4-96f67a4477a3"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:div>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>30</param1>\r
<!--Optional:-->\r
<param2>7</param2>\r
</calcReq>\r
<precision>0</precision>\r
</arg0>\r
</jax:div>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:assertion type="XPath Match" id="0a21f4f6-2a64-4fa8-a47f-78d6e5dcee0e" name="XPath Match returnCd"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:divResponse/return/returnCd</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="7c47ba76-13d0-4398-a78f-a974f14a4508" name="XPath Match calcRes.answer"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:divResponse/return/calcRes/answer</path><content>4</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="c4a28bac-c3f0-409a-9074-40131f757d78" name="XPath Match calcRes.remainder"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:divResponse/return/calcRes/remainder</path><content>2</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig action="http://jaxws.example/Calculator/divRequest" mustUnderstand="NONE" version="200508"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:testStep type="groovy" name="LoggerXml" id="e2273399-855f-4dbd-86f1-64ccbd30f7be"><con:settings/><con:config><script>// TestCaseName
def testCaseName = testRunner.testCase.name
// Date format
def fileNameDate = new Date().format("yyyyMMddHHmmss")
def resultListFileNameDate = new Date().format("yyyyMMddHH")
// TestTime
def testTime = new Date()
// Log File Path
def dir = testRunner.testCase.testSuite.project.getPropertyValue("outLogPath")
// Log File Name
def fileName = "${testCaseName}_${fileNameDate}.log"
def testCaseFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("resultListFilePrefix")
def testResultListCsvFileName = "${testCaseFIlePrefix}_${resultListFileNameDate}.csv"
def testAssertionFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("assertionListFilePrefix")
def testAssertionListCsvFileName = "${testAssertionFIlePrefix}_${resultListFileNameDate}.csv"
// Output File
def outputFile = new File(dir, fileName)
def testResultListFile = new File(dir, testResultListCsvFileName)
def testAssertionListFile = new File(dir, testAssertionListCsvFileName)
// Log title
outputFile.append("########################################\n")
outputFile.append("# " + testCaseName + "\n")
outputFile.append("########################################\n")
// Test time
outputFile.append("Test time: " + testTime + "\n")
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -1 )
outputFile.append("\n")
// Request message
outputFile.append("### Request message ###\n")
if(previousStep.testRequest.getRequestContent() != null){
outputFile.append(new String(previousStep.testRequest.getRequestContent()))
}
outputFile.append("\n\n")
// Response message
outputFile.append("### Response message ###\n")
if(previousStep.testRequest.getResponse() != null){
outputFile.append(previousStep.testRequest.getResponse().getResponseHeaders())
outputFile.append(previousStep.testRequest.getResponse().getContentAsXml())
}
//def resXmlStr = new String(previousStep.testRequest.messageExchange.rawResponseData)
//outputFile.append(resXmlStr.replaceAll(/></,">\n<"))
outputFile.append("\n")
// Step Index
def stepIdx = 0
// Assertion Index
def assertionIdx = 0
// testRunner size
def resCount = testRunner.results.size()
// Test Target
def testTarget = ""
// Get testCase result
for (testCaseResult in testRunner.results){
// Step Index
stepIdx = stepIdx +1
// Judge Test Target
if (resCount==stepIdx){
testTarget = "Target"
} else {
testTarget = "NotTarget"
}
testResultListFile.append("${testCaseName}")
testResultListFile.append(","+stepIdx)
testResultListFile.append(","+testTarget)
testResultListFile.append(","+testCaseResult.getStatus().toString())
testResultListFile.append("\n")
// Initialize Assertion Index
assertionIdx = 0
// Get Assertion List
for (assertion in testCaseResult.getTestStep().getAssertionList()) {
// Increment
assertionIdx = assertionIdx +1
// Assertion Result
testAssertionListFile.append("${testCaseName}")
testAssertionListFile.append(","+stepIdx)
testAssertionListFile.append(","+testTarget)
testAssertionListFile.append(","+assertionIdx)
testAssertionListFile.append(","+testCaseResult.getTestStep().name)
testAssertionListFile.append(","+assertion.getLabel())
testAssertionListFile.append(","+assertion.getStatus())
testAssertionListFile.append(","+assertion.getErrors())
testAssertionListFile.append("\n")
}
}
</script></con:config></con:testStep><con:properties/></con:testCase><con:testCase id="0712af43-f0da-4983-835e-fb6925556d44" failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="mul TestCase" searchProperties="true"><con:settings/><con:testStep type="request" id="274e4158-19bb-453a-a72e-c1cfa6d836d3" name="mul"><con:settings/><con:config xsi:type="con:RequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:interface>CalculatorPortBinding</con:interface><con:operation>mul</con:operation><con:request name="mul" id="d4da6b70-0d21-403a-8596-857d45252188"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:mul>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>6</param1>\r
<!--Optional:-->\r
<param2>3</param2>\r
</calcReq>\r
<precision>0</precision>\r
</arg0>\r
</jax:mul>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:assertion type="XPath Match" id="f97d7eeb-2179-458f-8c37-fd96d73ce28a" name="XPath Match returnCd"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:mulResponse/return/returnCd</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="ddf5e01d-5ef1-40c8-84ed-c4baa3554d08" name="XPath Match calcRes.answer"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:mulResponse/return/calcRes/answer</path><content>18</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="4fa2e10c-fdd1-441b-8313-fe3c45ccceaf" name="XPath Match calcRes.remainder"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:mulResponse/return/calcRes/remainder</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig action="http://jaxws.example/Calculator/mulRequest" mustUnderstand="NONE" version="200508"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:testStep type="groovy" name="LoggerXml" id="4c065666-49e1-4db5-8678-0965a746d358"><con:settings/><con:config><script>// TestCaseName
def testCaseName = testRunner.testCase.name
// Date format
def fileNameDate = new Date().format("yyyyMMddHHmmss")
def resultListFileNameDate = new Date().format("yyyyMMddHH")
// TestTime
def testTime = new Date()
// Log File Path
def dir = testRunner.testCase.testSuite.project.getPropertyValue("outLogPath")
// Log File Name
def fileName = "${testCaseName}_${fileNameDate}.log"
def testCaseFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("resultListFilePrefix")
def testResultListCsvFileName = "${testCaseFIlePrefix}_${resultListFileNameDate}.csv"
def testAssertionFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("assertionListFilePrefix")
def testAssertionListCsvFileName = "${testAssertionFIlePrefix}_${resultListFileNameDate}.csv"
// Output File
def outputFile = new File(dir, fileName)
def testResultListFile = new File(dir, testResultListCsvFileName)
def testAssertionListFile = new File(dir, testAssertionListCsvFileName)
// Log title
outputFile.append("########################################\n")
outputFile.append("# " + testCaseName + "\n")
outputFile.append("########################################\n")
// Test time
outputFile.append("Test time: " + testTime + "\n")
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -1 )
outputFile.append("\n")
// Request message
outputFile.append("### Request message ###\n")
if(previousStep.testRequest.getRequestContent() != null){
outputFile.append(new String(previousStep.testRequest.getRequestContent()))
}
outputFile.append("\n\n")
// Response message
outputFile.append("### Response message ###\n")
if(previousStep.testRequest.getResponse() != null){
outputFile.append(previousStep.testRequest.getResponse().getResponseHeaders())
outputFile.append(previousStep.testRequest.getResponse().getContentAsXml())
}
//def resXmlStr = new String(previousStep.testRequest.messageExchange.rawResponseData)
//outputFile.append(resXmlStr.replaceAll(/></,">\n<"))
outputFile.append("\n")
// Step Index
def stepIdx = 0
// Assertion Index
def assertionIdx = 0
// testRunner size
def resCount = testRunner.results.size()
// Test Target
def testTarget = ""
// Get testCase result
for (testCaseResult in testRunner.results){
// Step Index
stepIdx = stepIdx +1
// Judge Test Target
if (resCount==stepIdx){
testTarget = "Target"
} else {
testTarget = "NotTarget"
}
testResultListFile.append("${testCaseName}")
testResultListFile.append(","+stepIdx)
testResultListFile.append(","+testTarget)
testResultListFile.append(","+testCaseResult.getStatus().toString())
testResultListFile.append("\n")
// Initialize Assertion Index
assertionIdx = 0
// Get Assertion List
for (assertion in testCaseResult.getTestStep().getAssertionList()) {
// Increment
assertionIdx = assertionIdx +1
// Assertion Result
testAssertionListFile.append("${testCaseName}")
testAssertionListFile.append(","+stepIdx)
testAssertionListFile.append(","+testTarget)
testAssertionListFile.append(","+assertionIdx)
testAssertionListFile.append(","+testCaseResult.getTestStep().name)
testAssertionListFile.append(","+assertion.getLabel())
testAssertionListFile.append(","+assertion.getStatus())
testAssertionListFile.append(","+assertion.getErrors())
testAssertionListFile.append("\n")
}
}
</script></con:config></con:testStep><con:properties/></con:testCase><con:testCase id="a11f12e0-e72a-4168-aa15-38fbeace38aa" failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="sub TestCase" searchProperties="true"><con:settings/><con:testStep type="request" id="c10917d7-16b3-48d0-af1a-8d32f2e09518" name="sub"><con:settings/><con:config xsi:type="con:RequestStep" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:interface>CalculatorPortBinding</con:interface><con:operation>sub</con:operation><con:request name="sub" id="9c6f7f0d-1efb-4fa6-bee8-3e8c29938464"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting></con:settings><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhost:8080/Calculator</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jax="http://jaxws.example/">\r
<soapenv:Header/>\r
<soapenv:Body>\r
<jax:sub>\r
<!--Optional:-->\r
<arg0>\r
<!--Optional:-->\r
<calcReq>\r
<!--Optional:-->\r
<param1>5</param1>\r
<!--Optional:-->\r
<param2>3</param2>\r
</calcReq>\r
<precision>0</precision>\r
</arg0>\r
</jax:sub>\r
</soapenv:Body>\r
</soapenv:Envelope>]]></con:request><con:assertion type="XPath Match" id="e7c60d84-27d5-4270-9a13-577925537c3e" name="XPath Match returnCd"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:subResponse/return/returnCd</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="0e301deb-b007-4236-bf12-d5fb66c1450b" name="XPath Match calcRes.answer"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:subResponse/return/calcRes/answer</path><content>2</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:assertion type="XPath Match" id="535de555-8c13-45f6-bdb2-d8a54f5a2b7a" name="XPath Match calcRes.remainder"><con:configuration><path>declare namespace ns2='http://jaxws.example/';
//ns2:subResponse/return/calcRes/remainder</path><content>0</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig action="http://jaxws.example/Calculator/subRequest" mustUnderstand="NONE" version="200508"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:testStep type="groovy" name="LoggerXml" id="429f7b08-e9dd-4491-961a-ff9f933fc20a"><con:settings/><con:config><script>// TestCaseName
def testCaseName = testRunner.testCase.name
// Date format
def fileNameDate = new Date().format("yyyyMMddHHmmss")
def resultListFileNameDate = new Date().format("yyyyMMddHH")
// TestTime
def testTime = new Date()
// Log File Path
def dir = testRunner.testCase.testSuite.project.getPropertyValue("outLogPath")
// Log File Name
def fileName = "${testCaseName}_${fileNameDate}.log"
def testCaseFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("resultListFilePrefix")
def testResultListCsvFileName = "${testCaseFIlePrefix}_${resultListFileNameDate}.csv"
def testAssertionFIlePrefix = testRunner.testCase.testSuite.getPropertyValue("assertionListFilePrefix")
def testAssertionListCsvFileName = "${testAssertionFIlePrefix}_${resultListFileNameDate}.csv"
// Output File
def outputFile = new File(dir, fileName)
def testResultListFile = new File(dir, testResultListCsvFileName)
def testAssertionListFile = new File(dir, testAssertionListCsvFileName)
// Log title
outputFile.append("########################################\n")
outputFile.append("# " + testCaseName + "\n")
outputFile.append("########################################\n")
// Test time
outputFile.append("Test time: " + testTime + "\n")
// Current Step Index
def currentStepIdx = context.currentStepIndex
// Previous Step
def previousStep = testRunner.testCase.getTestStepAt(currentStepIdx -1 )
outputFile.append("\n")
// Request message
outputFile.append("### Request message ###\n")
if(previousStep.testRequest.getRequestContent() != null){
outputFile.append(new String(previousStep.testRequest.getRequestContent()))
}
outputFile.append("\n\n")
// Response message
outputFile.append("### Response message ###\n")
if(previousStep.testRequest.getResponse() != null){
outputFile.append(previousStep.testRequest.getResponse().getResponseHeaders())
outputFile.append(previousStep.testRequest.getResponse().getContentAsXml())
}
//def resXmlStr = new String(previousStep.testRequest.messageExchange.rawResponseData)
//outputFile.append(resXmlStr.replaceAll(/></,">\n<"))
outputFile.append("\n")
// Step Index
def stepIdx = 0
// Assertion Index
def assertionIdx = 0
// testRunner size
def resCount = testRunner.results.size()
// Test Target
def testTarget = ""
// Get testCase result
for (testCaseResult in testRunner.results){
// Step Index
stepIdx = stepIdx +1
// Judge Test Target
if (resCount==stepIdx){
testTarget = "Target"
} else {
testTarget = "NotTarget"
}
testResultListFile.append("${testCaseName}")
testResultListFile.append(","+stepIdx)
testResultListFile.append(","+testTarget)
testResultListFile.append(","+testCaseResult.getStatus().toString())
testResultListFile.append("\n")
// Initialize Assertion Index
assertionIdx = 0
// Get Assertion List
for (assertion in testCaseResult.getTestStep().getAssertionList()) {
// Increment
assertionIdx = assertionIdx +1
// Assertion Result
testAssertionListFile.append("${testCaseName}")
testAssertionListFile.append(","+stepIdx)
testAssertionListFile.append(","+testTarget)
testAssertionListFile.append(","+assertionIdx)
testAssertionListFile.append(","+testCaseResult.getTestStep().name)
testAssertionListFile.append(","+assertion.getLabel())
testAssertionListFile.append(","+assertion.getStatus())
testAssertionListFile.append(","+assertion.getErrors())
testAssertionListFile.append("\n")
}
}
</script></con:config></con:testStep><con:properties/></con:testCase><con:properties><con:property><con:name>resultListFilePrefix</con:name><con:value>CalculatorTestResultList</con:value></con:property><con:property><con:name>assertionListFilePrefix</con:name><con:value>CalculatorAssertionList</con:value></con:property><con:property><con:name>answer</con:name><con:value>10</con:value></con:property></con:properties></con:testSuite><con:properties><con:property><con:name>outLogPath</con:name><con:value>C:\tmp</con:value></con:property></con:properties><con:wssContainer/><con:oAuth2ProfileContainer/><con:oAuth1ProfileContainer/><con:sensitiveInformation/></con:soapui-project>