Rest 在模拟服务URL中使用通配符
我需要模拟一个rest服务,模拟已经在SoapUI上运行了。问题是我创建了一个模拟,其URL如下Rest 在模拟服务URL中使用通配符,rest,groovy,mocking,soapui,Rest,Groovy,Mocking,Soapui,我需要模拟一个rest服务,模拟已经在SoapUI上运行了。问题是我创建了一个模拟,其URL如下/test/userA/ 有没有一种方法可以创建一个模拟,该模拟也会响应url/test/userB/?我想的是/test/user?/或test/user[A-Z]/。使用SoapUI可能吗?我有点晚了,但这是一个可能的解决方案 在SOAPUI mockService中无法配置此类路径,但是您可以使用以下方法模拟您的目标: 您可以通过这种方式将所有请求配置为仅url路径/http://your.mo
/test/userA/
有没有一种方法可以创建一个模拟,该模拟也会响应url
/test/userB/
?我想的是/test/user?/
或test/user[A-Z]/
。使用SoapUI可能吗?我有点晚了,但这是一个可能的解决方案
在SOAPUI mockService中无法配置此类路径,但是您可以使用以下方法模拟您的目标:
您可以通过这种方式将所有请求配置为仅url路径/
http://your.mock.host:port/将在mockService中处理
然后,要检查路径是否是您想要的路径,并根据[A-Z]做出不同的响应,您可以在mockService的onRequest script
选项卡或mockService内部操作的Dispatch(script)
选项卡中使用以下groovy脚本:
// the regex
def pathRegex = /^\/test\/user([A-Z])\//
// get the request path
def path = mockRequest.getPath()
// check if the path is correct
def matcher = (path =~ pathRegex)
// path is not correct
// change assert to do your logic break...
assert matcher.matches()
// path is correct get the exaclty user[A-Z] to do
// your logic
def letter = matcher.group(1)
log.info letter
// do your logic depends on letter
...
此脚本的行为类似于:
对于URL/错误/URL/
输出:
assert matcher.matches()
| |
| false
java.util.regex.Matcher[pattern=^/test/test([A-Z])/ region=0,10 lastmatch=]
对于URL/test/userA/
Wed Nov 04 10:02:06 CET 2015:INFO:A
对于URL/test/userW/
11月4日星期三10:02:33 CET 2015:INFO:W
希望这有帮助