【问题标题】:patch endpoint test using rest assured mock mvc使用放心模拟 mvc 修补端点测试
【发布时间】:2021-11-16 20:14:13
【问题描述】:

我正在尝试使用放心的模拟 mvc 编写补丁端点测试。 但是我无法创建一个 jsonmerge 补丁的对象来放置在 mock 的主体中。下面是我需要编写测试的终点

     @PatchMapping(path = "/{orderId}", consumes = "application/merge-patch+json")
     public OrderDTO updateOrder(@PathVariable Long orderId, @RequestBody 
                                                       JsonMergePatchImpl patchRequest){
    return facade.patchOrder(orderId,patchRequest);


}

以下是我正在尝试但无法弄清楚的事情

            Mockito.when(facade.patchOrder(any(),any())).thenReturn(orderDTO);
            OrderDTO actual=given()
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            .body()
            .accept("application/merge-patch+json")
            .when()
            .patch(BASE_URL+"/"+1l)
            .then()
            .assertThat()
            .statusCode(200).extract().as(OrderDTO.class);

我的问题是我无法为 jsonmerge 补丁创建对象,以及作为内容类型放入的内容

【问题讨论】:

    标签: spring-boot integration-testing rest-assured mockmvc json-patch


    【解决方案1】:

    您可以将 contentType 指定为字符串:

    .contentType("application/merge-patch+json")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2019-05-23
      • 2021-10-31
      • 1970-01-01
      相关资源
      最近更新 更多