复杂 json 中的嵌入表达式未正确替换

2024-04-17

在空手道测试中 - 我们能够替换 json 中单个键的嵌入表达式。但是当尝试替换 json 的复杂键时它不起作用

输入 json:

    {
    "integration": {
        "serviceData": {
            "integrationService": {
                "name": "#(integrationName)",
                "description": "#(tenantID)",
                "serviceData": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n  <block type=\"start_block\" id=\"foOIiCF5aZGnie1GzBDB\" deletable=\"false\" x=\"150\" y=\"25\">\n    <field name=\"ORCH_NAME\">Add2NumDocInputs</field>\n    <field name=\"SVC_SIGNATURE\">{\"sig_in\":{\"rec_ref\":\"fld_[#(tenantID)]_stage00.documenttypes:sum2\",\"field_type\":\"recref\",\"node_type\":\"record\",\"field_dim\":\"0\"},\"sig_out\":{\"field_type\":\"record\",\"node_type\":\"record\",\"field_dim\":\"0\"}}</field>\n    <field name=\"AUDIT_SETTINGS\"></field>\n    <statement name=\"ADD_BLOCKS\">\n      <block type=\"service_block_math\" id=\"aUqb0MAozTHQFuHj5rma\">\n        <field name=\"SERVICE\">pub.math:addInts</field>\n        <field name=\"SERVICE_DESC_FIELD\"></field>\n        <field name=\"SERVICE_DETAILS\">{\"service\":\"pub.math:addInts\",\"map\":[{\"sourcePath\":\"/n2;1;0\",\"targetPath\":\"/num2;1;0\"},{\"sourcePath\":\"/n1;1;0\",\"targetPath\":\"/num1;1;0\"}]}</field>\n      </block>\n    </statement>\n  </block>\n</xml>"
            }
        }
    }
}

在上面的 json 中,'tenantID' 是从测试用例传递的密钥。 “tenantID”已正确替换为 json 中的“description”键。但它没有被“serviceData”键替换

请提出一些解决方案。 提前致谢


编辑:发布很长的答案后(请参阅此答案的结尾/第二部分),我意识到有一个超级简单的解决方案供您使用replace https://github.com/intuit/karate#replace空手道的语法:

* def integrationName = 'hello'
* def tenantID = 'world'
* def json =
"""
{
    "integration": {
        "serviceData": {
            "integrationService": {
                "name": "#(integrationName)",
                "description": "#(tenantID)",
                "serviceData": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n  <block type=\"start_block\" id=\"foOIiCF5aZGnie1GzBDB\" deletable=\"false\" x=\"150\" y=\"25\">\n    <field name=\"ORCH_NAME\">Add2NumDocInputs</field>\n    <field name=\"SVC_SIGNATURE\">{\"sig_in\":{\"rec_ref\":\"fld_[<tenantID>]_stage00.documenttypes:sum2\",\"field_type\":\"recref\",\"node_type\":\"record\",\"field_dim\":\"0\"},\"sig_out\":{\"field_type\":\"record\",\"node_type\":\"record\",\"field_dim\":\"0\"}}</field>\n    <field name=\"AUDIT_SETTINGS\"></field>\n    <statement name=\"ADD_BLOCKS\">\n      <block type=\"service_block_math\" id=\"aUqb0MAozTHQFuHj5rma\">\n        <field name=\"SERVICE\">pub.math:addInts</field>\n        <field name=\"SERVICE_DESC_FIELD\"></field>\n        <field name=\"SERVICE_DETAILS\">{\"service\":\"pub.math:addInts\",\"map\":[{\"sourcePath\":\"/n2;1;0\",\"targetPath\":\"/num2;1;0\"},{\"sourcePath\":\"/n1;1;0\",\"targetPath\":\"/num1;1;0\"}]}</field>\n      </block>\n    </statement>\n  </block>\n</xml>"
            }
        }
    }
}
"""
* replace json.tenantID = tenantID
* match json == 
"""
{
    "integration": {
        "serviceData": {
            "integrationService": {
                "name": "hello",
                "description": "world",
                "serviceData": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n  <block type=\"start_block\" id=\"foOIiCF5aZGnie1GzBDB\" deletable=\"false\" x=\"150\" y=\"25\">\n    <field name=\"ORCH_NAME\">Add2NumDocInputs</field>\n    <field name=\"SVC_SIGNATURE\">{\"sig_in\":{\"rec_ref\":\"fld_[world]_stage00.documenttypes:sum2\",\"field_type\":\"recref\",\"node_type\":\"record\",\"field_dim\":\"0\"},\"sig_out\":{\"field_type\":\"record\",\"node_type\":\"record\",\"field_dim\":\"0\"}}</field>\n    <field name=\"AUDIT_SETTINGS\"></field>\n    <statement name=\"ADD_BLOCKS\">\n      <block type=\"service_block_math\" id=\"aUqb0MAozTHQFuHj5rma\">\n        <field name=\"SERVICE\">pub.math:addInts</field>\n        <field name=\"SERVICE_DESC_FIELD\"></field>\n        <field name=\"SERVICE_DETAILS\">{\"service\":\"pub.math:addInts\",\"map\":[{\"sourcePath\":\"/n2;1;0\",\"targetPath\":\"/num2;1;0\"},{\"sourcePath\":\"/n1;1;0\",\"targetPath\":\"/num1;1;0\"}]}</field>\n      </block>\n    </statement>\n  </block>\n</xml>"
            }
        }
    }
}
"""

