-
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
8 changed files
with
275 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/test/java/com/anhtester/Bai14_Annotation/CommonTest.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,30 @@ | ||
package com.anhtester.Bai14_Annotation; | ||
|
||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeMethod; | ||
|
||
public class CommonTest { | ||
|
||
@BeforeClass | ||
public void beforeBaseClass() { | ||
System.out.println("Parent Before Class method"); | ||
} | ||
|
||
@AfterClass | ||
public void afterBaseClass() { | ||
System.out.println("Parent After Class method"); | ||
} | ||
|
||
@BeforeMethod | ||
public void beforeBaseMethod() { | ||
System.out.println("Parent Before method"); | ||
} | ||
|
||
@AfterMethod | ||
public void afterBaseMethod() { | ||
System.out.println("Parent After method"); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/test/java/com/anhtester/Bai14_Annotation/DemoRunTestAnnotation.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,77 @@ | ||
package com.anhtester.Bai14_Annotation; | ||
|
||
import org.testng.annotations.*; | ||
|
||
public class DemoRunTestAnnotation extends CommonTest { | ||
|
||
@BeforeSuite | ||
public void beforeSuite() { | ||
System.out.println("Before Suite"); | ||
} | ||
|
||
@AfterSuite | ||
public void afterSuite() { | ||
System.out.println("After Suite"); | ||
} | ||
|
||
@BeforeTest | ||
public void beforeTest() { | ||
System.out.println("Before Test"); | ||
} | ||
|
||
@AfterTest | ||
public void afterTest() { | ||
System.out.println("After Test"); | ||
} | ||
|
||
@BeforeClass | ||
public void beforeClass() { | ||
System.out.println("Before Class"); | ||
} | ||
|
||
@AfterClass | ||
public void afterClass() { | ||
System.out.println("After Class"); | ||
} | ||
|
||
@BeforeGroups(groups = { "testOne" }) | ||
public void beforeGroupOne() { | ||
System.out.println("Before Group testOne"); | ||
} | ||
|
||
@AfterGroups(groups = { "testOne" }) | ||
public void afterGroupOne() { | ||
System.out.println("After Group testOne"); | ||
} | ||
|
||
@BeforeGroups(groups = { "testTwo" }) | ||
public void beforeGroupTwo() { | ||
System.out.println("Before Group testTwo"); | ||
} | ||
|
||
@AfterGroups(groups = { "testTwo" }) | ||
public void afterGroupTwo() { | ||
System.out.println("After Group testTwo"); | ||
} | ||
|
||
@BeforeMethod | ||
public void beforeMethod() { | ||
System.out.println("Before Method"); | ||
} | ||
|
||
@AfterMethod | ||
public void afterMethod() { | ||
System.out.println("After Method"); | ||
} | ||
|
||
@Test(groups = { "testOne" }) | ||
public void testOneMethod() { | ||
System.out.println("Test method 1"); | ||
} | ||
|
||
@Test(groups = { "testTwo" }) | ||
public void testTwoMethod() { | ||
System.out.println("Test method 2"); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
src/test/java/com/anhtester/Bai14_Annotation/DemoRunTestXML_01.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,81 @@ | ||
package com.anhtester.Bai14_Annotation; | ||
|
||
import com.anhtester.common.BaseTest; | ||
import com.anhtester.globals.ConfigsGlobal; | ||
import com.anhtester.globals.TokenGlobal; | ||
import com.anhtester.helpers.JsonHelper; | ||
import com.anhtester.model.LoginPOJO; | ||
import com.anhtester.model.data.LoginPOJO_Builder; | ||
import com.google.gson.Gson; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.path.json.JsonPath; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
import net.datafaker.Faker; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.util.Locale; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class DemoRunTestXML_01 extends BaseTest { | ||
|
||
@BeforeClass | ||
public void beforeClass1(){ | ||
System.out.println("This is before class CON1"); | ||
} | ||
|
||
public static int CATEGORY_ID; | ||
public static String CATEGORY_NAME; | ||
|
||
@Test(priority = 1) | ||
public void testAddNewCategory() { | ||
System.out.println("Create Category"); | ||
String dataFile = "src/test/resources/testdata/CreateCategory.json"; | ||
|
||
Faker faker = new Faker(new Locale("vi")); | ||
CATEGORY_NAME = faker.job().title(); | ||
System.out.println("CATEGORY_NAME: " + CATEGORY_NAME); | ||
|
||
JsonHelper.updateValueJsonFile(dataFile, "name", CATEGORY_NAME); | ||
|
||
RequestSpecification request = given(); | ||
request.baseUri("https://api.anhtester.com/api") | ||
.accept(ContentType.JSON) | ||
.contentType(ContentType.JSON) | ||
.header("Authorization", "Bearer " + TokenGlobal.TOKEN) | ||
.body(new File(dataFile)); | ||
|
||
Response response = request.post("/category"); | ||
|
||
response.prettyPrint(); | ||
response.then().statusCode(200); | ||
|
||
CATEGORY_ID = Integer.parseInt(response.path("response.id").toString()); | ||
System.out.println("CATEGORY_ID: " + CATEGORY_ID); | ||
} | ||
|
||
@Test(priority = 2) | ||
public void testGetCategoryById() { | ||
System.out.println("Get Category By Id"); | ||
|
||
RequestSpecification request = given(); | ||
request.baseUri("https://api.anhtester.com/api") | ||
.accept(ContentType.JSON) | ||
.contentType(ContentType.JSON) | ||
.header("Authorization", "Bearer " + TokenGlobal.TOKEN); | ||
|
||
System.out.println("CATEGORY_ID: " + CATEGORY_ID); | ||
Response response = request.get("/category/" + CATEGORY_ID); | ||
|
||
response.prettyPrint(); | ||
response.then().statusCode(200); | ||
|
||
JsonPath jsonPath = response.jsonPath(); | ||
Assert.assertEquals(jsonPath.get("response.name"), CATEGORY_NAME, "Category name not match."); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/com/anhtester/Bai14_Annotation/DemoRunTestXML_02.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,60 @@ | ||
package com.anhtester.Bai14_Annotation; | ||
|
||
import com.anhtester.common.BaseTest; | ||
import com.anhtester.globals.ConfigsGlobal; | ||
import com.anhtester.globals.TokenGlobal; | ||
import com.anhtester.model.BookPOJO; | ||
import com.google.gson.Gson; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
import net.datafaker.Faker; | ||
import org.joda.time.LocalDateTime; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Locale; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public class DemoRunTestXML_02 extends BaseTest { | ||
|
||
@BeforeClass | ||
public void beforeClass2(){ | ||
System.out.println("This is before class CON2"); | ||
} | ||
|
||
@Test | ||
public void testAddNewBook() { | ||
|
||
Faker faker = new Faker(new Locale("vi")); | ||
String BOOK_NAME = faker.book().title() + "_" + LocalDateTime.now(); | ||
|
||
BookPOJO bookPOJO = new BookPOJO(); | ||
|
||
bookPOJO.setName(BOOK_NAME); | ||
bookPOJO.setCategory_id(DemoRunTestXML_01.CATEGORY_ID); | ||
bookPOJO.setPrice(120000); | ||
bookPOJO.setRelease_date("2024-01-27"); | ||
bookPOJO.setStatus(true); | ||
|
||
bookPOJO.setImage_ids(new ArrayList<>(Arrays.asList(2, 18, 19))); | ||
|
||
Gson gson = new Gson(); | ||
|
||
RequestSpecification request = given(); | ||
request.baseUri(ConfigsGlobal.URI) | ||
.accept(ContentType.JSON) | ||
.contentType(ContentType.JSON) | ||
.header("Authorization", "Bearer " + TokenGlobal.TOKEN) | ||
.body(gson.toJson(bookPOJO)); | ||
|
||
Response response = request.post("book"); | ||
response.prettyPrint(); | ||
|
||
response.then().statusCode(200); | ||
|
||
} | ||
} |
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
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 +1 @@ | ||
{"name":"Global Education Orchestrator"} | ||
{"name":"Internal Hospitality Designer"} |
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,10 @@ | ||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > | ||
|
||
<suite name="SuiteRunAnnotation" verbose="1"> | ||
<test name="FirstTest"> | ||
<classes> | ||
<class name="com.anhtester.Bai14_Annotation.DemoRunTestXML_01"/> | ||
<class name="com.anhtester.Bai14_Annotation.DemoRunTestXML_02"/> | ||
</classes> | ||
</test> | ||
</suite> |
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,10 @@ | ||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > | ||
|
||
<suite name="SuiteRunTest" verbose="1"> | ||
<test name="FirstTest"> | ||
<classes> | ||
<class name="com.anhtester.Bai14_Annotation.DemoRunTestXML_01"/> | ||
<class name="com.anhtester.Bai14_Annotation.DemoRunTestXML_02"/> | ||
</classes> | ||
</test> | ||
</suite> |