[英]Rest-Assured - How to validate response body with POJO
I'm freshman in Rest-Assured.我是 Rest-Assured 的大一新生。 I have a simple test which gets response body and I want to validate whether the response body matches with my POJO class.
我有一个获取响应正文的简单测试,我想验证响应正文是否与我的 POJO class 匹配。
Here is my test:这是我的测试:
@Test
public void getMySmartPlansList() {
MySPList mysp = new MySPList();
given().log().all().spec(getReqSpec())
.get(Endpoints.getMY_SP())
.then().assertThat().statusCode(200).body("first_page_url", equalTo(mysp.getFirst_page_url()));
System.out.println("SUCCESS");
}
Here is my POJO class:这是我的 POJO class:
package com.payloads;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import java.util.List;
@Getter
public class MySPList {
private int current_page;
private List<MySPObject> data;
private String first_page_url = "/?page=1";
private int from;
private int last_page;
private String last_page_url;
@JsonIgnore private String next_page_url; ////
private String path;
private int per_page;
@JsonIgnore private String prev_page_url; ////
private int to;
private int total;
}
So how to validate that the response body structure is equal to my POJO class?那么如何验证响应体结构等于我的 POJO class 呢?
Thanks in advance提前致谢
Try the approach like this:试试这样的方法:
MyPOJO myPojo = RestAssured.given()
.get(new URL("https://YOU_URL"))
.getBody()
.as(MyPOJO.class);
And then compare the object to your golden one as usual.然后像往常一样将 object 与您的黄金进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.