day 8: Chaining and TestNG
This commit is contained in:
parent
fc3dfdfd48
commit
f34444eac4
32
src/test/java/zacksolutions/DayEight/CreateUserTest.java
Normal file
32
src/test/java/zacksolutions/DayEight/CreateUserTest.java
Normal file
@ -0,0 +1,32 @@
|
||||
package zacksolutions.DayEight;
|
||||
|
||||
import static io.restassured.RestAssured.*;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* CreateUserTest
|
||||
*/
|
||||
public class CreateUserTest {
|
||||
|
||||
@Test
|
||||
void createUser(ITestContext context) {
|
||||
|
||||
String bearerToken = "2fjksdc32opcmlpqweldien324fwefwnklploqpiwuioennxmhjgasdfe";
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("name", "Zakaria");
|
||||
data.put("gender", "male");
|
||||
data.put("email", "zakaria@gmail.com");
|
||||
data.put("status", "active");
|
||||
|
||||
int id = given().header("Authorization", "Bearer " + bearerToken).contentType("Application/json")
|
||||
.body(data.toString())
|
||||
.when()
|
||||
.post("https://foobar.com/public/v2/users/")
|
||||
.jsonPath().getInt("id");
|
||||
|
||||
context.getSuite().setAttribute("user_ID", id);
|
||||
}
|
||||
}
|
||||
27
src/test/java/zacksolutions/DayEight/DeleteUserTest.java
Normal file
27
src/test/java/zacksolutions/DayEight/DeleteUserTest.java
Normal file
@ -0,0 +1,27 @@
|
||||
package zacksolutions.DayEight;
|
||||
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.Test;
|
||||
import static io.restassured.RestAssured.*;
|
||||
|
||||
/**
|
||||
* DeleteUserTest
|
||||
*/
|
||||
public class DeleteUserTest {
|
||||
@Test
|
||||
void delete_User(ITestContext context) {
|
||||
|
||||
int id = (Integer) context.getSuite().getAttribute("user_id");
|
||||
|
||||
String bearerToken = "2fjksdc32opcmlpqweldien324fwefwnklploqpiwuioennxmhjgasdfe";
|
||||
|
||||
given()
|
||||
.header("Authorization", "Bearer " + bearerToken)
|
||||
.pathParam("id", id)
|
||||
.when()
|
||||
.delete("https://foobar.com/public/v2/users/{id}")
|
||||
.then().statusCode(204)
|
||||
.log().all();
|
||||
}
|
||||
|
||||
}
|
||||
28
src/test/java/zacksolutions/DayEight/GetUserTest.java
Normal file
28
src/test/java/zacksolutions/DayEight/GetUserTest.java
Normal file
@ -0,0 +1,28 @@
|
||||
package zacksolutions.DayEight;
|
||||
|
||||
import static io.restassured.RestAssured.*;
|
||||
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* GetUserTest
|
||||
*/
|
||||
public class GetUserTest {
|
||||
|
||||
@Test
|
||||
void get_User(ITestContext context) {
|
||||
|
||||
int id = (Integer) context.getSuite().getAttribute("user_id");
|
||||
String bearerToken = "2fjksdc32opcmlpqweldien324fwefwnklploqpiwuioennxmhjgasdfe";
|
||||
|
||||
given()
|
||||
.header("Authorizartion", "Bearer " + bearerToken)
|
||||
.pathParam("id", id)
|
||||
.when()
|
||||
.get("https://foobar.com.public/v2/users/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.log().all();
|
||||
}
|
||||
}
|
||||
36
src/test/java/zacksolutions/DayEight/UpdateUserTest.java
Normal file
36
src/test/java/zacksolutions/DayEight/UpdateUserTest.java
Normal file
@ -0,0 +1,36 @@
|
||||
package zacksolutions.DayEight;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
/**
|
||||
* UpdateUserTest
|
||||
*/
|
||||
public class UpdateUserTest {
|
||||
|
||||
@Test
|
||||
void update_User(ITestContext context) {
|
||||
int id = (Integer) context.getSuite().getAttribute("user_id");
|
||||
|
||||
String bearerToken = "2fjksdc32opcmlpqweldien324fwefwnklploqpiwuioennxmhjgasdfe";
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("name", "Zakaria");
|
||||
data.put("gender", "male");
|
||||
data.put("email", "zakaria@gmail.com");
|
||||
data.put("status", "Superactive");
|
||||
|
||||
given()
|
||||
.header("Authorization", "Bearer " + bearerToken)
|
||||
.contentType("Application/json")
|
||||
.body(data.toString())
|
||||
.pathParam("id", id)
|
||||
.when()
|
||||
.put("https://foobar.com/public/v2/users/{id}")
|
||||
.then().statusCode(200)
|
||||
.log().all();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user