编辑:这是原始答案(如下),留在这里,因为它可能作为参考有用。

哇,我可以说这是 XML 和 JSON 的可怕组合。嵌入表达式有一个规则,它们必须是字符串start with #(

所以你需要将你的流程分成这样的东西。由于您的有效负载,它很复杂。不是因为空手道:)

* def integrationName = 'hello'
* def tenantID = 'world'
* def recRef = 'fld_[' + tenantID + ']_stage00.documenttypes:sum2'
# by the way this is also possible as an embedded expression #('fld_[' + tenantID + ']_stage00.documenttypes:sum2')
* string signature = {"sig_in":{"rec_ref":"#(recRef)","field_type":"recref","node_type":"record","field_dim":"0"},"sig_out":{"field_type":"record","node_type":"record","field_dim":"0"}}
* def xml = 
"""
<xml xmlns="http://www.w3.org/1999/xhtml">
  <block type="start_block" id="foOIiCF5aZGnie1GzBDB" deletable="false" x="150" y="25">
    <field name="ORCH_NAME">Add2NumDocInputs</field>
    <field name="SVC_SIGNATURE">#(signature)</field>
    <field name="AUDIT_SETTINGS"></field>
    <statement name="ADD_BLOCKS">
      <block type="service_block_math" id="aUqb0MAozTHQFuHj5rma">
        <field name="SERVICE">pub.math:addInts</field>
        <field name="SERVICE_DESC_FIELD"></field>
        <field name="SERVICE_DETAILS">{"service":"pub.math:addInts","map":[{"sourcePath":"/n2;1;0","targetPath":"/num2;1;0"},{"sourcePath":"/n1;1;0","targetPath":"/num1;1;0"}]}</field>
      </block>
    </statement>
  </block>
</xml>
"""
* xmlstring xml = xml
* def json = 
"""
{
    "integration": {
        "serviceData": {
            "integrationService": {
                "name": "#(integrationName)",
                "description": "#(tenantID)",
                "serviceData": "#(xml)"
            }
        }
    }
}
"""
* match json ==
"""
{
    "integration": {
        "serviceData": {
            "integrationService": {
                "name": "hello",
                "description": "world",
                "serviceData": "#string"
            }
        }
    }
}
"""
* match json.integration.serviceData.integrationService.serviceData contains '"rec_ref":"fld_[world]_stage00.documenttypes:sum2"'

另请阅读有关类型转换的文档:https://github.com/intuit/karate#type-conversion https://github.com/intuit/karate#type-conversion

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

复杂 json 中的嵌入表达式未正确替换 的相关文章

