karate icon indicating copy to clipboard operation
karate copied to clipboard

Namespaces declared in Soap:Envelope ignored when comparing SOAP response with expected value

Open bouncysteve opened this issue 6 months ago • 2 comments

I am testing a soap service which sometimes returns nil elements, defined in xsi namespace. Unlike issue #754, the xsi namespace is defined in the response, it is declared in the soap envelope, so that this test using locally defined xml will pass:

Scenario:

        * def content =
        """
        <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Body>
        <GetNextDeparturesResponse xmlns="http://gndrurl">
        <DeparturesBoard
        xmlns:c6="http://c6url"
        xmlns:t13="http://t13url">
        <t13:destination>
        <t13:service xsi:nil="true"/>
        </t13:destination>
        </DeparturesBoard>
        </GetNextDeparturesResponse>
        </soap:Body>
        </soap:Envelope>
        """

        * def content2 =
        """
        <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Body>
        <GetNextDeparturesResponse xmlns="http://gndrurl">
        <DeparturesBoard
        xmlns:c6="http://c6url"
        xmlns:t13="http://t13url">
        <t13:destination>
        <t13:service xsi:nil="true"/>
        </t13:destination>
        </DeparturesBoard>
        </GetNextDeparturesResponse>
        </soap:Body>
        </soap:Envelope>
        """
        
        * match content == content2

However, a scenario where a SOAP request produces the same XML in the response will fail on the match statement:

 ...
 Then match soapCall.response == content2
 ...
javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared.

This looks like a problem in the handling of the response when used in match, as if it is being treated differently to any other xml document, perhaps by stripping the soap wrapper from both documents before comparing, so that the xsi namespace declaration is lost?

Note that this problem happens regardless of the value of xmlNamespaceAware

bouncysteve avatar Dec 22 '23 14:12 bouncysteve