bug: fix validations for xml #1494 (#1495)

This commit is contained in:
Javier Alejandro Miño
2020-09-07 02:07:20 -05:00
committed by GitHub
parent 8cfff1caa3
commit 0f338ca5a0
3 changed files with 24 additions and 1 deletions

View File

@@ -220,7 +220,7 @@ class XmlToXPathsConverter {
private static List<Node> addValueNodes(Node node, List<List<Node>> valueNodes, List<Node> attributes) {
getChildNodesAsList(node).each {
attributes.addAll(getAttributesAsList(node))
attributes.addAll(getAttributesAsList(it))
if (isValueNode(it) && !isBlank(it.nodeValue)) {
valueNodes << withParents(it)
}

View File

@@ -312,6 +312,11 @@ class WireMockXmlStubStrategySpec extends Specification implements WireMockStubV
"expression": "/test/alpha/text()",
"equalTo": "abc"
}
}, {
"matchesXPath" : {
"expression" : "/test/duck/@type",
"equalTo" : "xtype"
}
}, {
"matchesXPath": {
"expression": "/test/duck/text()",

View File

@@ -17,6 +17,12 @@ class XmlToXPathsConverterSpec extends Specification {
String unnamedXml = '''<customer>
<email>customer@test.com</email>
</customer>
'''
@Shared
String attributesInChildXml = '''<customer first_custom_attribute="first_value">
<email second_custom_attribute="second_value" >customer@test.com</email>
<address third_custom_attribute="third_value"/>
</customer>
'''
@Unroll
@@ -39,6 +45,18 @@ class XmlToXPathsConverterSpec extends Specification {
e.message.contains('Prefix must resolve to a namespace: ns1')
}
@Unroll
def "should generate matched path [#expectedValue] for xPath [#value]"() {
expect:
value == expectedValue
where:
value || expectedValue
XmlToXPathsConverter.mapToMatchers(attributesInChildXml).get(0).path() || '''/customer/email/text()'''
XmlToXPathsConverter.mapToMatchers(attributesInChildXml).get(1).path() || '''/customer/@first_custom_attribute'''
XmlToXPathsConverter.mapToMatchers(attributesInChildXml).get(2).path() || '''/customer/email/@second_custom_attribute'''
XmlToXPathsConverter.mapToMatchers(attributesInChildXml).get(3).path() || '''/customer/address/@third_custom_attribute'''
}
@Unroll
def "should remove elements to [#expectedValue] for xPath [#value]"() {
given: