forked from authorjapps/zerocode
-
Notifications
You must be signed in to change notification settings - Fork 1
Producing and Consuming a Alphanumeric Key for recordType JSON
Ben Crossett edited this page Feb 28, 2025
·
1 revision
Release version > 1.3.42
See below :
"key": "EMP-123",
{
"scenarioName": "DEMO SCENARIO - JSON String alphanumeric string key",
"steps": [
{
"name": "do_produce",
"url": "kafka-topic:THE_TEST_TOPIC",
"operation": "produce",
"request": {
"recordType": "JSON",
"records": [
{
"key": "EMP-123",
"value": {
"appName": "App X"
}
}
]
},
"verify": {
"status": "Ok"
}
},
{
"name": "do_consume",
"url": "kafka-topic:THE_TEST_TOPIC",
"operation": "consume",
"request": {
"consumerLocalConfigs": {
"recordType": "JSON",
"commitSync": true,
"showRecordsConsumed": true,
"maxNoOfRetryPollsOrTimeouts": 3
}
},
"verify": {
"records": [
{
"key": "${$.do_produce.request.records[0].key}",
"value": {
"appName": "App X"
}
}
]
}
}
]
}
2024-04-21 15:19:33,235 [main] WARN o.j.z.c.r.StepNotificationHandler -
***Step PASSED - Scenario:DEMO SCENARIO - JSON String alphanumeric string key -> do_produce
--------- TEST-STEP-CORRELATION-ID: 60089fbe-c392-40b2-9f0d-03b67fb52de9 ---------
*requestTimeStamp:2024-04-21T15:19:33.105
step:do_produce
id:None
url:kafka-topic:THE_TEST_TOPIC
method:PRODUCE
request:
{
"recordType" : "JSON",
"records" : [ {
"key" : "EMP-123",
"value" : {
"appName" : "App X"
}
} ]
}
--------- TEST-STEP-CORRELATION-ID: 60089fbe-c392-40b2-9f0d-03b67fb52de9 ---------
Response:
{
"status" : "Ok",
"recordMetadata" : {
"offset" : 0,
"timestamp" : 1713712773230,
"serializedKeySize" : 7,
"serializedValueSize" : 19,
"topicPartition" : {
"hash" : 1415128977,
"partition" : 0,
"topic" : "THE_TEST_TOPIC"
}
}
}
*responseTimeStamp:2024-04-21T15:19:33.234
*Response delay:129.0 milli-secs
---------> Expected Response: <----------
{
"status" : "Ok"
}
-done-
2024-04-21 15:19:45,271 [main] WARN o.j.z.c.r.StepNotificationHandler -
***Step PASSED - Scenario:DEMO SCENARIO - JSON String alphanumeric string key -> do_consume
--------- TEST-STEP-CORRELATION-ID: 7aadad7e-25a1-4eac-8127-6abf87c1b132 ---------
*requestTimeStamp:2024-04-21T15:19:33.235
step:do_consume
id:None
url:kafka-topic:THE_TEST_TOPIC
method:CONSUME
request:
{
"consumerLocalConfigs" : {
"recordType" : "JSON",
"commitSync" : true,
"showRecordsConsumed" : true,
"maxNoOfRetryPollsOrTimeouts" : 3
}
}
--------- TEST-STEP-CORRELATION-ID: 7aadad7e-25a1-4eac-8127-6abf87c1b132 ---------
Response:
{
"records" : [ {
"key" : "EMP-123",
"value" : {
"appName" : "App X"
},
"headers" : { }
} ],
"size" : 1
}
*responseTimeStamp:2024-04-21T15:19:45.270
*Response delay:12035.0 milli-secs
---------> Expected Response: <----------
{
"records" : [ {
"key" : "EMP-123",
"value" : {
"appName" : "App X"
}
} ]
}
-done-
See below :
"key": "\"EMP-123\"",
{
"scenarioName": "DEMO SCENARIO",
"steps": [
{
"name": "do_produce",
"url": "kafka-topic:THE_TOPIC2",
"operation": "produce",
"request": {
"recordType": "JSON",
"records": [
{
"key": "\"EMP-123\"",
"value": {
"appName": "App X"
}
}
]
},
"verify": {
"status": "Ok"
}
},
{
"name": "do_consume",
"url": "kafka-topic:THE_TOPIC2",
"operation": "consume",
"request": {
"consumerLocalConfigs": {
"recordType": "JSON",
"commitSync": true,
"showRecordsConsumed": true,
"maxNoOfRetryPollsOrTimeouts": 3
}
},
"verify": {
"size": 1,
"records": [
{
// "key": "${$.do_produce.request.records[0].key}", //<----- DO NOT ASSERT THE KEY(See below on how to assert the key.)
"value": {
"appName": "App X"
}
}
]
}
}
]
}
2024-04-13 11:07:34,856 [main] WARN o.j.z.c.r.ZeroCodeMultiStepsScenarioRunnerImpl -
-----------------------------------------------------------------------------------
Scenario:
+++++++++
DEMO SCENARIO
-----------------------------------------------------------------------------------
***Step PASSED - Scenario:DEMO SCENARIO -> do_produce
--------- TEST-STEP-CORRELATION-ID: 4e2cb1fb-a4d9-448a-b2fc-58820e56028a ---------
*requestTimeStamp:2024-04-13T11:07:34.882
step:do_produce
id:None
url:kafka-topic:THE_TOPIC2
method:PRODUCE
request:
{
"recordType" : "JSON",
"records" : [ {
"key" : "\"EMP-123\"",
"value" : {
"appName" : "App X"
}
} ]
}
--------- TEST-STEP-CORRELATION-ID: 4e2cb1fb-a4d9-448a-b2fc-58820e56028a ---------
Response:
{
"status" : "Ok",
"recordMetadata" : {
"offset" : 0,
"timestamp" : 1713002855330,
"serializedKeySize" : 9,
"serializedValueSize" : 19,
"topicPartition" : {
"hash" : 273628274,
"partition" : 0,
"topic" : "THE_TOPIC2"
}
}
}
*responseTimeStamp:2024-04-13T11:07:35.364
*Response delay:482.0 milli-secs
---------> Expected Response: <----------
{
"status" : "Ok"
}
-done-
***Step PASSED - Scenario:DEMO SCENARIO -> do_consume
--------- TEST-STEP-CORRELATION-ID: d503b36d-0cc8-4cf0-9497-57a3d7540315 ---------
*requestTimeStamp:2024-04-13T11:07:35.367
step:do_consume
id:None
url:kafka-topic:THE_TOPIC2
method:CONSUME
request:
{
"consumerLocalConfigs" : {
"recordType" : "JSON",
"commitSync" : true,
"showRecordsConsumed" : true,
"maxNoOfRetryPollsOrTimeouts" : 3
}
}
--------- TEST-STEP-CORRELATION-ID: d503b36d-0cc8-4cf0-9497-57a3d7540315 ---------
Response:
{
"records" : [ {
"key" : "EMP-123",
"value" : {
"appName" : "App X"
},
"headers" : { }
} ],
"size" : 1
}
*responseTimeStamp:2024-04-13T11:07:47.724
*Response delay:12357.0 milli-secs
---------> Expected Response: <----------
{
"size" : 1,
"records" : [ {
"value" : {
"appName" : "App X"
}
} ]
}
-done-
Visit the Zerocode Documentation Site for all things.
-
User's Guide
-
Matchers
-
Zerocode Value Tokens
-
YAML DSL
-
Http Testing
-
Kafka Testing
- Introduction
- Produce, consume proto message
- Produce raw message
- Consume raw message
- Produce JSON message
- Consume JSON message
- Produce and consume XML message
- Kafka - consume the latest message or n latest messages
- Produce avro message
- Consume avro message
- KSQL in action
- Produce multiple records
- Produce from file
- Produce to a partition
- Produce and consume records with headers
- Produce n assert partition ack
- Comsume and dump to file
- commitSync vs commitAsync
- Overriding config inside a test
- Chosing String or Int or Avro Serializer
- Chosing String or Int or Avro Deserializer
- Attaching timestamp during load
- Default timestamp provided by Kafka
- Consume and assert avro schema metadata
- Error handling - produce via avro schema
- Sorting Kafka records consumed
-
DB Testing
-
Kotlin Testing
-
Performance Testing - Load and Stress
- Performance Testing - via awesome JUnit runners
- Load Vs Stress generation on target application
- Run a single test or a scenario in parallel
- Run multiple test scenarios in parallel - Production load simulation
- Dynamically change the payload for every request
- Analytics - Useful report(s) or statistics
-
Parameterized Testing
-
Docker
-
More+
-
Extensions
-
JUnit5 Jupiter Test
-
Questions And Answers(FAQ)
- What is Zerocode testing?
- SSL http https connections supported?
- How to assert array size Greater-Than Lesser-Than etc?
- How to invoke POST api?
- How to assert custom headers of the response?
- How to pass custom security token into the request header?
- When to use JUnit Suite runner and when Zerocode Package runner?
- How to execute DB SQL and assert?
- How to handle Http response other than utf-8 e.g. utf-16 or utf-32 ?
- Random Number Generator Placeholders Usages and Limits
- Automation tests for Zerocode lib itself
- Picking a leaf value from the array matching JSON Path
- Array assertions made easy, incl. size and element finder
-
Read Our Blogs
- Top 16 Open Source API Testing Tools For REST & SOAP Services - joecolantonio (Lists popular tools - Globally)
- OAuth2 Test Automation - DZone 2min Read
- Zero defect APIs - Build Pipe Line - Medium 10 min Read
- Develop ZeroDefect API's with ZeroCode! - Extreme Portal ( A must read for all developers and test engineers) 10min Read
- Performance testing using JUnit and maven - Codeproject 10 min Read
- REST API or SOAP End Point Testing - Codeproject 10min Read
- DZone- MuleSoft API Testing With Zerocode Test Framework - DZone 5min Read
- Testing need not be harder or slower, it should be easier and faster - DZone 5 min Read
- Kotlin Integration Testing simplified via Zerocode - Extreme portal 10 min Read
- and More...