随机推荐

  • 按数据存储 API 中的范围进行过滤

    数据存储 API 文档位于http docs ckan org en ckan 2 2 datastore html http docs ckan org en ckan 2 2 datastore html描述 datastore del
  • 在同一用户的不同设备之间共享 Facebook 访问令牌

    用户可以从不同的设备登录我们的应用程序 我们希望将用户的访问令牌转移到他们登录的所有设备 这样他们就不必在他们使用的每台设备上再次执行 Facebook 登录步骤 在 Facebook 的开发者文档页面之一 https developers
  • matplotlib - 从等高线提取值

    这个问题 答案对 https stackoverflow com questions 5666056 matplotlib extracting data from contour lines显示如何从等高线图中提取顶点 p cs coll
  • 按频率对波形进行颜色编码[关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想按本地频率内容显示每个部分中颜色编码的音频波形 基本上与 Serato Traktor 或任何其他
  • 显示当前时间 (EST)

    我创建了一个用户窗体 其中包含一个文本框 该文本框将显示美国东部时间的当前时间 唯一的问题是 反映的时间当然是我们国家的当前时间 所以我想将其转换为 EST 即 12 00从我们的时代开始 Private Sub UserForm Init
  • 如何在extjs中动态设置url和root

    有人能告诉我如何在 Ext JS 中动态设置商店的 url 和 root 吗 我创建了一家像下面这样的商店 我需要更新根并动态设置控制器内的 url Ext define Test store TestStore extend Ext da
  • WSDLException:尝试解析引用的架构时发生错误

    我正在尝试使用 windows xp 上的 eclipse Galileo 和 axis 2 1 4 从本地 WSDL 文件生成代理类 我的问题是 由于 WSDL 中导入的架构 我收到错误 令我烦恼的是
  • 使用 Facebook SDK 4.15.1 在 iOS 10 上使用 Facebook SDK 登录、分享和点赞时获取空白页面

    在我的应用程序中使用 FBSDKLoginKit FBSDKShareKit 登录 共享链接和点赞链接时 我收到此错误 我使用 FBSDKLoginButton 登录 property nonatomic strong IBOutlet F
  • 使用 WHERE 子句的值范围进行查询?

    我有一个 Google 电子表格 我想运行QUERY功能 但我想要WHERE语句来检查一系列值 我基本上是在寻找我会使用的东西INSQL 中的语句 什么是INGoogle 电子表格中的等效项 所以现在我有 QUERY Sheet1 A3 A
  • Google 服务帐户未获得日历 API 授权

    我正在尝试通过服务帐户连接到我们 G Suite 域上的所有日历 我创建了一个新项目 并在 API 和服务页面中启用了 Google Calendar API 我创建了一个 Google 服务帐户 A name 似乎适用的角色 生成的jso
  • 从应用程序的资源加载 .NET 程序集并从内存运行它,但不终止主/主机应用程序

    介绍 我正在使用共享的下一个 C 代码示例大卫赫夫南 for 从应用程序的资源加载 NET 程序集并从内存中运行它 https stackoverflow com a 24033647 1248295 Assembly a Assembly
  • 通过通用参考捕获

    当将推导类型作为右值引用传递时 我获得了通用引用功能 并且可以实现完美转发 如下所示 template
  • Typescript 中的类和 Keyof

    从 TypeScript 开始 我尝试使用keyof定义类的动态属性 type UserType id number name string class Domain
  • 如何在 Adob​​e AEM 中启用 WebDAV?

    我尝试通过 WebDAV 访问 Adob e AEM 但是无法使其工作 我正在运行开箱即用的 crx quickstart 因此我使用端口 4502 和默认工作区 我使用 Windows 资源管理器作为 WebDAV 客户端 可以轻松地连接
  • 如何使用php将数组分成两个相等的部分

    如何在 PHP 中使用 array slice 将数组分成两个相等的部分 这是我的要求 第一个数组包含 0 1200 第二个数组包含 1200 end From array slice 的文档 https www php net array
  • 如何将数据传递到 Angular-strap 弹出窗口

    我试图在悬停在全日历项目上时显示角带弹出框 我正在使用 eventMouseover eventMouseout 回调来显示 隐藏弹出窗口 scope calendarConfig defaultView basicWeek eventMo
  • git push origin master 凭据丢失或无效

    无法再推送到原始主机 git push origin master 几天以来 我卸载了 git 和 Visual Code 并重新安装了它 但没有任何结果 我遇到了同样的错误 Missing or invalid credentials E
  • 如何在同一进程中从不同路径加载到同一库两次?

    我正在编写一个新程序 即使用 OpenSSL 加密数据 我希望我的程序符合 FIPS 标准 为了强制执行 FIPS 模式 我使用 API 进行设置FIPS 模式 集 我还需要将加密的数据传输到第三方设备 设备供应商还提供了一个与设备通信的库
  • 在 C# 中匹配西里尔字母符号

    我有一个巨大的代码文件 其中有很多行 如下所示 Enterprise TextMessageBox Show String Format S n n 0 e gt Message S 我想做的是用我提供的另一个文本找到带有西里尔符号字符串的
  • 复杂 json 中的嵌入表达式未正确替换

    在空手道测试中 我们能够替换 json 中单个键的嵌入表达式 但是当尝试替换 json 的复杂键时它不起作用 输入 json integration serviceData integrationService name integrati