本文介绍了如何使用放心,以验证嵌套的反应如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助,使用放心库从下面的响应验证特定的JSON参数。

Need help to validate particular JSON parameter from below response using REST Assured library.

我尝试了一些选项来验证其他类似的参数,如下图所示,但没有奏效。

I tried some of the options to validate other similar parameter as shown below but it didn't work.

.then().body("value.value.value.name", hasItems("balanceResultCode")).body("value.value.value.value", hasItems("0"));

如果我想验证的结果code&放大器;从下面的响应subscriberIdType那我该怎么办呢?

If I want to validate "resultCode" & "subscriberIdType" from below response then how can I do it?

[
{
    "name":"Id",
    "value":"11"
},
{
    "name":"version",
    "value":null
},
{
    "name":"header",
    "value":[
        {
            "name":"mVersion",
            "value":"1"
        },
        {
            "name":"Name",
            "value":"BalQ"
        },
        {
            "name":"appID",
            "value":"90091"
        },
        {
            "name":"requestUid",
            "value":"REST_REQUQEST_1"
        },
        {
            "name":"sessionId",
            "value":"REST_SESSION_1"
        },
        {
            "name":"requestType",
            "value":"SomeRequestType"
        },
        {
            "name":"requestNumber",
            "value":"REQ_111"
        },
        {
            "name":"requestDuplicate",
            "value":"1"
        },
        {
            "name":"serviceProvider",
            "value":1
        },
        {
            "name":"username",
            "value":"user"
        },
        {
            "name":"password",
            "value":"pass"
        },
        {
            "name":"resultCode",
            "value":100
        }
    ]
},
{
    "name":"content",
    "value":[
        {
            "name":"subscriberAddressing",
            "value":[
                {
                    "name":"subscriber",
                    "value":[
                        {
                            "name":"subscriberIdType",
                            "value":200
                        },
                        {
                            "name":"subscriberIdValue",
                            "value":"1234567890"
                        }
                    ]
                }
            ]
        }
    ]
}

]

推荐答案

这是一个方法:

then().
       body("find { it.name == 'header' }.value.find { it.name == 'resultCode' }.value", is(100)).
       body("find { it.name == 'content' }.value.find { it.name == 'subscriberAddressing' }.value.find { it.name == 'subscriber' }.value.find { it.name == 'subscriberIdType'}.value", is(200));

您可以在Groovy的集合和GPath读取多达了解更多信息。

You can read up on Groovy collections and GPath to learn more.

这篇关于如何使用放心,以验证嵌套的反应如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:48