Scoring Logic
The score is a number ranging from 0 to 1, aiding in the selection of a <structure> from a list for validation against the received response. It is calculated by comparing a structure in the response of a test case to the corresponding structures outlined in the ZSPEC.
It will be between 0 and 1 whenever there is mismatch in
- keys of a structure
- data-type of the <property> of a structure
- possible values of the properties
If the structure in the response matches exactly with the structure mentioned in the ZSPEC, then the score for the structure will be 1. The structure with the highest score will be taken for validation.
Score | Match |
---|---|
1 | perfect match |
> 0 and < 1 | issue with keys |
0 | no match |
The cases attribute of a structure helps in shortlisting structures from a list and the scoring logic applies only to the shortlisted structures. If cases attribute was not mentioned in the structures, then the scoring logic will apply to all the structures in the list to find the best match of the response.
You can familiarize yourself with the various services and components and gain a more practical understanding of Catalyst by using the step-by-step guide present in the Tutorials section.
Samples
Let us take a few XML response structures and a JSON response to find out how scoring logic works in validating the response.
With Cases Attribute
Here is the structure of the update API’s success response,
copy{ "code": "SUCCESS", "details": {}, "message": "Record Updated", "status": "success" }
Now, we have the following four response structures out of which, two structures has Success value for cases attribute.
copy<!-- Structure - A --> <structure name="create_success" cases="Success"> <property name="code" type="string" values="SUCCESS" /> <property name="details" type="map" /> <property name="message" type="string" values="Record created" /> <property name="status" type="string" values="success" /> </structure>
copy<!-- Structure - B --> <structure name="invalid_error" cases="InvalidValueInURLPath"> <property name="code" type="string" values="INVALID_URL_PATTERN" /> <property name="details" type="map" /> <property name="message" type="string" values="Please check if the URL trying to access is a correct one" /> <property name="status" type="string" values="error" /> </structure>
copy<!-- Structure - C --> <structure name="update_success" cases="Success"> <property name="code" type="string" values="SUCCESS" /> <property name="details" type="map" /> <property name="message" type="string" values="Record Updated" /> <property name="status" type="string" values="success" /> </structure>
copy<!-- Structure - D --> <structure name="mandatory_error" cases="Mandatory"> <property name="code" type="string" values="REQUIRED_NOT_FOUND" /> <property name="details" type="map" /> <property name="message" type="string" values="Mandatory fields are missing" /> <property name="status" type="string" values="error" /> </structure>
ZEST will take up the two structures defined with success case and apply scoring logic over it. It compares every key and value of the structure with the received JSON response.
Except for the message key’s value, all other keys and values are same for both the structures. The value of message key in the JSON response is Record Updated. It looks for the structure with the same message and gives the highest score.
Following is the structure with score 1
copy<!-- Structure - C --> <structure name="update_success" cases="Success"> <property name="code" type="string" values="SUCCESS" /> <property name="details" type="map" /> <property name="message" type="string" values="Record Updated" /> <property name="status" type="string" values="success" /> </structure>
The other structure with the same success case will be given a score less than 1
copy<!-- Structure - A --> <structure name="create_success" cases="Success"> <property name="code" type="string" values="SUCCESS" /> <property name="details" type="map" /> <property name="message" type="string" values="Record created" /> <property name="status" type="string" values="success" /> </structure>
Last Updated 2025-05-30 16:54:59 +0530 +0530
Yes
No
Send your feedback to us