Compare commits
7 Commits
0ad17563e3
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 69574c2966 | |||
| 799e3fa587 | |||
| 40137d11a8 | |||
| f34444eac4 | |||
| fc3dfdfd48 | |||
| 20ea80437b | |||
| e93f401684 |
@@ -6,11 +6,8 @@
|
|||||||
<artifactId>restAssured</artifactId>
|
<artifactId>restAssured</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>restAssured</name>
|
<name>restAssured</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
||||||
|
<suite name="AuthenticationTests">
|
||||||
|
<test name="AuthenticationTestSuite">
|
||||||
|
<classes>
|
||||||
|
<class name="zacksolutions.DayEight.CreateUserTest"/>
|
||||||
|
<class name="zacksolutions.DayEight.GetUserTest"/>
|
||||||
|
<class name="zacksolutions.DayEight.UpdateUserTest"/>
|
||||||
|
<class name="zacksolutions.DayEight.DeleteUserTest"/>
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
|
</suite>
|
||||||
@@ -70,4 +70,23 @@ public class AuthenticationTest {
|
|||||||
.get("https://api.github.com/user/repos")
|
.get("https://api.github.com/user/repos")
|
||||||
.then().statusCode(200).log().all();
|
.then().statusCode(200).log().all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(priority = 7)
|
||||||
|
void testAPIKeyAuth() {
|
||||||
|
|
||||||
|
/* THIS METHOD 1
|
||||||
|
given().queryParam("appid", "53f8437943998c07789a6693aec69607")
|
||||||
|
.when().get("https://api.openweathermap.org/data/2.5/weather?q=New York&appid=53f8437943998c07789a6693aec69607")
|
||||||
|
.then().statusCode(200).log().all();
|
||||||
|
*/
|
||||||
|
//METHOD 2
|
||||||
|
given()
|
||||||
|
.pathParam("myPath", "data/2.5/weather")
|
||||||
|
.queryParam("q", "New York")
|
||||||
|
.queryParam("appid", "53f8437943998c07789a6693aec69607")
|
||||||
|
.when()
|
||||||
|
.get("https://api.openweathermap.org/{myPath}")
|
||||||
|
.then().statusCode(200).log().all();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
|
||||||
<suite name="All Test Suite" >
|
|
||||||
<test name="RestAssured">
|
|
||||||
<classes>
|
|
||||||
<class name="zacksolutions.DayOne.HttpRequestTest"/>
|
|
||||||
<class name="zacksolutions.DayTwo.PostReqBodyTest"/>
|
|
||||||
<class name="zacksolutions.DayThree.CookiesDemoTest"/>
|
|
||||||
<class name="zacksolutions.DayThree.PathandQuerryParTest"/>
|
|
||||||
</classes>
|
|
||||||
</test>
|
|
||||||
</suite>
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user