【问题标题】:Rest Assured Failed to parse the JSON document放心解析 JSON 文档失败
【发布时间】:2019-08-08 16:53:36
【问题描述】:

我正在尝试测试我正在做的一项小型休息服务,以使用放心学习。我听从了这个人视频的建议:https://www.youtube.com/watch?v=yDdBOspPp_c

但是在实现帖子的时候说:解析json文档失败 但是,数据会保存在数据库中。我该怎么办?

@SuppressWarnings("unchecked")
    @Test
    public void deveInserirUmProduto() {

        // Specify base URI
        RestAssured.baseURI = "http://localhost:8080/ProjetoJersey/api/produto";

        // Request Object
        RequestSpecification httpRequest = RestAssured.given();

        //Request playload sending along with post request
        JSONObject requestParams = new JSONObject();

        requestParams.put("nome", "MacBook PRO");
        requestParams.put("tipoProduto", "INFORMATICA");
        requestParams.put("valor", 26000.00);
        requestParams.put("cor", "Cinza Espacial");
        requestParams.put("especificacoes", "Top de linha");

        httpRequest.header("Content-type", "application/json");

        httpRequest.body(requestParams.toJSONString());

        // Response Object
        Response response = httpRequest.request(Method.POST, "/");

        // Print response in console window
        String responseBody = response.getBody().asString();
        System.out.println("Response Body is: " + responseBody);

        // Status code validation
        int statusCode = response.getStatusCode();
        System.out.println("Status code is: " + statusCode);
        Assert.assertEquals(statusCode, 201);

        // Success code validation
        String successCode = response.jsonPath().get("SuccessCode");
        Assert.assertEquals(successCode, "OPERATION_SUCCESS");

    }

【问题讨论】:

    标签: java junit rest-assured rest-assured-jsonpath


    【解决方案1】:
     Response response = httpRequest.request(Method.POST, "/");
    

    在上面的行中,您只输入了“/”。我认为应该是“/register”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 2015-10-05
      • 2021-05-30
      • 1970-01-01
      • 2017-07-27
      • 2015-10-19
      • 2015-01-19
      相关资源
      最近更新 更多