citrus icon indicating copy to clipboard operation
citrus copied to clipboard

Multiple jsonPath-Validations not working

Open chokdee opened this issue 3 years ago • 3 comments

Citrus Version 3.4.0

Question Why is the following code not working:

$(http()
  .client(myclient)
  .receive()
  .response(HttpStatus.OK)
  .message()
  .type(MessageType.JSON)
  .validate(jsonPath().expression("$.name", "meier"))
  .validate(jsonPath().expression("$.vorname", "heinz"))
  .validate(jsonPath().expression("$.city", "München")));

What I've tried so far The following is working

$(http()
  .client(myclient)
  .receive()
  .response(HttpStatus.OK)
  .message()
  .type(MessageType.JSON)
  .validate(jsonPath().expression("$.name", "meier")
                      .expression("$.vorname", "heinz")
                      .expression("$.city", "München")));

Additional information I think at least an error should be thrown. In the first case only the first validation is executed. Better would be to except both variants, isn't it?

Btw: a chain of extract value is working e.g.

.extract(JsonPathSupport.jsonPath().expression("$.id", "${itemId1}"))
 .extract(JsonPathSupport.jsonPath().expression("$.barcode", "${barcode1}")))

chokdee avatar Sep 27 '22 10:09 chokdee

Agreed! both options should be valid

christophd avatar Sep 27 '22 18:09 christophd

Seems to be the case in 3.3.0 too.

sscholl avatar Oct 18 '22 07:10 sscholl

Multiple calls of .validate(jsonPath()...) create multiple JsonPath Validation Contexts. However AbstractMessageValidator.validateMessage() takes only the first validationContext. I created a pull request.

sscholl avatar Oct 18 '22 11:10 sscholl