fix: 1
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package zacksolutions;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package api.endpoints;
|
||||
|
||||
public class Routes {
|
||||
public static String BASE_URL = "https://petstore.swagger.io/v2/";
|
||||
public static String POST_URL = BASE_URL + "user/";
|
||||
public static String GET_URL = BASE_URL + "user/{username}";
|
||||
public static String UPDATE_URL = BASE_URL + "user/{username}";
|
||||
public static String DELETE_URL = BASE_URL + "user/{username}";
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package api.endpoints;
|
||||
|
||||
import api.payload.User;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
public class UserEndpoints {
|
||||
public static Response createUser(User payload){
|
||||
Response response = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.accept(ContentType.JSON)
|
||||
.body(payload)
|
||||
.when()
|
||||
.post(Routes.POST_URL);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static Response readUser(String userName){
|
||||
Response response = given()
|
||||
.pathParam("username", userName)
|
||||
.when()
|
||||
.get(Routes.GET_URL);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static Response updateUser(String userName, User payload){
|
||||
Response response = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.accept(ContentType.JSON)
|
||||
.pathParam("usermame", userName)
|
||||
.body(payload)
|
||||
.when()
|
||||
.put(Routes.UPDATE_URL);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static Response deleteUser(String userName){
|
||||
Response response = given()
|
||||
.pathParam("username", userName)
|
||||
.when()
|
||||
.delete(Routes.DELETE_URL);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package api.payload;
|
||||
|
||||
public class User {
|
||||
int id;
|
||||
String username;
|
||||
String firstname;
|
||||
String lastname;
|
||||
String email;
|
||||
String password;
|
||||
String phone;
|
||||
int userStatus = 0;
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
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 int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package api.test;
|
||||
|
||||
import api.endpoints.UserEndpoints;
|
||||
import api.payload.User;
|
||||
import io.restassured.response.Response;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class UserTest {
|
||||
|
||||
User userPayload;
|
||||
@BeforeClass
|
||||
public void setupData(){
|
||||
userPayload = new User();
|
||||
userPayload.setId(10);
|
||||
userPayload.setUsername("snowman");
|
||||
userPayload.setFirstname("Desmond");
|
||||
userPayload.setLastname("Hume");
|
||||
userPayload.setEmail("desmondh@gamil.com");
|
||||
userPayload.setPassword("4815162342");
|
||||
userPayload.setPhone("79460893");
|
||||
}
|
||||
|
||||
@Test(priority = 1)
|
||||
public void testPostUser(){
|
||||
Response response = UserEndpoints.createUser(userPayload);
|
||||
response.then().log().all();
|
||||
|
||||
Assert.assertEquals(response.getStatusCode(), 200);
|
||||
}
|
||||
|
||||
@Test(priority = 2)
|
||||
public void testGetUser(){
|
||||
Response response = UserEndpoints.readUser(this.userPayload.getUsername());
|
||||
response.then()
|
||||
.statusCode(200).log().all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user