-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRUD.java
More file actions
70 lines (51 loc) · 1.99 KB
/
CRUD.java
File metadata and controls
70 lines (51 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package homeAPI;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
public class CRUD {
public static int id;
@Test
public void createRecord() throws JSONException {
String json = new JSONObject().put("Street", "Konstantin.Velichkov").put("City", "Sofia").put("zip", "454353")
.put("phone_number", "46754365463").toString();
RestAssured.baseURI = "http://milen.gq:3000/api/addresses/";
Response r = given().contentType("application/json").body(json).when().post("");
JsonPath jsonPathEvaluator = r.jsonPath();
id = jsonPathEvaluator.get("id");
System.out.println(id);
String body = r.getBody().asString();
System.out.println(body);
}
public int getId() {
return id;
}
public void setId(int id) {
CRUD.id = id;
}
@Test
public void getReccord() {
given().when().get("http://milen.gq:3000/api/addresses/"+ id).then().statusCode(200).contentType("application/json")
.body("id", is(id), "City", is("Sofia"));
}
@Test
public void updateRecord() throws JSONException {
String json = new JSONObject().put("Street", "Konstantin.Velichkov").put("City", "Sofia").put("zip", "6767").put("zip", "454353")
.put("phone_number", "6666666").put("id", id).toString();
System.out.println(id);
RestAssured.baseURI = "http://milen.gq:3000/api/addresses/"+ id;
Response r = given().contentType("application/json").body(json).when().put("");
System.out.println(id);
String body = r.getBody().asString();
System.out.println(body);
}
/*@Test
public void getUpdatedReccord() {
given().when().get("http://milen.gq:3000/api/addresses/" + id).then().statusCode(200).contentType("application/json")
.body("id", is(id), "phone_number", is("0876002233"));
}*/
}