如题,有大神知道怎么做吗?我没有看到任何 API 或教程如何操作。我的示例资源:
@Path("/tests")
@Consumes("application/json")
@Produces("application/json")
public class TestResource {
private final SomeDAO dao;
public TestResource(SomeDAO dao) {
this.dao = dao;
}
public static class RequestBody {
@JsonProperty("p1")
public String p1;
@JsonProperty("p2")
public String p2;
}
@POST
@UnitOfWork
public Saying postSomething(RequestBody requestBody) {
Thing thing = dao.create(new Thing(requestBody.p1, requestBody.p2));
return new Saying("Added : " + actor.toString());
//Saying is the representation of JSON response
}
最佳答案
您可以使用 Apache CXF 和 Jersey 的测试实用程序为 JAX-RS 资源编写端到端测试用例。请参阅以下链接中的示例:
https://cwiki.apache.org/confluence/display/CXF20DOC/JAXRS+Testing https://jersey.java.net/documentation/latest/test-framework.html
关于java - 如何在 Jackson 中对使用 JSON 正文作为参数的资源编写测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34300795/