【发布时间】:2020-11-24 12:45:12
【问题描述】:
在以下情况下需要帮助:
我有以下 pojo 类,当我使用 reassured 进行后调用时,我不想在我的 java 类中设置每个字段。要实现这些,需要维护一个 createissue.json 文件。 在进行后期调用时,我想从 createissue.json 文件中读取每个字段。
下面是我的 pojo 类 CreateIssuepayload.java
公共类 CreateIssuepayload {
@JsonProperty("summary")
private String summary;
@JsonProperty("description")
private String description;
@JsonProperty("issuetype")
private IssueType issuetype;
@JsonProperty("project")
private Project project;
public CreateIssuepayload(Project project, IssueType issuetype,String description, String summary) {
this.summary = summary;
this.description = description;
this.issuetype = issuetype;
this.project = project;
}
public CreateIssuepayload(Project project,IssueType issuetype,String description) {
this.description = description;
this.issuetype = issuetype;
this.project = project;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public IssueType getIssuetype() {
return issuetype;
}
public void setIssuetype(IssueType issuetype) {
this.issuetype = issuetype;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
}
我的 createissue.json 文件
{
"fields":{
"summary":"Please look into issue",
"description":"Unable to create my JIRA ticket 3",
"issuetype":{
"name":"Bug"
},
"project":{
"key":"BP"
}
}
}
还有我的测试用例来发出帖子请求
@Test(enabled = false)
public static void test1() throws JsonProcessingException {
IssueType issuetype = new IssueType("**Bug**");
Project project = new Project("**BP**");
CreateIssuepayload mypojo = new CreateIssuepayload(project, issuetype, "**Unable to create my JIRA ticket 3**",
"**Please look into issue.....**");
Fields f = new Fields(mypojo);
RestAssured.baseURI = "http://localhost:8080";
Response res = given().header("Content-Type", "application/json")
.header("cookie", "JSESSIONID=" + Basic.sessionGen() + "").body(f).expect()
.body(containsString("greeting")).when().post("/rest/api/2/issue").then().extract().response();
}
这里我不想在 java 类的测试用例中设置我的测试数据,如 Bug、BP 等。我想从 json 文件中动态读取它
注意:我也不想将整个 json 文件作为我的正文发布。
感谢任何帮助。 谢谢。
【问题讨论】:
标签: java json rest-assured rest-assured-jsonpath