简体   繁体   English

使用 XML 的 Spring Cloud 合同。 尝试根据请求指定模拟

[英]Spring cloud contract with XML. Trying to specify mock depend on request

In the most cases I can specify mock via element content-type and the value inside of it.在大多数情况下,我可以通过元素内容类型和其中的值来指定模拟。 I'm connecting it with xpath and everything is going well.我正在将它与 xpath 连接,一切顺利。 But now i got a case where inside wsdl every xsd got the same content-type.但是现在我遇到了一个案例,在 wsdl 中,每个 xsd 都有相同的内容类型。 I have no idea how I can make a condition to specify concrete mock.我不知道如何制定条件来指定具体的模拟。 I guess the only thing which is different in every xsd inside this url is root element.我想这个 url 中每个 xsd 中唯一不同的是根元素。 Have u got any solution?你有什么解决办法吗? Do u think it is possible to specify mock depend on request root element and how ?你认为可以根据请求根元素以及如何指定模拟吗? This is example of my contract这是我的合同的例子

Contract.make {
        request {
            priority(1)
            method 'POST'
            url '/ws/xxxx/xxx'
            body(new MatchingStrategy(anyNonEmptyString(), MatchingStrategy.Type.MATCHING))
            bodyMatchers {
                xPath("//*[local-name()='Chnl']/text()", new MatchingTypeValue(MatchingType.EQUALITY, "xxx"))
            }
            headers {
                header(contentType(), regex('application/.*xml.*xxxxxxx.*'))
            }
        }
        response {
            status 200
            body(fileAsBytes("xxxx.xml"))
            headers {
                contentType(applicationXml())
            }
        }
    }

我通过在 bodyMatcher 中为主 xml 元素添加新的 xpath 条件解决了我的问题。

xPath("//*[local-name()='Body']", new MatchingTypeValue(MatchingType.REGEX, ".*nameOfRootXmlElement.*"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM