SoapUI 模拟异步服务 [英] SoapUI mocking asynchronous services

查看:19
本文介绍了SoapUI 模拟异步服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 SoapUI 来模拟 Web 服务,以便在我们访问真正的 Web 服务之前测试我们的应用程序 (APP).

We use SoapUI to mock web services to test our application (APP) before we have access to real webservices.

创建一个将返回预定义响应的同步模拟服务很简单.但是,我必须模拟一些 异步 服务,其中 APP 发送请求,SoapUI 立即响应确认(例如 SUCCESS),然后在预定义的时间间隔后 SoapUI 将调用我们的应用程序(APP 是然后充当服务器).我设法使用测试用例来做到这一点,其中第一步是 MockResponse,然后是延迟,然后是 MockRequest(调用我们的应用程序).

Creating a synchronous Mock Service which will return predefined response is straightforward. However I have to mock some asynchronous services where the APP sends a request, the SoapUI immediately responds back with confirmation (e.g. SUCCESS) and then after a predefined interval the SoapUI will call our application back (the APP is then acting as a server). I managed to do it using test case where first step is MockResponse, then delay and then MockRequest (to call our app).

以上工作正常,但我想通过直接在模拟响应中编写脚本来避免使用测试用例.我设法编写了脚本,当模拟服务收到请求时,它将触发回调.

The above works fine but I'd like to do it by scripting it directly in the Mock Reponse to avoid using Test Cases. I managed to write the script which when a Mock Service receives request it will fire the callback.

def project = result.mockOperation.mockService.project
// The API documentation doesn't say what finish is supposed to do but I try (doesn't help)
result.finish()
// Request that will be returned back - THE CALLBACK
def request = project.interfaces["LocationServicesOperation"].operations["ackLocation"].getRequestByName("Request 1")
sleep(4000)
request.submit(new com.eviware.soapui.impl.wsdl.WsdlSubmitContext(  ), false)

上面的问题是它会在发送初始请求的响应之前触发回调.我尝试在 SoapUI PRO 中使用事件处理,但无法正常工作.在 Wireshark 中,我可以看到这样的通信:

The issue with the above is that it will fire the callback BEFORE sending the response for the initial request. I tried using event handling in SoapUI PRO but I can't get that working. In Wireshark I can see the communication like this:

1) APP request -> SoapUI 
2) SoapUI callback -> APP
3) APP confirms 2) -> SoapUI 
4) SoapUI confirms 1) -> APP

但是它必须是:

1) APP request -> SoapUI 
2) SoapUI confirms 1) -> APP
3) SoapUI callback -> APP
4) APP confirms 2) -> SoapUI 

上面的代码实际上来自 SoapUI Pro 中的 MockRunListener.onMockResult 事件.result.finish() 不起作用.

The code above is actually from MockRunListener.onMockResult event in SoapUI Pro. the result.finish() doesn't do the trick.

感谢您的建议!

推荐答案

我终于在 http://www.eviware.com/forum/viewtopic.php?f=5&t=3542&p=12474&hilit=asynchronous#p12474

诀窍不是直接从响应脚本中分派请求,而是将回调请求添加到测试中,然后调用测试.这将导致模拟运行器首先发送对请求的响应,然后运行测试用例.

The trick was instead of dispatching the request directly from within the response script to add the callback request to a test and then call the test. This will cause the mock runner to first send response to the request and after that run the test case.

优点是测试用例是动态触发的,不需要一直运行.

The advantage is that the test case is triggered dynamically and doesn't need to run all the time.

这篇关于SoapUI 模拟异步服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