zerocode: [KAFKA]Cannot inject ZeroCode variables into Validators
Description:
This is my usecase:
Details were already provided initially. Copy pasting it again
- Consuming from Kafka multiple messages which are from different partitions.
- Need to validate the ID field of each message consumed. This ID is Random.Number generated in a previous test (REST POST).
- Trying to access this ID deterministically using validators and it is not working. Below is the validator being used. While consuming we are trying to validate the ID of the message consumed.
{
"name": "consume_from_test-topic",
"url": "kafka-topic:test-topic",
"operation": "consume",
"request": {
"consumerLocalConfigs": {
"recordType": "JSON",
"commitSync": false,
"showRecordsConsumed": true,
"maxNoOfRetryPollsOrTimeouts": 2
}
},
"validators": [
{
"field": "$..journals[?(@.id==${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id})]",
"value": "${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id}"
}
]
}
This is my actual request and actual response
Paste a sample or example here:
Complete logs already attached, as previously requested.
This is what I want to assert or validate
Paste a sample or example here:
Need to validate the value of ID field of each message consumed. This ID is Random.UUID Number generated in a previous test (REST POST)
Further details:
@authorjapps Scenario:
- Consuming from Kafka multiple messages which are from different partitions.
- Need to validate the ID field of each message consumed. This ID is Random.Number generated in a previous test (REST POST).
- Trying to access this ID deterministically using validators and it is not working. Below is the validator being used. While consuming we are trying to validate the ID of the message consumed.
{
"name": "consume_from_test-topic",
"url": "kafka-topic:test-topic",
"operation": "consume",
"request": {
"consumerLocalConfigs": {
"recordType": "JSON",
"commitSync": false,
"showRecordsConsumed": true,
"maxNoOfRetryPollsOrTimeouts": 2
}
},
"validators": [
{
"field": "$..journals[?(@.id==${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id})]",
"value": "${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id}"
}
]
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (4 by maintainers)
Commits related to this issue
- fix(validators): support of Zerocode expressions and jsonpath Close #436 — committed to authorjapps/zerocode by M3lkior 2 years ago
- fix(validators): support of Zerocode jsonpath expressions in field Close #436 — committed to authorjapps/zerocode by M3lkior 2 years ago
- fix(validators): support of Zerocode jsonpath expressions in field Close #436 — committed to authorjapps/zerocode by M3lkior 2 years ago
- fix(validators): support of Zerocode jsonpath expressions in field Close #436 — committed to authorjapps/zerocode by M3lkior 2 years ago
- fix(validators): support of Zerocode jsonpath expressions in field Close #436 — committed to authorjapps/zerocode by M3lkior 2 years ago
- fix(validators): support of Zerocode jsonpath expressions in field Close #436 — committed to authorjapps/zerocode by M3lkior 2 years ago
Thank you, great job. Will review and merge soon.
Final bit and help needed when you get chance: Would you mind adding a basic helloword-type example for this please into the Docs?
This will be very useful for most users.
Already did understand what is needed:
The assertion to check here, that the data that was put on the backend rest server, is the same as received from the kafka topic. That is why it was tried to match the outcome of the kafka topic with the request to the backend rest server and because order may be different for the records, the jsonpath matcher in the “field” was used to get the correct record (
$..journals[?(@.id==${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id})]
which means get the record with an id that matches with the original request list the first one’s id) and then perform a (second imo unnecessary because if the jsonpath matching above is not getting a result, it doesn’t exist and if is matches, then we know the outcome too) check with the value (${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id}.
which means the value of the original request list the first one’s id)… Right?@kt09 Can you please paste the specific snippet from the log? The attached log file has too many other unrelated details which might be make it difficult for the collaborators to drill down to your specific problem. This looks more like a usage problem than an issue. You can discuss this in Slack too where you may find assistance from wider audience
Parsing the jsonpath with variables is possible, but this assertion is not working as you would expect. The field will give a result as
'[{"id":"0e42651b-9e4d-4d82-ad77-7c115c947dde"}]'
while the value will become'0e42651b-9e4d-4d82-ad77-7c115c947dde'
. 😉