Add a check of non existence in a API response
i have this kind of API response :
{"response": {"responsesRecherche": {
"1": {
"consultation": {
"Id": "16391821108191",
"referenceFonctionnelle": "Dume OE US 78 - CTR016",
"idTypeProcedure": "01",
"idNatureMarket": "01",
"idTypeMarket": "01"
},
"lot": [{"numeroLot": "016"}],
"Opérateur Economique": {"id": "38103128500491"},
"Dume OE": {
"dumeOEId": "mybmttmy",
"statutDume": "REMPLACE",
"nouveauDume": {
"dumeOEId": "uxudjs9s",
"statutDume": "VALIDE",
"accessible": true,
"Date de création": "2018-09-11 04:57:22",
"Date de modification": "2018-09-11 04:57:22"
},
"accessible": true,
"Date de création": "2018-09-11 04:57:00",
"Date de modification": "2018-09-11 04:57:22"
}
},
"2": {
"consultation": {
"Id": "56559466095920",
"referenceFonctionnelle": "Dume OE US 78 - CTR016",
"idTypeProcedure": "01",
"idNatureMarket": "01",
"idTypeMarket": "01"
},
"lot": [{"numeroLot": "03"}],
"Opérateur Economique": 18,
"Dume OE": {
"dumeOEId": "qo92j8tt",
"statutDume": "VALIDE",
"accessible": true,
"Date de création": "2018-09-11 04:12:02",
"Date de modification": "2018-09-11 04:12:02"
}
},
...
...
"50": {
"consultation": {
"Id": "31739414944098",
"referenceFonctionnelle": "Dume A - CTR021",
"idTypeProcedure": "01",
"idNatureMarket": "01",
"idTypeMarket": "01"
},
"lot": [{"numeroLot": "78"}],
"Opérateur Economique": 18,
"Dume OE": {
"dumeOEId": "7bewwsrj",
"statutDume": "VALIDE",
"accessible": true,
"Date de création": "2018-09-13 08:41:44",
"Date de modification": "2018-09-13 08:41:44"
}
},
}}}
I have to check creation dates of the Dume OE object. "Date de création" in french.
So my following script works perfectly when all Dume OE objects are complete recorded.
But we have new problem, API returns incomplete response for some Dume OE :
"42": {
"consultation": "16391821108191",
"lot": [{"numeroLot": "03"}],
"Opérateur Economique": 18,
"Dume OE": "uxudjs9s"
},
there is no information on Dume OE object. I have to add a IF which check "date de création" existence,
before check his format and value.. I try "contains" method, but i have groovy error :(
My script :
import net.sf.*
import net.sf.json.*
import net.sf.json.groovy.*
import com.eviware.soapui.support.XmlHolder
def GU = new com.eviware.soapui.support.GroovyUtils( context )
def Response = context.expand ( '${CP_CTR006_DateDebutSansDateFin#Response}').toString()
def Slurp = new JsonSlurper().parseText(Response)
.response.responsesRecherche
.collect {keyname, keyvalue -> keyvalue } // créé la liste de valeurs derrière le compteur
.collect { it."Dume OE"}
def cpt = Slurp.size()
log.info " Dates trouvées = " + cpt
def i=0
checkdate = true
def testdate = testRunner.testCase.testSuite.getProperty("DateCreation").value
testdate = testdate.substring(1,11)
testdate = testdate + " 00.00.00"
while (i<cpt && checkdate==true)
{
// TO DO : Add condition IF "Date de création" not exist in Slurp[i] object before check date
if (Slurp[i]."Date de création" < testdate) {checkdate = false }
assert checkdate
i++
}
if (checkdate) {log.info "Toutes les dates sont postérieures à " + testdate }
It is not hard but i am weak with collection objects :(
hi.
I try but it don't work. same error "groovy.lang.MissingPropertyException: No such property: Date de création for class: java.lang.String
I try this just after :
if (Slurp[i].("Date de création")) {
if (Slurp[i]."Date de création" < testdate) {checkdate = false }
assert checkdate
i++}
}but i got the same error :(
i think i should use "contains" method rightly.