diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c0ee0d5 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/body.json b/body.json new file mode 100644 index 0000000..f5efc57 --- /dev/null +++ b/body.json @@ -0,0 +1,11 @@ +{ + "id": "9", + "name": "Leena", + "location": "Denver", + "phone": "+1-555-4455", + "courses": [ + "C++", + "Game Development", + "Graphics Programming" + ] +} \ No newline at end of file diff --git a/jsonServer/students.json b/jsonServer/students.json index 2356bb3..b8a7242 100644 --- a/jsonServer/students.json +++ b/jsonServer/students.json @@ -22,17 +22,6 @@ "Machine Learning" ] }, - { - "id": "3", - "name": "Charlie Williams", - "location": "Chicago", - "phone": "+1-555-9101", - "courses": [ - "Python", - "React", - "Cybersecurity" - ] - }, { "id": "4", "name": "Diana Evans", @@ -111,72 +100,15 @@ ] }, { - "id": "a786", - "courses": "[SeleniumTesting, DevOps]", - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "49ae", - "courses": "[SeleniumTesting, DevOps]", - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "dc1f", - "courses": "[SeleniumTesting, DevOps]", - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "8e58", - "courses": "[SeleniumTesting, DevOps]", - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "22b2", + "id": "9", "courses": [ - "SeleniumTesting", - "DevOps" + "C++", + "Game Development", + "Graphics Programming" ], - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "60b3", - "courses": [ - "SeleniumTesting", - "DevOps" - ], - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "54d0", - "courses": [ - "SeleniumTesting", - "DevOps" - ], - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" - }, - { - "id": "7def", - "courses": [ - "SeleniumTesting", - "DevOps" - ], - "phone": "+1 2019361028", - "name": "Zakaria", - "location": "Queens" + "phone": "+1-555-4455", + "name": "Leena", + "location": "Denver" } ] } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8901c74..acf3b55 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,13 @@ json-schema-validator 5.5.0 + + + org.json + json + 20240303 + + com.github.scribejava diff --git a/src/test/java/zacksolutions/DayTwo/Pojo_PostReq.java b/src/test/java/zacksolutions/DayTwo/Pojo_PostReq.java new file mode 100644 index 0000000..10ac6ab --- /dev/null +++ b/src/test/java/zacksolutions/DayTwo/Pojo_PostReq.java @@ -0,0 +1,40 @@ +package zacksolutions.DayTwo; + +public class Pojo_PostReq { + String name; + String location; + String phone; + String [] courses; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String[] getCourses() { + return courses; + } + + public void setCourses(String[] courses) { + this.courses = courses; + } +} diff --git a/src/test/java/zacksolutions/DayTwo/PostReqBodyTest.java b/src/test/java/zacksolutions/DayTwo/PostReqBodyTest.java index 4221d0f..d4dbb3c 100644 --- a/src/test/java/zacksolutions/DayTwo/PostReqBodyTest.java +++ b/src/test/java/zacksolutions/DayTwo/PostReqBodyTest.java @@ -1,7 +1,12 @@ package zacksolutions.DayTwo; +import org.json.JSONObject; +import org.json.JSONTokener; import org.testng.annotations.Test; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -12,23 +17,25 @@ import static io.restassured.RestAssured.when; import static org.hamcrest.Matchers.equalTo; public class PostReqBodyTest { - @Test(priority = 1) + public String id; + //@Test(priority = 1) void getStudents() { - String name= when().get("http://127.0.0.1:3000/students/7").jsonPath().getString("name"); + String name= when().get("http://127.0.0.1:3000/students/54d0").jsonPath().getString("name"); List courses = new ArrayList<>(); - courses = when().get("http://127.0.0.1:3000/students/7def").jsonPath().getList("courses"); + courses = when().get("http://127.0.0.1:3000/students/54d0").jsonPath().getList("courses"); System.out.println("The student name is: " + name + " and skill set is as follow " + courses.get(1)); } - @Test(priority = 2) +/* + @Test(priority = 1) void postStudent(){ //first method to add data using HashMap HashMap data = new HashMap<>(); - String[] courses = {"SeleniumTesting", "DevOps"}; data.put("name", "Zakaria"); data.put("location", "Queens"); data.put("phone", "+1 2019361028"); + String[] courses = {"SeleniumTesting", "DevOps"}; data.put("courses", courses); given().contentType("application/json").body(data) .when().post("http://127.0.0.1:3000/students/") @@ -40,5 +47,61 @@ public class PostReqBodyTest { .body("courses[1]", equalTo("DevOps")).header("Content-Type", "application/json") .log().all(); } + @Test(priority = 2) + void DeleteStudent(){ + when().delete("http://127.0.0.1:3000/students/3"); + } +*/ +/* + @Test(priority = 1) + void postStudentORGLibrary(){ + //first method to add data using HashMap + JSONObject data = new JSONObject(); + data.put("name", "Zakaria"); + data.put("location", "Queens"); + data.put("phone", "+1 2019361028"); + String[] courses = {"SeleniumTesting", "DevOps"}; + data.put("courses", courses); + + given().contentType("application/json").body(data.toString()) + .when().post("http://127.0.0.1:3000/students/") + .then().statusCode(201) + .body("name", equalTo("Zakaria")) + .body("location",equalTo("Queens")) + .body("phone", equalTo("+1 2019361028")) + .body("courses[0]", equalTo("SeleniumTesting")) + .body("courses[1]", equalTo("DevOps")).header("Content-Type", "application/json") + .log().all(); + } + @Test(priority = 2) + void DeleteStudent(){ + when().delete("http://127.0.0.1:3000/students/3"); + + } +*/ +@Test(priority = 1) +void postStudentJsonFile() throws FileNotFoundException { + //first method to add data using HashMap + + FileReader fr = new FileReader(new File("body.json")); + JSONTokener jt = new JSONTokener(fr); + JSONObject data = new JSONObject(jt); + + given().contentType("application/json").body(data.toString()) + .when().post("http://127.0.0.1:3000/students/") + .then().statusCode(201) + .body("name", equalTo("Leena")) + .body("location", equalTo("Denver")) + .body("phone", equalTo("+1-555-4455")) + .body("courses[0]", equalTo("C++")) + .body("courses[1]", equalTo("Game Development")) + .body("courses[2]", equalTo("Graphics Programming")).header("Content-Type", "application/json") + .log().all(); +} + @Test(priority = 2) + void DeleteStudent(){ + when().delete("http://127.0.0.1:3000/students/3"); + + } }