Forum Discussion
Hi Tim,
Sounds reasonable.
To make the request from the mock, I would say there are 3 main options:
1) Call the actual service using a thrid party java/Groovy library e.g. like you said using ws-lite or similar
2) Call the actual service using the SoapUI objects, as per Ole's solution in the post you referenced.
3) Call the actual service using by triggering another seperate TestCase which contains a Request TestStep to call your actual service.
I would say all are fine options, and I could discuss the others/provide code advice, but since you propabably already considered the first two options, I'll try to describe my idea for option 3) incase you prefer it as a less code centric option.
So the main part of option 3 is how to trigger the separate TestCase, this can be done in the mock script using something like:
//You can pass data when calling the TestCase e.g. the mock request
def map = new StringToObjectMap()
map.put("responseData", requestToMock)
def testSuite = context.mockService.project.
getTestSuiteByName("Separate TestSuite")
def callBackTestCase = testSuite.getTestCaseByName("Separate TestCase")
def callBackRequest = (WsdlTestRequestStep) callBackTestCase.getTestStepsOfType(WsdlTestRequestStep.class).get(0)
(This code was adapted from a different solution, but similar use-case http://community.smartbear.com/t5/SoapUI-Open-Source/How-to-simulate-an-asynchronous-web-service-with-mock-services/m-p/98365#M17496)
Does this make sense? So basically option 3 involves a small amout of Groovy code in the mock to get SoapUI to forward the mock request to the actual service, maybe also has the avantage of being able to add Assertions for the forwarding Request TestStep..
Let me know if you'd like to discuss any points.
Hope this helps,
Cheers,
Rupert
Thanks for the reply Rupert.
can you please explain this line in your suggestion:
def callBackRequest = (WsdlTestRequestStep) callBackTestCase.getTestStepsOfType(WsdlTestReques​tStep.class).get(0)
I'm pretty new to Groovy and I'm not familiar with the syntax of class name in parens
"callBackRequest = (WsdlTestRequestStep)"
Thanks,
Tim
- rupert_anderson9 years agoValued Contributor
Hi Tim,
I do appologise for that line, I think I accidentally copied that part in from the other solution (referenced from the link). What that line does (or did in the other solution) was to get hold of the request contained in the other TestCase in order to set the endpoint property to the call back url - it was using WS-Addressing to provide a call back address you see.
In your case the only parts you might need are:
def map = new StringToObjectMap()
map.put("responseData", requestToMock)def testSuite = context.mockService.project.
getTestSuiteByName("Separate TestSuite")
def callBackTestCase = testSuite.getTestCaseByName("Separate TestCase")callBackTestCase.run(map, false) //true here means call asynchronously i.e. dont wait to the TestCase to finish first
But... now that you have said that you need to package the mock as a war, then that makes this solution innapropriate since the separate TestCase used to forward the request could not be packaged in the mock!
With that I recomend solution 1 or 2 i.e. I think you need to make a Groovy request based on the mockRequest in order to forward the request on to the actual service. If you need any tips for this please ask.
Cheers,
Rupert
Related Content
- 10 months agolodecesa
- 3 years agokimmatsumoto
- 8 months agoMehwishDaud
- 2 years agorodm0001
Recent Discussions
- 13 hours agoemoya
- 17 hours agoMyBalanceNow