为类型数组设置数据- RestAssured Post 方法
Setting data for type array- RestAssured Post Method
我正在尝试为此 body 创建一个有效负载,并将执行 POST。
{
"location": {
"lat": -38.383494,
"lng": 33.427362
},
"accuracy": 50,
"name": "Frontline house Seattle",
"phone_number": "(1) 952 893 3937",
"address": "29, side layout, cohen 09",
"types": [
"shoe park",
"shop"
],
"website": "http://google.com",
"language": "French-EN"
}
这是我创建的 3 个 classes
@Getter
@Setter
public class Payload {
private Location location;
private int accuracy;
private String name;
private String phone_number;
private String address;
private List<Types> types;
private String website;
private String language;
}
@Getter
@Setter
public class Location {
private double lat;
private double lng;
}
@Setter
@Getter
public class Types {
private String zero;
private String one;
}
以下将用于执行 post
@Test
public void createAddress(){
Location location = new Location(); // Location Class
location.setLat(-38.383494);
location.setLng(33.427362);
Types[] type = new Types[2]; // Type Class
Payload payload = new Payload();
payload.setLocation(location); // This is how we will set the Location type class in Payload
payload.setAccuracy(50);
payload.setName("Frontline house");
payload.setPhone_number("(1) 952 893 3937");
payload.setAddress("29, side layout, cohen 09");
payload.setTypes();
}
问题: 我不确定如何设置类型的值来创建这个 payload.I 也感觉我错误地声明了类型。在 class 中,我声明了 2 个字符串变量。
提前感谢您的建议。
您不必为类型创建单独的 class,因为它是一个列表,只需将其声明为字符串列表即可
@Setter
@Getter
private List<String> types;
它们的 getter 和 setter 是
public List<String> getTypes() {
return types;
}
public void setTypes(List<String> types) {
this.types = types;
}
在你的测试中
List<String> myList =new ArrayList<String>();
myList.add("shoe park");
myList.add("shop");
payload.setTypes(myList);
我正在尝试为此 body 创建一个有效负载,并将执行 POST。
{
"location": {
"lat": -38.383494,
"lng": 33.427362
},
"accuracy": 50,
"name": "Frontline house Seattle",
"phone_number": "(1) 952 893 3937",
"address": "29, side layout, cohen 09",
"types": [
"shoe park",
"shop"
],
"website": "http://google.com",
"language": "French-EN"
}
这是我创建的 3 个 classes
@Getter
@Setter
public class Payload {
private Location location;
private int accuracy;
private String name;
private String phone_number;
private String address;
private List<Types> types;
private String website;
private String language;
}
@Getter
@Setter
public class Location {
private double lat;
private double lng;
}
@Setter
@Getter
public class Types {
private String zero;
private String one;
}
以下将用于执行 post
@Test
public void createAddress(){
Location location = new Location(); // Location Class
location.setLat(-38.383494);
location.setLng(33.427362);
Types[] type = new Types[2]; // Type Class
Payload payload = new Payload();
payload.setLocation(location); // This is how we will set the Location type class in Payload
payload.setAccuracy(50);
payload.setName("Frontline house");
payload.setPhone_number("(1) 952 893 3937");
payload.setAddress("29, side layout, cohen 09");
payload.setTypes();
}
问题: 我不确定如何设置类型的值来创建这个 payload.I 也感觉我错误地声明了类型。在 class 中,我声明了 2 个字符串变量。
提前感谢您的建议。
您不必为类型创建单独的 class,因为它是一个列表,只需将其声明为字符串列表即可
@Setter
@Getter
private List<String> types;
它们的 getter 和 setter 是
public List<String> getTypes() {
return types;
}
public void setTypes(List<String> types) {
this.types = types;
}
在你的测试中
List<String> myList =new ArrayList<String>();
myList.add("shoe park");
myList.add("shop");
payload.setTypes(myList);