package com.restassured;
import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.*;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.filter.log.LogDetail;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
public class RequestSpecificationEampTest {
//RequestSpecification requestSpecification;
ResponseSpecification responsespecification;
@BeforeClass
public void beforeclass(){
/*
requestSpecification=with()
.baseUri("https://api.postman.com")
.header("x-api-key","PMAK-631a2a89ef67cc30d8922311-2273650e3d64f42f372683dad1d843baf1");
*/
RequestSpecBuilder requestspecbuilder=new RequestSpecBuilder();
requestspecbuilder.setBaseUri("https://api.postman.com");
requestspecbuilder.addHeader("x-api-key","PMAK-631a2a89ef67cc30d8922311-2273650e3d64f42f372683dad1d843baf1");
requestspecbuilder.log(LogDetail.ALL);
requestSpecification=requestspecbuilder.build();
responsespecification=RestAssured.expect()
.statusCode(200)
.contentType(ContentType.JSON);
}
@Test(enabled = false)
public void validate_statuscode() {
get("/workspaces")
.then().spec(responsespecification)
.log().all();
}
@Test
public void validate_responsebody() {
Response response=get("/workspaces")
.then().spec(responsespecification)
.log().all()
.extract()
.response();
assertThat(response.path("workspaces[0].name").toString(),
equalTo("myworkspace123"));
}
/*
@Test(enabled = false)
public void validateStatusCode() {
Response response =given().spec(requestSpecification).get("/workspaces")
.then().log().all().extract()
.response();
assertThat(response.statusCode(),is(equalTo(200)));
}
@Test(enabled=false)
public void validate_responseBody() {
Response response=requestSpecification.get("/workspaces")
.then().log().all()
.extract().response();
assertThat(response.statusCode(),is(equalTo(200)));
}
@Test
public void validate_statuCode() {
Response response=given().spec(requestSpecification).get("/workspaces")
.then().log().all()
.extract().response();
assertThat(response.statusCode(),is(equalTo(200)));
assertThat(response.path("workspaces[0].name").toString(),equalTo("myworkspace123"));
assertThat(response.path("workspaces[1].name").toString(),equalTo("APITesting20221"));
}
*/
}