如何在请求SOAP模拟服务的Groovy中多次复制相同类型

huangapple go评论44阅读模式
英文:

How to multiuply times the same type in request soap mock service groovy

问题

抱歉,由于代码格式的特殊性,我可以帮你理解这段代码的意思并提供指导。

这段代码是关于发送 SOAP 模拟服务中的请求,其中包含了发送多行相同类型的数据的需求。在给定的 XML 结构中,<invoiceDatas> 标签内包含了<invoiceData>,表示发票数据的单行。

你想要发送不止一行,比如3行数据,以此类推。为了实现这一目标,你需要重复<invoiceData>块多次,每次填充不同的数据。

你希望的响应结果是重复的<invoiceData>块,每个块都包含相同的结构但数据不同。为了实现这一点,你可以在请求中重复<invoiceData>的部分,每个重复的部分填入不同的数据。这样的请求会在响应中生成多个<invoiceData>块。

至于如何用 Groovy 动态实现这个目标,你可以使用循环或动态生成 XML 的方式来构建请求。使用 Groovy 的 XML 处理功能,你可以编写代码来循环创建多个<invoiceData>块,并填充不同的数据。这样可以灵活地生成包含所需行数数据的请求。

希望这能帮助你动态地生成包含多行相同类型数据的请求。

英文:

How to send multiply time the same type in request soap mock services

   <invoiceDatas>
               <!--Zero or more repetitions:-->
               <invoiceData>
                  <id>?</id>
                  <MPK>?</MPK>
                  <RK>?</RK>
                  <value>?</value>
               </invoiceData>
            </invoiceDatas>

i alwyas can send one row with this, but how to change to send for example 3 rows
cans omeone explain
in response i should have

 <invoiceDatas>
               <!--Zero or more repetitions:-->
               <invoiceData>
                  <id>?</id>
                  <MPK>?</MPK>
                  <RK>?</RK>
                  <value>?</value>
               </invoiceData>
  <!--Zero or more repetitions:-->
               <invoiceData>
                  <id>?</id>
                  <MPK>?</MPK>
                  <RK>?</RK>
                  <value>?</value>
               </invoiceData>
  <!--Zero or more repetitions:-->
               <invoiceData>
                  <id>?</id>
                  <MPK>?</MPK>
                  <RK>?</RK>
                  <value>?</value>
               </invoiceData>
            </invoiceDatas>

how i can do that ?
i knwo the best oprion it is to copy this type but i want to this dynamic by groovy

答案1

得分: 1

我已经阅读了他们的文档,但是我无法理解其中的头绪。文档太模糊了,假设太多,以至于它并不是特别有用。使用手动构建请求的流程,我认为在手动请求中不可能创建一个重复的表达式。你将不得不手动编写4或5个invoiceData节点,每个节点都带有问号,然后使用他们的表单界面来填充这些内容。但是你不能使用那种方法为N个项目创建一个重复表达式(比如forEach、each等)。

因此,你必须切换到Groovy脚本,但那里的文档完全没有帮助。使用Groovy脚本,我甚至无法构建一个简单请求,与手动请求给出的等效内容相同。我认为你最好的选择是在他们的论坛上寻求帮助:https://community.smartbear.com/t5/SoapUI-Open-Source/ct-p/soapui-os-community

除此之外,我建议你放弃那个工具,并使用另一个更适合程序员的库,比如:https://github.com/jwagenleitner/groovy-wslite

这是一个较旧的库,但我最近使用过并且很喜欢它。它很容易上手编码,而且使用起来不费吹灰之力,依赖项很少。如果你在使用Groovy 3或4,它并不是真正受支持的,并且使用了已弃用的类,但仍然非常适用于SOAP。

英文:

I've read their documentation and I can't make heads or tails of it. It's so vague and assumes too much for it to be of much use. Using the manual request building process I don't think it's possible to create a repetitive expression in a Manual Request. You'd have to manually write out say 4 or 5 invoiceData nodes each with ? and then fill those in using their Form UI. But you couldn't create a repetition expression (forEach, each, etc) for N items using that method.

So you have to switch to Groovy script, but the documentation there is entirely unhelpful. Using a groovy script I couldn't even get to building a simple request equivalent to what the Manual Request gave you. I think you're best bet is to ask on their forum for help: https://community.smartbear.com/t5/SoapUI-Open-Source/ct-p/soapui-os-community

Beyond that I'd just cut my losses with that tool and go with another more programmer friendly library like: https://github.com/jwagenleitner/groovy-wslite

It's an older library, but I recently used it and I liked it. It was low barrier to get coding, worked without a lot of effort, and had a very low number of dependencies. It's not really supported and uses deprecated classes if you're working Groovy 3 or 4, but it's still quite usable and useful for SOAP.

huangapple
  • 本文由 发表于 2023年2月19日 22:22:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75500798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定