Comparator Library is used to compare 2 API responses (HTTP/HTTPS)
Created a comparator library that will compare 2 API responses which
- Could be nested or unordered in nature
- Can compare millions of requests without any memory issues
- Considered API response as blank for below cases:
- Any API which gives response code other than 200
- If any URL is not having proper protocol i.e. http,https,www etc...
- Considered APIs with GET request method only
- Not handled cases for APIs which requires authorization/authentication
-
This is the library we use to read URLs from 2 files
-
Used HTTPclient library to get response from urls
-
Created parseJSON method to parse response which checks whether jsonnode is array,object or value
-
Created compare method(passed map of response 1 and response 2 as parameters), to compare responses on the basis of key-value pairs. Following criteria were used to draw the comparison:
- If the number of keys match across both the responses, then
- If the keys match across both the responses, then
- If the values corresponding to specific key also match across both the responses
-
Created printResult method, to print output in required format
- Following testcases were considered using TestNG
- If both the URL give same response, it should be able to give output in the format of URL1 equals URL2
- If both the URL does not give same response, it should be able to give output in the format of URL1 not equals URL2
- If both of the URLs has blank response, it should be able to give output in the format of URL1 not equals URL2
- If one or both of the URLs have exception eg. response code !=200, file has unequal urls, file has blank entry in it, the program should not terminated
- Tested with 1000 requests, to ensure there are no memory issues
- Eclipse
- Maven
- TestNG
- Create Maven build as "clean install". Command: mvn clean install
- So a jar file will be generated
- Execute project from command prompt java -jar .jar file1 file2