Citrus Framework - Validate JSON response with Java DSL

995 views Asked by At

I have checked the Citrus documentation, but I could not find an example. My code is in the following style:

   http()
        .client(something)
        .receive()
        .response(HttpStatus.OK)
        .messageType(MessageType.JSON);

How can I check a token in the JSON response, that it contains only numbers and letters for instance with regular expressions?

1

There are 1 answers

0
Christoph Deppisch On BEST ANSWER

You can use JsonPath expressions in combination with RegExp validation matchers.

http()
    .client(something)
    .receive()
    .response(HttpStatus.OK)
    .messageType(MessageType.JSON)
    .validate("$.user.name", "Penny")
    .validate("$.user.aliases", "@matches('[a-z0-9]')@");

Also see documentation here

http://www.citrusframework.org/reference/html/json-path.html http://www.citrusframework.org/reference/html/validation-matchers.html