如何使用 Rest Assured 在同一 API 主体上发送 String[] 和 String

我正在尝试使用 Rest-Assured 和 Java 为 POST API 创建测试自动化。


此 API 具有以下主体作为 Application/JSON:


{

    "billing_address": {

        "region": "Sao Paulo",

        "region_id": 123,

        "country_id": "BR",

        "street": ["Av Paulista"],

        "postcode": "10577",

        "city": "SAO PAULO",

        "telephone": "555-555-1111",

        "company": "Test test",

        "firstname": "Fernando",

        "lastname": "Alves",

        "document": "0123444064"

     }

}

在我的代码中,我开发了以下方法来发送此值和请求:


public void criarPF (String srtAmbiente, String srtAPI, String srtToken, String srtRegion, String srtRegionID, String srtCountryID, String srtStreet,

                    String srtPostcode, String srtCity, String srtTelephone, String srtCompany, String srtFirstname, String srtLastname, String srtDocument) {

                    

                    String uriBase = srtAmbiente;

                    String Api = srtAPI;

                    

                    Map<String, String> addressContent = new HashMap<String,String>();

                    addressContent.put("region", srtRegion);

                    addressContent.put("region_id", srtRegionID);

                    addressContent.put("country_id", srtCountryID);

                    addressContent.put("street", srtStreet);

                    addressContent.put("postcode", srtPostcode);

                    addressContent.put("city", srtCity);

                    addressContent.put("telephone", srtTelephone);

                    addressContent.put("company", srtCompany);

                    addressContent.put("firstname", srtFirstname);

                    addressContent.put("lastname", srtLastname);

                    addressContent.put("document", srtDocument);


我收到一条错误消息,指出“street”不是一个字符串,而是一个字符串 []。

那么,如何在同一 API 主体中发送 String 和 String[] 值?


天涯尽头无女友
浏览 88回答 1
1回答

小唯快跑啊

您正在设置street一个字符串值。像这样改变它:Map<String, Object> addressContent = new HashMap<>();addressContent.put("region", srtRegion);addressContent.put("region_id", srtRegionID);addressContent.put("country_id", srtCountryID);// Here wrap strStreet in a ListaddressContent.put("street", Arrays.asList(srtStreet));addressContent.put("postcode", srtPostcode);addressContent.put("city", srtCity);addressContent.put("telephone", srtTelephone);addressContent.put("company", srtCompany);addressContent.put("firstname", srtFirstname);addressContent.put("lastname", srtLastname);addressContent.put("document", srtDocument);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java