• Compare-api-utility is scalable, standalone spring-boot based application for comparing API responses.
• Response can be of type JSON, XML or even plain text.
- This uses Apache Kafka as distributed event streaming platform at the backend which is High-throughput and fault-tolerant.
- Apache Kafka is able to handle these messages with very low latency of the range of milliseconds.
- Kafka Publish JSON/String message as a request object which is then handle by ThreadPoolExecutor by running multiple threads.
- ApiUtility for getting API response for different request URL.
- CompareJSON & CompareXML classes are used to compare two JSON and XML responses. Both can compare JSON and XML ignoring different order of key values, tags, attributes and whitespaces.
- Two separate files has been created to provide APIs. “EventListener” pushes all data to Kafka queue which is then consumed by Kafka consumer, comparing API responses through ThreadPoolExecutor.
- Application is run in multiple threads and can cater to million streams/events and is fault tolerant by creating replicas and optimizing partions.
Tools & Languages
• Spring-boot • Kafka • Maven • Java • TestNG • Logback • Extent Reports • GSON
Download Kafka https://kafka.apache.org/downloads
Start Zookeeper: bin/zookeeper-server-start.sh config/zookeeper.properties
Start Kafka Server: bin/kafka-server-start.sh config/server.properties
Create Kafka Topic: bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication- factor 1 --partitions 1 --topic Kafka_Example
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication- factor 1 --partitions 1 --topic Kafka_json
Go to compare-api-utility directory and run below command:
mvn clean spring-boot:run
Flow starts from ProducerDataClass listening to ApplicationReadyEvent
• Two files File 3 and File 4 are placed in src/main/resources.
• Extent report will be generated under “compare-api-utility/result- files/extent-reports” with current timestamp as file name.
• For running tests, run below command:
mvn clean test
Assumptions:
- If Both response are null, then APIs are equal
- If Both response are empty, then APIs are equal
- Both have same error message response, then APIs are equal
- Both have same response but different response status, then APIs are equal.