SoapUI模拟服务/模拟操作中的XPATH调度 [英] XPATH Dispatch in SoapUI Mock service/ Mock operation

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

问题描述

我是SoapUI的新手,并试图了解XPATH分派在模拟服务中进行模拟操作的用途.

I am new in SoapUI, and was trying to understand the use of XPATH dispatch for a mock operation in a mock service.

这是我到目前为止所做的事情

Here is what I have done so far

  1. 为计算器创建了模拟服务
  2. 添加了模拟操作减法

以下是该操作的示例请求

Following is a sample request for the operation

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
   <soapenv:Header/>
   <soapenv:Body>
      <cal:subtract>
         <cal:x>1</cal:x>
         <cal:y>1</cal:y>
      </cal:subtract>
   </soapenv:Body>
</soapenv:Envelope>

以下是针对相同内容的示例响应

Following is a sample response for the same

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
   <soapenv:Header/>
   <soapenv:Body>
      <cal:subtractResponse>
         <cal:Result>?</cal:Result>
      </cal:subtractResponse>
   </soapenv:Body>
</soapenv:Envelope>

我能够了解其他分派,但不了解XPATH,因为以下是我在XPATH分派中输入的内容

I was able to understand about other dispatch but not about XPATH as following is what I have entered in the XPATH dispatch

declare namespace cal='http://www.parasoft.com/wsdl/calculator/';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
//cal:subtract/cal:x

还观察到,如果我已经使用了SCRIPT分派并从下拉菜单切换到XPATH,则该脚本在声明/脚本框/区域中可见

It was also observed that if I have already used SCRIPT dispatch and switch to XPATH from the dropdown, the script is visible in the declaration/scripting box/area

以下是问题:

  1. XPATH和SCRIPT是否调度相同
  2. 如果没有,那么XPATH分派实际上是如何工作的,以从所有MockResponses列表中识别出要分派的响应

请帮助我.

PS:我已经经历了 http://www.soapui.org/soap-mocking/reference/mockoperation.html http://www.soapui.org/soap-mocking/mockoperations-and -responses.html

PS: I have already gone through http://www.soapui.org/soap-mocking/reference/mockoperation.html http://www.soapui.org/soap-mocking/mockoperations-and-responses.html

推荐答案

您在问题中提到的soapUI文档是获取信息的正确位置.但是,可用信息不完整.

The soapUI documentation that you mentioned in your question is the right location to get the information. However, the information available is not complete.

搜索了一段时间后,找到了详细信息.

After searching for sometime, found the details.

最初,在 Xpath Script 调度方法之间感到困惑.

Initially, got confused between Xpath and Script Dispatch methods.

以下是您要找的其他信息:

Here is the additional information than what you are looking for:

XPATH和SCRIPT调度是否相同

Is XPATH and SCRIPT dispatch same

答案为.两者都不一样

如果没有,那么XPATH调度实际上是如何工作的,以从所有MockResponses列表中识别出要调度的响应

If not, how does the XPATH dispatch actually work to identify what response to dispatch out of all form MockResponses list

在文档中找到的以下信息:

The following information found in the documentation:

XQUERY -这与QUERY_MATCH类似,但功能却不那么强大; XPath表达式应用于传入的请求,结果值用于选择要返回的MockResponse.在前面的搜索结果示例中,我们可以设置XPath表达式以选择一个搜索词,然后创建以每个期望值命名的MockResponses.优点是我们不需要为新的搜索条件添加新的XPath语句,只需添加另一个MockResponse.

XQUERY - This is similar to the QUERY_MATCH but not quite as powerful; an XPath expression is applied to the incoming request and the resulting value is used for selecting which MockResponse to be returned. In our previous example of search results, we could set the XPath expression to select a search term and then create MockResponses named after each expected value. The advantage being that we don’t need to add new XPath statements for new search criteria, just another MockResponse.

假设您为模拟服务操作创建了多个响应,例如PositiveResponseNegativeResponseZeroResponse.

Assume that you created multiple responses say PositiveResponse, NegativeResponse, ZeroResponse for subtract operation of Mock Service.

以下是您可能希望在请求中应用并发送适当的响应的示例条件.当然,您可能需要的数量就很多.

Here are the sample conditions that you may want to apply on the request and dispatch appropriate response. Of course, you may have as many as you require.

  1. PositiveResponse-如果x,y值分别为10、5.
  2. NegativeResponse-如果x,y值分别为5、10.
  3. ZeroResponse-否则(如果以上条件都不满足,则必须执行此操作.)
  1. PositiveResponse - if x, y values are 10, 5 respectively.
  2. NegativeResponse - if x, y values are 5, 10 respectively.
  3. ZeroResponse - otherwise (this is mandatory if none of the above satisfy).

这是您需要在为 XPATH 调度模式指定的编辑器中编写的方式

Here is how you need to write in the editor given for XPATH Dispatch mode

declare namespace cal='http://www.parasoft.com/wsdl/calculator/';
if (//cal:subtract/cal:x[. = '10'] and //cal:subtract/cal:y[. = '5']) then
    'PositiveResponse'
    else 
    if (//cal:subtract/cal:x[. = '5'] and //cal:subtract/cal:y[. = '10']) then
    'NegativeResponse'
    else
    'ZeroResponse'

希望您现在知道并区分 SCRIPT 调度模式.

Hope you are now aware and differentiate the SCRIPT Dispatch mode.

我认为造成混淆是因为 SCRIPT XPATH 都显示了相同类型的编辑器.但是其中的内容将完全不同.此外,如果您选择 SCRIPT 调度模式,您还可以轻松地在编辑器顶部看到一条消息,指出 log,上下文,mockRequest 变量的可用性,当 XPATH .

I think the confusion created because both SCRIPT and XPATH shows an editor of same type. But the content inside of it will be entirely different. Also you can easily see a message on top of the editor that log, context, mockRequest availability of variables if you select SCRIPT Dispatch mode and it vanishes when XPATH is choosen.

只要给出 SCIRPT 示例,以防您感兴趣:

Just giving SCIRPT example in case if you are interested in it:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def x = holder.getNodeValue("//*:x") as int
def y = holder.getNodeValue("//*:y") as int
context.result = x - y

可以进行简单测试(以区分两者),将上面的脚本复制为 xpath ,然后尝试进行测试,并收到 soap fault (肥皂故障),说不知道.该测试将确认 xpath script 不同.

A simple test can be (to differentiate between the two), copy the above script for xpath and try testing and soap fault is received saying does not know groovyUtils. This test will confirm that xpath and script are different.

在这里您可能不需要创建多个响应,因为上面的代码可以处理动态输入值并在响应中设置result. 操作的MockReponse可能如下所示,其中占位符${result}.

Here you may not needed to create multiple responses as the above code can handle dynamic input values and set the result in the response. MockReponse for subtract operation may look like below with place holder as ${result}.

脚本的MOCKRESPONSE:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
   <soapenv:Header/>
   <soapenv:Body>
      <cal:subtractResponse>
         <cal:Result>${result}</cal:Result>
      </cal:subtractResponse>
   </soapenv:Body>
</soapenv:Envelope>

希望这可以澄清.

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

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