New to Groovy and a bit of a novice with coding overall but I'm trying so please bear with me. Apologies in advance if I don't but enough detail as to what I'm trying to achieve here!
I am writing a scripted test in SOAPUI for a SOAP call that has multiple instances of the same named node ("//ns2:AddOnCode"). I have expected results of what values I am expecting to return in the instances of this node.
So far I have created the following which works in terms of it only passes if all of these values are present. But I'd like to take this one step further and get the test to fail if this node is returned with a value that I havent defined.
So if say all these 5 values returned but also a 6th //ns2:AddOnCode value came with say '999' then I'd like this test to fail.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
assert holder["//ns2:AddOnCode"].contains('029')
assert holder["//ns2:AddOnCode"].contains('030')
assert holder["//ns2:AddOnCode"].contains('040')
assert holder["//ns2:AddOnCode"].contains('083')
assert holder["//ns2:AddOnCode"].contains('105')
Below is my response. You can see there are various instances of AddOnCode and these are what I am intereted in testing. My asserts above succesfully pass as all five of these are present in the response but I need to add a further step to look for any other AddOnCode values that are not in my list of assert values.
<ns2:AddOnService>
<ns2:AddOnCode>029</ns2:AddOnCode>
<ns2:AddOnDesc>OVERPAYMENT</ns2:AddOnDesc>
</ns2:AddOnService>
<ns2:AddOnService>
<ns2:AddOnCode>030</ns2:AddOnCode>
<ns2:AddOnDesc>REWARDS POOL</ns2:AddOnDesc>
</ns2:AddOnService>
<ns2:AddOnService>
<ns2:AddOnCode>040</ns2:AddOnCode>
<ns2:AddOnDesc>NON URGENT</ns2:AddOnDesc>
</ns2:AddOnService>
<ns2:AddOnService>
<ns2:AddOnCode>083</ns2:AddOnCode>
<ns2:AddOnDesc>EXGRATIA</ns2:AddOnDesc>
</ns2:AddOnService>
<ns2:AddOnService>
<ns2:AddOnCode>105</ns2:AddOnCode>
<ns2:AddOnDesc>MISC NON CLAIMABLE</ns2:AddOnDesc>
</ns2:AddOnService>
</ns2:AddOnServices>
assert ! holder["//ns2:AddOnCode"].contains('999')- daggett