0

如何使用 WebTestClient 为没有 RequestBody 的控制器的 Post Request 方法编写 Junit 测试用例? 我在 Restcontroller 中有一个 Post 方法,如下所示 -

    public ResponseEntity<Object> submit(@PathVariable("cartId"),@RequestHeader(value = "affId") String affId) {
        return orderService.submit(cartId,affId);
    }

截至目前,我正在尝试如下,但它给出:java.lang.AssertionError: Status expected:<200 OK> but was:<415 UNSUPPORTED_MEDIA_TYPE>

when(orderService.submit(anyString(), anyString())).thenReturn(getResponseObject());
            webTestClient.post().uri("/CartApi/{cartId}", "abc12345")
                    .header("affId", "123").exchange().expectStatus().isOk();
4

0 回答 0