-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75827ff
commit f4bc269
Showing
7 changed files
with
97 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.giangtester.api; | ||
|
||
import com.giangtester.models.Student; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class DeleteStudent { | ||
|
||
public Response deleteStudent(Student student) { | ||
return given().log().all() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.delete("/{id}", student.getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.giangtester.api; | ||
|
||
import com.giangtester.models.Student; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class PostStudent { | ||
|
||
public Response createAStudent(Student student) { | ||
return given().log().all() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(student) | ||
.post(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.giangtester.api; | ||
|
||
import com.giangtester.models.Student; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class PutStudent { | ||
|
||
public Response updateStudent(Student student, String id) { | ||
return given().log().all() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(student) | ||
.put("/{id}", id); | ||
} | ||
} |
29 changes: 14 additions & 15 deletions
29
src/test/java/com/giangtester/features/DELETEStudentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
package com.giangtester.features; | ||
|
||
import com.giangtester.api.DeleteStudent; | ||
import com.giangtester.api.PostStudent; | ||
import com.giangtester.base.BaseClass; | ||
import com.giangtester.models.Student; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class DELETEStudentTest extends BaseClass { | ||
|
||
@Test | ||
void deleteAnExistingStudent() { | ||
// Arrange: Setup data | ||
Student student = Student.getInstance(); | ||
given().log().all().contentType(ContentType.JSON) | ||
.when().body(student).post(); | ||
private Student student; | ||
private final PostStudent postStudent = new PostStudent(); | ||
private final DeleteStudent deleteStudent = new DeleteStudent(); | ||
|
||
// Act: Call API delete student | ||
Response res = given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.delete("/{id}", student.getId()); | ||
@BeforeEach | ||
void createStudent() { | ||
student = Student.getInstance(); | ||
postStudent.createAStudent(student); | ||
} | ||
|
||
// Assert | ||
@Test | ||
void deleteAnExistingStudent() { | ||
Response res = deleteStudent.deleteStudent(student); | ||
res.then().statusCode(204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 11 additions & 23 deletions
34
src/test/java/com/giangtester/features/POSTNewStudentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,27 @@ | ||
package com.giangtester.features; | ||
|
||
import com.giangtester.api.PostStudent; | ||
import com.giangtester.base.BaseClass; | ||
import com.giangtester.models.Student; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class POSTNewStudentTest extends BaseClass { | ||
|
||
@Test | ||
void postNewStudent() { | ||
List<String> courses = new ArrayList<>(); | ||
courses.add("Math"); | ||
courses.add("Economics"); | ||
private Student student; | ||
private final PostStudent postStudent = new PostStudent(); | ||
|
||
Student student = Student.getInstance(); | ||
student.setId(101); | ||
student.setFirstName("Giang"); | ||
student.setLastName("Nguyen"); | ||
student.setEmail("giang.nguyen@gc.com"); | ||
student.setProgramme("Computer Science"); | ||
student.setCourses(courses); | ||
@BeforeEach | ||
void createStudent() { | ||
student = Student.getInstance(); | ||
} | ||
|
||
Response res = given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(student) | ||
.post(); | ||
//res.prettyPrint(); | ||
@Test | ||
void postNewStudent() { | ||
Response res = postStudent.createAStudent(student); | ||
res.then().statusCode(201).body("msg", equalTo("Student added")); | ||
} | ||
} |
25 changes: 14 additions & 11 deletions
25
src/test/java/com/giangtester/features/PUTStudentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters