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.
I have found a solution. I have moved on to a new SoapUI project (a SOAP project, this time, not REST) and just for the sake of punishing myself I tried again to construct a custom sequence. I have taken bits of a coupe of the kind responses and amended them based on my observations and have come up with the following.
I realised that the script log was showing the values of my list items with the square brackets around them. It occurred to me that a statement like this:-
myRespList = ["Response_2","Response_1"]
- must do a bit more than just insert the two strings "Response_2" and "Response_1" to a list; it must be adding the square brackets around the words first. No idea why.
I re-named my methods to include the square brackets and suddenly the thing is working.
Here are the details:-
My Responses in the method are as follows:-
[Response_Template]
[Response_1]
[Response_2]
My code (heaviliy influenced by previous contributors) is as follows.
// get the list from the context def myRespList = context.myRespList // if list is null or empty reinitalize it if (!myRespList || !myRespList?.size) { log.info "--> Refreshing the list" // list in the desired output order myRespList = ["Response_2","Response_1"] } // take the first element from the list def myResp = myRespList.take(1) // update the context with the list without this element context.myRespList = myRespList.drop(1) // return the response log.info "--> Response is: " + myResp return myResp;
The output in the script is like this:-
- Fri Oct 09 18:34:47 BST 2015:INFO:--> Refreshing the list
- Fri Oct 09 18:34:47 BST 2015:INFO:--> Response is: [Response_2]
- Fri Oct 09 18:34:50 BST 2015:INFO:--> Response is: [Response_1]
- Fri Oct 09 18:34:51 BST 2015:INFO:--> Refreshing the list
- Fri Oct 09 18:34:51 BST 2015:INFO:--> Response is: [Response_2]
- Fri Oct 09 18:34:51 BST 2015:INFO:--> Response is: [Response_1]
- Fri Oct 09 18:34:52 BST 2015:INFO:--> Refreshing the list
- Fri Oct 09 18:34:52 BST 2015:INFO:--> Response is: [Response_2]
The SOAP XML Responses from the mock service are swicthing betwen Response_2 and Response_1 as desired.