【发布时间】:2021-10-20 20:11:29
【问题描述】:
我有一个需要多个条目的 REST API POST 请求。这些条目是使用 PathSegment 提取的。 API 正在工作,但是当我使用 Rest Assured 编写测试用例时,我遇到了断言失败。我将 JAX-RS 和 Jersey 用于 API。
我已经通过 SO 和其他一些论坛寻求答案,但没有令人满意的答案。
我的 REST API 代码是:
@Produces(MediaType.APPLICATION_JSON)
@Path("/order/{id}/{var1: items}/{var2: qty}")
public final String orderMultipleItems(@PathParam("var1") final PathSegment itemPs, @PathParam("var2") final PathSegment qtyPs,
@PathParam("id") final int id) {
HashMap<Integer, Integer> items = new HashMap<Integer, Integer>();
//rest of the code
}
这是我放心的代码:
@Test
public final void testOrderMultipleItems() throws URISyntaxException, AssertionError {
String msg= given().contentType("application/json").when()
.post(TestUtil.getURI("/api/customer/order/1002/items;item=3006;item=3005/qty;q=1;q=1"))
.getBody().asString();
assertNotEquals("Order(s) Received", msg);
}
我在测试时得到 404,但当我通过 curl 运行 POST 请求时得到 200。我是否在我的发布请求的测试用例中犯了错误?
任何建议都将不胜感激。
【问题讨论】: