Forum Discussion

Donovan's avatar
Donovan
Occasional Contributor
11 years ago

Mock Service Response Logic

Hello Team,

I'm just getting into Mocking Up Services and discovered this is such great functionality. However, I need help with placing logic into my Mock Responses.

I have built two mock responses. I have also built two requests. I need to build logic in the Mock Service to return the associated response to the correct request.

How should I approach this? Do I create a Dispatch Script? If so, do I build a if statement in groovy in order to return back the correct response?

Thanks

5 Replies

  • Donovan's avatar
    Donovan
    Occasional Contributor
    I have a request with three input parameters.

    These three values will return my expected response. I have 9 different scenarios that will each return a different response. I have a test step already created that will call the mockservice, but I need to be able to branch on the request coming and provide the associated response.

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ust="http://www.test.com">
    <soapenv:Header/>
    <soapenv:Body>
    <ust:Cre>
    <ust:A>A</ust:A>
    <ust:C>X</ust:C>
    <ust:F>B</ust:F>
    </ust:Cre>
    </soapenv:Body>
    </soapenv:Envelope>

    Expected Return

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ust="http://www.test.com">
    <soapenv:Header/>
    <soapenv:Body>
    <ust:CreResponse>
    <ust:CreList>
    <!--0 to 100 repetitions:-->
    <ust:Cre>
    <ust:CreKey>${guidVal}</ust:CreKey>
    <ust:CreType>A</ust:CrwType>
    <ust:CreReqQty>4</ust:CreReqQty>
    <ust:FDay>
    <!--Optional:-->
    <ust:FDayPeriod>Basic</ust:FDayPeriod>
    <!--Optional:-->
    <ust:FPeriodCode>B</ust:FPeriodCode>
    <!--Optional:-->
    <ust:DLength>1080</ust:DLength>
    <!--Optional:-->
    <ust:MaxPeriod>16</ust:MaxPeriod>
    <!--Optional:-->
    <ust:MinPeriod>12</ust:MinPeriod>
    </ust:FDay>
    <!--1 or more repetitions:-->
    <ust:DPosition>
    <ust:ACode>TEST</ust:ACode>
    <ust:CCode>M</ust:CCode>
    <ust:Cert>qualified</ust:Cert>
    <ust:CCode>P</ust:CeCode>
    <ust:CePosition>P</ust:CPosition>
    <!--Optional:-->
    <ust:CreReqQty>1</ust:CreReqQty>
    </ust:DPosition>
    </ust:Cre>
    </ust:CreList>
    </ust:CreResponse>
    </soapenv:Body>
    </soapenv:Envelope>
  • Donovan's avatar
    Donovan
    Occasional Contributor
    I keep getting a script returned [null]. I'm confused as to why.

    // create XmlHolder for request content
    def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )

    // get arguments
    def arg1 = holder["//*:ACode"]
    def arg2 = holder["//*:CrType"]
    def arg3 = holder["//*:FPeriod"]

    // Select valid response randomly
    if( arg1 = 'C' & arg2 = '2LM")
    return "Simple Response"