zerocode: [KAFKA]Cannot inject ZeroCode variables into Validators

Description:

This is my usecase:

Details were already provided initially. Copy pasting it again

  1. Consuming from Kafka multiple messages which are from different partitions.
  2. Need to validate the ID field of each message consumed. This ID is Random.Number generated in a previous test (REST POST).
  3. 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:

  1. Consuming from Kafka multiple messages which are from different partitions.
  2. Need to validate the ID field of each message consumed. This ID is Random.Number generated in a previous test (REST POST).
  3. 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

Most upvoted comments

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?

Doc link: <will create a paste the doc page link here soon>

This will be very useful for most users.

Already did understand what is needed:

  • he has a step in which he posts some data with a list to a backend rest server
  • this backend application will put this received datalist as separate records on the kafka topic
  • next step of the test will get the data records from the kafka topic

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?

@authorjapps - breaking down the test steps even more!

Test Case steps:

  1. Test case 1 - Send a POST request which posts 2 records.
  2. Microservice picks these 2 records.
  3. Microservice publishes these 2 records on a Kafka topic. Record format is Json.
  4. Let us assume that the ID of these two records published in Step 3 are ID 1 and ID 2.
  5. Test case 2 - Consume from this topic and validate that ID 1 and ID 2 fields of the 2 records published in Step 3 are present on the topic.

Issue is on Step 5, where I cannot validate the value of ID field (1 and 2 in the steps above) using the method I have described. Hope this further break down is clear!

@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'. 😉