citrusframework / yaks

YAKS is a platform to enable Cloud Native BDD testing on Kubernetes
Apache License 2.0
83 stars 27 forks source link

XML over HTTP: CitrusRuntimeException: Failed to find proper message validator for message #395

Closed gerrym7 closed 2 years ago

gerrym7 commented 2 years ago

I have something like the following feature file:

Feature: Sample Feature

  Background:
    Given variables
      | traceId          | citrus:randomUUID() |
      | traceIdInvalid   | citrus:randomUUID() |

  Scenario: Valid SOAP Request
    Given URL: http://random-validation.mysandbox.svc:8090
    Given HTTP request headers
      | Accept          | application/xml |
      | Content-type    | application/xml |
      | SOAPAction      | http://expectedSoapAction/ExecuteRandomAction |
    Given HTTP request body
    """
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ci="http://ci.random.action">
      <soapenv:Header/>
      <soapenv:Body>
        <ci:ExecuteRandomAction>
          <ci:TheAction>
            <ci:TheId>${traceId}</ci:TheId>
          </ci:TheAction>
        </ci:ExecuteRandomAction>
      </soapenv:Body>
    </soapenv:Envelope>
    """
    When send POST /executeaction
    Then expect HTTP response expression: //ns2:Success="false"
    Then receive HTTP 200 OK

The response would look something like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
       <ns2:ExecuteRandomActionResponse 
            xmlns:ns2="xmlns:ci="http://ci.random.action" 
            xmlns:ns3="http://another.name.space" 
            xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/">
         <ns2:RandomActionResponse>
            <ns2:Success>false</ns2:Success>
            <ns2:ErrorCode>ValidationError</ns2:ErrorCode>
            <ns2:ErrorMessage>Missing Value.</ns2:ErrorMessage>
         </ns2:RandomActionResponse>
      </ns2:ExecuteRandomActionResponse>
   </soap:Body>
</soap:Envelope>

The Then expect HTTP response expression seems to work for JSON jsonpath, but not for XML xpath with namespaces. Am I doing this wrong?

christophd commented 2 years ago

XML validation is not part of the default YAKS runtime. So you need to add this validation module explicitly, You can do this in your feature file by adding the following tag at the top of the feature file:

@require(com.consol.citrus:citrus-validation-xml:@citrus.version@)

As an alternative you can add the validation module as a dependency to the yaks-config.yaml

config:
  runtime:
    settings:
      dependencies:
        - groupId: com.consol.citrus
          artifactId: citrus-validation-xml
          version: "@citrus.version@"

This should fix your error CitrusRuntimeException: Failed to find proper message validator for message

gerrym7 commented 2 years ago

Thank you, it works!