simple scripting in a Mock Service - no longer works
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
simple scripting in a Mock Service - no longer works
In a previous project (about a year ago) I used simple scripting in a soapUI Mock Service.
I had several responses defined for a method. For one of my tests, I wanted to ensure that a subset of the responses would be returned in a specific sequence when the method was called repeatedly by the client piece. There was nothing fancy about this - no conditional programming, just a specification of which named responses I wanted to be sent back to the client.
I have had to re-visit this project to fix a small bug and I wanted to do a similar test. However the scripting no longer works.
Effectively I have the following responses in the Mock Responses panel of my Login method:-
Login_Response_OKAY_1
Login_Response_OKAY_2
Login_Response_OKAY_3
Login_Response_OKAY_4
Login_Response_ERROR
In the Dispatch dropdown list I have "SCRIPT" selected. In the Default Response dropdown list I have "Login_Response_ERROR" selected. In the panel below this I have the following script:-
return "Login_Response_OKAY_2"
return "Login_Response_OKAY_1"
return "Login_Response_OKAY_3"
return "Login_Response_OKAY_4"
In this test I did not want the fifth variant of the response (the error case) sent back. This used to work a treat.
I used to get the responses in the order as written, and then they would repeat - i.e. 2, 1, 3, 4, 2, 1, 3, 4 etc).
Now I just get the first response in the list, namely Login_Response_OKAY_2, repeatedly.
I am using soapUI 5.0.0 and I have Groovy specified as the scripting language (I think this is the default).
The only difference I can think of between now and a year ago is that I was probably using an earlier version of soapUI.
Can someone suggest what is wrong and how to cure this?
Thanks.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Really, does no-one have any wisdom to offer on this one? This sort of mock service setup has to be in the category of Mock Service Scripting 101 and yet no advice on how to make it work?
Sigh.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am re-visiting this problem once again. This time I have moved up to SoapUI 5.2.0. And this time I am modelling a RESTful web service instead of a SOAP web service.
Again I should like to define a specific order of responses from the set of responses that I have created for a method. If I use the SEQUENCE option, the responses will come out in the order in which they were added. But I do not want this. Suppose I want to just return the 4th and the 5th response and for now ignore the 1st, 2nd and 3rd?
The tool does not allow me to arbitrarily move the responses as they are listed. I do not wish to delete any of them. I should like to write a script that says, "Send back the 4th response, then the 5th, regardless of the contents of the incoming request."
Please, anyone?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
To do what you need and many other dynamic responses, I would use a Dispatch type of SCRIPT. Please see example in the screen shot:
Basically, the script allows you to conditionally return different responses e.g. you could do return "response 4" or whatever you need.
Assuming you're happy to do some simple Groovy script, does this make sense? If you're not happy to, then your options are limited to the sequence option.
Hope this helps,
Cheers,
Rupert
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Rupert, for your response.
Unfortunately, that is not what I am attempting to do. Your example addresses the very reasoble desire to base the response on the contents of the request. So for example, if the <userID> is "tomthumb", generate "Response 2", else generate "Response 1".
My needs are so much simpler!
The request in this case is going to be the same each time, but the response will change over time, and that is what I wish to simulate - by choosing a subset of my already defined responses and sending them back in a custom order of my choosing. I tried to highlight this in my second post in the thread.
It seems that all sorts of wonderfully complex things are possible in SoapUI but not this trivial task. Ironically, it used to work. On a previous project I was able to specify in a script section somethuing like the following:-
return "Response 5" return "Response 4" return "Response 7"
Only these three reponses were returned, and in the obvious order specified, not in the order in which they were created. Other responses that I had defined (but did not wish to use on this occasion) were ignored and I did not have to delete them.
When I came back to re-use my SoapUI project after making some code changes, this feature no longer worked and I could not track down the cause, except maybe a change in version of SoapUI that I was using.
This problem applies to scripting responses to both SOAP web services and RESTful web services.
The only solution I have to the problem is to delete the responses, create exactly the ones I want to use in this case, and select the SEQUENCE option. But that sucks. It sucks golf balls up a garden hose.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"I have a problem with Mock Service scripting. It used to work. Now it doesn't."
-- quoting from the original query.
Would you please post the script that used to work? and also post the error that you see in the log, may be that will help to narrow down the core of the issue? Also list the details of your environment changes between working, not working which I think will help you also to pin point the issue
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A possible workaround could be:
// get the list from the context def myRespList = context.myRespList // if list is null or empty reinitalize it if(!myRespList || !myRespList?.size){ // list in the desired output order myRespList = ["Response 2","Response 3","Response 4","Response 7"] } // take the first element from the list def resp = myRespList.take(1) // update the context with the list without this element
context.myRespList = myRespList.drop(1) // return the response
log.info "-->"+resp
return resp
Check the details in the post here: http://stackoverflow.com/questions/32975240/soapui-mock-service-custom-sequence-of-responses/3298012...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rao,
@nmrao wrote:"I have a problem with Mock Service scripting. It used to work. Now it doesn't."
-- quoting from the original query.
Would you please post the script that used to work? and also post the error that you see in the log, may be that will help to narrow down the core of the issue? Also list the details of your environment changes between working, not working which I think will help you also to pin point the issue
I would probably have been able to dig up the original details of changes etc when I first posted my question about a year ago. Right now it is not convenient/possible for me to do so.
I should emphasise that I was able to achieve the desired behaviour before and now I am not and I think I am doing exactly the same thing to achieve the effect. That is what I mean by, "It used to work. Now it doesn't." - that's my experience. It may be that I am doing it wrong.
I know of no error in a log - sorry. I just experience the moclk service always just responding with the one mock response. I am unable to specify a custom sequence for the mock responses already crafted.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Albert,
@AlbertCiffone wrote:
A possible workaround could be:
// get the list from the context def myRespList = context.myRespList // if list is null or empty reinitalize it if(!myRespList || !myRespList?.size){ // list in the desired output order
myRespList = ["Response 2","Response 3","Response 4","Response 7"] } // take the first element from the list def resp = myRespList.take(1) // update the context with the list without this element
context.myRespList = myRespList.drop(1) // return the response
log.info "-->"+resp
return respCheck the details in the post here: http://stackoverflow.com/questions/32975240/soapui-mock-service-custom-sequence-of-responses/3298012...
Thanks. This is interesting and I think I get what you are doing here. It doesn't work, though.
Interestingly the log.info statement does output the names of the responses I want, for example, if I specify my list to be just two of the responses out the 5 that I have currently defined, those two are output in the script log:-
myRespList = ["Response 2","Response 4"]
...
...
...
...
// return the response
log.info "-->"+resp
return resp
This produces in the script log the following:-
Wed Oct 07 12:28:00 BST 2015:INFO:-->[Response 2]
Wed Oct 07 12:28:01 BST 2015:INFO:-->[Response 4]
Wed Oct 07 12:28:03 BST 2015:INFO:-->[Response 2]
Wed Oct 07 12:28:04 BST 2015:INFO:-->[Response 4]
Wed Oct 07 12:28:04 BST 2015:INFO:-->[Response 2]
Wed Oct 07 12:28:06 BST 2015:INFO:-->[Response 4]
and so on.
But the response that comes back to the client (which is another instance of SoapUI running as a client on another workstation) is whatever is specified in the Deafult Response dropdown list on the server instance.
It's like the "return" statement in the script is being ignored by the tool.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works correctly for me. Check that the string that you're returning correspond to the response names... you use "Login_Response_OKAY_1" as name instead of "Response 1"... In my example I use this names but check that you're using the correct ones for your case.
...
myRespList = ["Login_Response_OKAY_1","Login_Response_OKAY_2"]
...
If you return a string that not exist as a name it executes the default option.
