0

I am new to soap Ui, and have to configure a mock, to mock responses from asoap service given some requests.

this is the groovy script to dispatch :

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def idReq = String.valueOf(holder.getNodeValue("//id"))

switch (idReq) {
    case "74":
        context.ResultResponse = "Response_74"
        break
    case "53":
        context.ResultResponse = "Response_53"
        break
    case "37":
        context.ResultResponse = "Response_037"
        break
    case "12":
        context.ResultResponse = "Response_12"
        break
    case "147":
        context.ResultResponse = "Response_147"
        break
    case "90":
        context.ResultResponse = "Response_90"
        break
    default:
        context.ResultResponse = "Response_74"
        break
}

Then I deployed it as a war. Some colleagues want to edit the script to add a new mock response.

I don't know how to edit it when I only have the war package. Has anyone done this before?

marcAntoine
  • 668
  • 5
  • 19
  • 35
  • In that it is not just above script change, but also require change to the project and add new response too, right? I believe you need to update the project and redo the same. – Rao Aug 22 '17 at 08:54

1 Answers1

0

I believe that you should be able to do it without switch block
i.e., replace switch block with below statement

context.ResultResponse = "Response_${idReq}"

You won't be needing to add more case.

EDIT Based on OP's comments

It is possible to send dynamic response with adding multiple responses to mock service. All you need to do is have single response with placeholder value. Each response is in a file, load the respective file based on data and set that as response. No additional responses, no changes to script.

Rao
  • 20,781
  • 11
  • 57
  • 77
  • thak you for your answer, i will change the script, but in case there is no response with id wanted it will return default, i want to be able to edit and add mock responses to the war. – marcAntoine Aug 22 '17 at 09:23
  • @manu, I believe that you are having place holder in the response, not actually different response, right? – Rao Aug 22 '17 at 09:28
  • it's actually a completely different responses that i get from the real soap service given some id, the data in the response completely changes – marcAntoine Aug 22 '17 at 09:29
  • Ok, actually you could even do that without adding multiple responses. – Rao Aug 22 '17 at 09:32
  • how can i do that, or how can my colleague do that when he only have the war, does he have to create a new project in soapUi and import the war, i don't know if that's possible... – marcAntoine Aug 22 '17 at 09:45
  • Yes, that is possible. All you need to do is have single response with placeholder value. Each response is in a file, load the respective file based on data and set that as response. No additional responses, no changes to script. – Rao Aug 22 '17 at 10:00
  • You can find some sample code snippet to achieve the same - https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-get-soap-mock-response-from-external-file/m-p/110795/highlight/true#M19159 – Rao Aug 22 '17 at 10:09
  • suppose i actually begin with 10 responses created, i load the response file given an id in request, how can i add the other responses when they have completely different data which has nothing to do with the id in request ? suppose i have to add 100 other responses – marcAntoine Aug 22 '17 at 14:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152535/discussion-between-rao-and-manu). – Rao Aug 22 '17 at 14:10
  • @manu, is https://stackoverflow.com/questions/34835395/how-to-access-file-resources-in-soapui-mock-service-which-is-going-to-be-deploye helpful? – Rao Aug 23 '17 at 14:01