Problem Statement :
- Microservices retrieves data from DB2 Database as part of Production
- Different Set of data feasible in Different Environment
- As part of it, it needs to ensure Retrieval logic is accurate
- java Code Converts DB2 Data into JSON structure
- Microservices logic doesnt control creating Database,its only limited to retrieval
- As part of above requirement , In memory DB (H2) is being discussed for Testing where data is loaded using DDL/DML and Expected JSON response to be generated manually as part of unit Testing
Test Validation Objective : test "Retrial Logic" so that irrespective of Environment, same values are retrieved .When Microservices is invoked, internally Test Harness URL calls to In Memory Database to retrieve Actual response
Test Automation Framework in Place :
- Karate Framework
Test Automation Approach:
- Load data into in Memory Database using DDL/DML (file) as part of Test Execution
- Invoke Microservice Request using karate
- Compare Actual Response against Expected JSON response captured in Step
- Delete the Database as part of Cleanup
Note - As it would be very tedious to write same Test Automation logic which helps to convert Data into DB ( In Memory ) to JSON (Expected Response), Expected JSON response to be captured as base expected response
Its Expected to have Test Automation Maintenance to Update DDL/DML or expected JSON is there is any change in actual Retrieval Logic.
Refernce for In memory DB Testing :
https://www.baeldung.com/spring-jpa-test-in-memory-database
#xyz-service-response.json is generated as part of unit testing while In memory DB is Created @TestRetrivalLogicusingInMemoryRequirnments Feature: demo reading files and using in a test
Background:
* url 'http://localhost:8080/api/sample/v1.0/'
* header Accept = 'application/json'
* configure logPrettyResponse = true
* configure ssl = true
Scenario: using json as a string Load data into In Memory Database ---->> This is expected Gherkin Statement. Need to understand how we can do in Karate
Given path 'getDerivedRules'
And request { "pricingVerIds": [{ "AncestorVersionId": 123456123, "kidsVersionIds": [3432432,345324324] }],"executionFlow": "Cheque","PriceType": "dollarinINYIELD", "validationLevel": "Aggrement_LEVEL"}
When method POST
Then status 200
Then match $ == read('xyz-service-response.json')
Challenge and Query :
As karate Gherkin statement doesn't have Java Glue Code , and it has own DSL, can this be achieved using Karate or we need to stick to RESTAssured or similar Framework
Request for Help :
Any suggestion or code snippet to handle above would be helpful