jeudi 27 février 2020

karate: assist in finding solution for nested if condition in json response. i tried my best to put my question out there

I have lengthy json response (350 lines - tend to increase based on inputs) that has 24 source codes + overall status code.

business logic implemented as:: 
Overall status code = GREEN if all (24 codes) are GREEN;
RED if any of them is RED;
YELLOW is any of them is YELLOW and none is RED;

I have tried this logic step be step as below, also pls suggest me with the minimum lines code to achieve that.

    * def result = callonce read('file.feature')

    Then match result.response.StatusCode == 200
    Then match result.response.Message == 'Request Successful'

    * def final = result.response
    * st1 = final.Result[0].ssmCore.missing.status
    * st2 = final.Result[0].ssmCore.zero.status
    * st3 = final.Result[0].ssmCore.sw.status
    * st4 = final.Result[0].ssmCore.bum.status
    * st5 = final.Result[0].ssmComm.missing.status
    * st6 = final.Result[0].ssmComm.zero.status
    * st7 = final.Result[0].ssmComm.sw.status
    * st8 = final.Result[0].ssmComm.bum.status
    * st9 = final.Result[0].ssmmas.missing.status
    * st10 = final.Result[0].ssmmas.zero.status
    * st11 = final.Result[0].ssmmas.sw.status
    * st12 = final.Result[0].ssmmas.bum.status
    * st13 = final.Result[0].ssmris.missing.status
    * st14 = final.Result[0].ssmris.zero.status
    * st15 = final.Result[0].ssmris.sw.status
    * st16 = final.Result[0].ssmris.bum.status
    * st17 = final.Result[0].ssmhist.missing.status
    * st18 = final.Result[0].ssmhist.zero.status
    * st19 = final.Result[0].ssmhist.sw.status
    * st20 = final.Result[0].ssmhist.bum.status
    * st21 = final.Result[0].ssmpr.missing.status
    * st22 = final.Result[0].ssmpr.zero.status
    * st23 = final.Result[0].ssmpr.sw.status
    * st24 = final.Result[0].ssmpr.bum.status

    * def overallStatus = final.Result[0].Sourcestatus

    * def ssmcorestatus = '{st1 == "RED" || st2 == "RED" || st3 == "RED"  || st4 == "RED" }' ? 'RED' : 'GREEN'
    * def ssmCommstatus = '{st5 == "RED" || st6 == "RED" || st7 == "RED"  || st8 == "RED" }' ? 'RED' : 'GREEN'
    * def ssmmasstatus = '{st9 == "RED" || st10 == "RED" || st11 == "RED"  || st12 == "RED" }' ? 'RED' : 'GREEN'
    * def ssmrisstatus = '{st13 == "RED" || st14 == "RED" || st15 == "RED"  || st16 == "RED" }' ? 'RED' : 'GREEN'
    * def ssmhiststatus = '{st17 == "RED" || st18 == "RED" || st19 == "RED"  || st20 == "RED" }' ? 'RED' : 'GREEN'
    * def ssmprstatus = '{st21 == "RED" || st22 == "RED" || st23 == "RED"  || st24 == "RED" }' ? 'RED' : 'GREEN'


    * def status = '{ssmcorestatus == "RED" || ssmCommstatus == "RED" || ssmmasstatus == "RED"  || ssmrisstatus == "RED" || ssmhiststatus == "RED" || ssmprstatus == "RED" }' ? 'RED' : 'GREEN'

    * print overallStatus
    * print status

    * match overallStatus == status

Aucun commentaire:

Enregistrer un commentaire