-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
5 changed files
with
207 additions
and
0 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,5 @@ | ||
package com.anhtester.globals; | ||
|
||
public class TokenGlobal { | ||
public static String TOKEN; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/anhtester/Bai8_PATCH_DELETE/DemoDELETE.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.anhtester.Bai8_PATCH_DELETE; | ||
|
||
import com.anhtester.common.BaseTest; | ||
import com.anhtester.globals.TokenGlobal; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class DemoDELETE extends BaseTest { | ||
|
||
@Test | ||
public void testDeleteUser_DELETE() { | ||
|
||
//Chuẩn bị thông tin username để delete | ||
String username = "an01"; | ||
|
||
RequestSpecification request = given(); | ||
request.baseUri("https://api.anhtester.com/api") | ||
.accept("application/json") | ||
.contentType("application/json") | ||
.header("Authorization", "Bearer " + TokenGlobal.TOKEN) | ||
.queryParam("username", username); | ||
|
||
Response response = request.when().delete("/user"); | ||
response.prettyPrint(); | ||
|
||
response.then().statusCode(200); | ||
|
||
String message = response.getBody().path("message"); | ||
Assert.assertEquals(message, "Success", "The message not match."); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/test/java/com/anhtester/Bai8_PATCH_DELETE/DemoPATCH.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.anhtester.Bai8_PATCH_DELETE; | ||
|
||
import com.anhtester.common.BaseTest; | ||
import com.anhtester.globals.TokenGlobal; | ||
import com.anhtester.model.LoginPOJO; | ||
import com.anhtester.model.PatchUserPOJO; | ||
import com.google.gson.Gson; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class DemoPATCH extends BaseTest { | ||
|
||
@Test | ||
public void testUpdateUser_PATCH() { | ||
|
||
//Chuẩn bị data cho edit user | ||
PatchUserPOJO patchUserPOJO = new PatchUserPOJO(); | ||
patchUserPOJO.setFirstName("Thái"); | ||
patchUserPOJO.setLastName("Uyên"); | ||
patchUserPOJO.setEmail("[email protected]"); | ||
patchUserPOJO.setPhone("0111123456"); | ||
patchUserPOJO.setUserStatus(0); | ||
patchUserPOJO.setUsername("boiboi2"); | ||
|
||
Gson gson = new Gson(); | ||
|
||
RequestSpecification request = given(); | ||
request.baseUri("https://api.anhtester.com/api") | ||
.accept("application/json") | ||
.contentType("application/json") | ||
.header("Authorization", "Bearer " + TokenGlobal.TOKEN) | ||
.body(gson.toJson(patchUserPOJO)); | ||
|
||
Response response = request.when().patch("/user/2"); | ||
response.prettyPrint(); | ||
|
||
response.then().statusCode(200); | ||
|
||
String message = response.getBody().path("message"); | ||
Assert.assertEquals(message, "Success", "The message not match."); | ||
} | ||
|
||
@Test | ||
public void testUpdateUser_PATCH2(){ | ||
System.out.println(TokenGlobal.TOKEN); | ||
System.out.println("Test case thứ 2"); | ||
} | ||
|
||
@Test | ||
public void testUpdateUser_PATCH3(){ | ||
System.out.println(TokenGlobal.TOKEN); | ||
System.out.println("Test case thứ 3"); | ||
} | ||
} |
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,37 @@ | ||
package com.anhtester.common; | ||
|
||
import com.anhtester.globals.TokenGlobal; | ||
import com.anhtester.model.LoginPOJO; | ||
import com.google.gson.Gson; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.testng.annotations.*; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class BaseTest { | ||
@BeforeTest | ||
public void loginUser() { | ||
|
||
//Khởi tạo giá trị cho các fields thông qua hàm xây dựng | ||
LoginPOJO loginPOJO = new LoginPOJO("anhtester", "Demo@123"); | ||
|
||
//Dùng thư viện Gson để chuyển class POJO về dạng JSON | ||
Gson gson = new Gson(); | ||
|
||
RequestSpecification request = given(); | ||
request.baseUri("https://api.anhtester.com/api") | ||
.accept("application/json") | ||
.contentType("application/json") | ||
.body(gson.toJson(loginPOJO)); | ||
|
||
Response response = request.when().post("/login"); | ||
//response.prettyPrint(); | ||
|
||
response.then().statusCode(200); | ||
|
||
//Lưu giá trị token vào biến TOKEN nhé | ||
TokenGlobal.TOKEN = response.getBody().path("token"); | ||
System.out.println("Token: " + TokenGlobal.TOKEN); | ||
} | ||
} |
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,71 @@ | ||
package com.anhtester.model; | ||
|
||
public class PatchUserPOJO { | ||
|
||
private String firstName; | ||
private String lastName; | ||
private String email; | ||
private String phone; | ||
private int userStatus; | ||
private String username; | ||
|
||
public PatchUserPOJO() { | ||
} | ||
|
||
public PatchUserPOJO(String firstName, String lastName, String email, String phone, int userStatus, String username) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.email = email; | ||
this.phone = phone; | ||
this.userStatus = userStatus; | ||
this.username = username; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getPhone() { | ||
return phone; | ||
} | ||
|
||
public void setPhone(String phone) { | ||
this.phone = phone; | ||
} | ||
|
||
public int getUserStatus() { | ||
return userStatus; | ||
} | ||
|
||
public void setUserStatus(int userStatus) { | ||
this.userStatus = userStatus; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
} |