raygoel
4 years agoOccasional Contributor
Groovy Script assertion always passes even though the values don't match the response
Hi,
I am writing assertions for an API which has the following JSON response -
{
"id" : "dd72080a-be22-4e60-a0e4-58f35d4144e5",
"name" : "I_Plate3",
"containerType" : null,
"isInventory" : true,
"isProcess" : false,
"inventoryTemplateName" : "I_Plate3",
"process" : null,
"lid" : null
},
{
"id" : "1f2e0738-358e-478b-abf9-d4b79383d587",
"name" : "Plate1",
"containerType" : "SLAS/SBS Standard",
"isInventory" : false,
"isProcess" : true,
"inventoryTemplateName" : null,
"process" : {
"id" : "a3b5e431-dc18-43af-b204-ae877c7c72b9",
"name" : "UsingProcessPlates"
},
"lid" : null
},
In the response I iterate over isProcess and if it is true, I put an assertion on the process name and lid. Here is the script I am using for this -
import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurpedResponse = new JsonSlurper().parseText(response)
if ( slurpedResponse*.isProcess) {
switch (slurpedResponse.name) {
case "Plate1" :
assert slurpedResponse.process.name == "UsingProce"
assert slurpedResponse.lid == null
}
case "Plate2" :
assert slurpedResponse.process.name == "UsingProcessPlates"
assert slurpedResponse.lid == "Plate2Lid"
}
}
The issue is that the assertion below passes when it should be failing since the name of the process does not match with what it is in the JSON response.
assert slurpedResponse.process.name == "UsingProce"
I have tried it with assert slurpedResponse.process.name.toString() as well but the assertion still passes when it should fail.
Can someone please help me with the error in my script?