authorjapps / zerocode

A community-developed, free, opensource, automated testing framework for microservices APIs, Kafka(Data Streams) and Load testing. Zerocode Open Source enables you to create, change and maintain your automated test scenarios via simple JSON or YAML files. Visit documentation below:
https://zerocode-tdd.tddfy.com
Apache License 2.0
872 stars 374 forks source link

Vaue lookup tokens don't work in kakfa JSON value #660

Open Tobolov opened 3 months ago

Tobolov commented 3 months ago

Value lookup tokens such as $.stepname.querystr token don't work within a json value field of kafka a kafka record. This is the case for both the produce and consume operations.

Scenario to replicate:

---
scenarioName: Demonstrate issue 2
steps:
  - name: create_app
    url: "kafka-topic:APP"
    operation: produce
    request:
      recordType: JSON
      records:
        - key: ${RANDOM.NUMBER}
          value:
            appId: $.create_app.request.records[0].key
            userId: ${RANDOM.NUMBER}
    verify:
      status: Ok
  - name: verify_app
    url: "kafka-topic:APP"
    operation: consume
    retry:
      max: 3
      delay: 1000 #ms
    request:
      consumerLocalConfigs:
        recordType: JSON
        commitSync: true
        showRecordsConsumed: true
        maxNoOfRetryPollsOrTimeouts: 3
    verify:
      size: 1
      records:
        - key:  $.create_app.request.records[0].key
          value:
            appId:  $.create_app.request.records[0].key
            userId:  $.create_app.request.records[0].value.userId

Actual record produced to Kafka: Key: 4712019646354101240 Value:

{
    "appId": "$.create_app.request.records[0].key",
    "userId": "3430825975012614214"
}

**Exception thrown:***

java.lang.RuntimeException: Assertion failed for :- 

[Demonstrate issue 2] 
    |
    |
    +---Step --> [verify_app] 

Failures:
--------- 
Assertion jsonPath '$.records[0].value.userId' with actual value '3430825975012614214' did not match the expected value '$.create_app.request.records[0].value.userId'
----------------------------------------------------------------------------------------------------------------------------------
Assertion jsonPath '$.records[0].key' with actual value '4712019646354101240' did not match the expected value '$.create_app.request.records[0].key'

    at org.jsmart.zerocode.core.runner.StepNotificationHandler.handleAssertionFailed(StepNotificationHandler.java:37)
    at org.jsmart.zerocode.core.runner.StepNotificationHandler.handleAssertion(StepNotificationHandler.java:71)
    at org.jsmart.zerocode.core.runner.ZeroCodeMultiStepsScenarioRunnerImpl.executeRetry(ZeroCodeMultiStepsScenarioRunnerImpl.java:316)
    at org.jsmart.zerocode.core.runner.ZeroCodeMultiStepsScenarioRunnerImpl.executeRetryWithSteps(ZeroCodeMultiStepsScenarioRunnerImpl.java:191)
    at org.jsmart.zerocode.core.runner.ZeroCodeMultiStepsScenarioRunnerImpl.executeSteps(ZeroCodeMultiStepsScenarioRunnerImpl.java:173)
    at org.jsmart.zerocode.core.runner.ZeroCodeMultiStepsScenarioRunnerImpl.runScenario(ZeroCodeMultiStepsScenarioRunnerImpl.java:136)
    at org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner.runLeafJsonTest(ZeroCodeUnitRunner.java:223)
    at org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner.runChild(ZeroCodeUnitRunner.java:127)
    at org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner.runChild(ZeroCodeUnitRunner.java:51)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner.run(ZeroCodeUnitRunner.java:107)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
nirmalchandra commented 2 months ago

@Tobolov , Sounds like ${RANDOM.NUMBER.FIXED} might help in this case.

authorjapps commented 4 days ago

@Tobolov , can you check if this issue was solved by this PR? If so, we can close this ticket.