Created
October 1, 2021 13:17
-
-
Save berkdulger/8b0b8351e49eb9778e9f294c31cb9116 to your computer and use it in GitHub Desktop.
RestAssuredTest
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
package Restassured; | |
import io.restassured.RestAssured; | |
import io.restassured.response.ValidatableResponse; | |
import org.junit.Test; | |
import org.junit.experimental.categories.Category; | |
import static io.restassured.RestAssured.given; | |
import static io.restassured.config.XmlConfig.xmlConfig; | |
import static io.restassured.http.ContentType.JSON; | |
import static io.restassured.http.ContentType.XML; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.hamcrest.MatcherAssert.assertThat; | |
import static org.hamcrest.Matchers.hasSize; | |
import static org.hamcrest.xml.HasXPath.hasXPath; | |
interface IntegrationTest {} | |
public class RestAssuredTest { | |
@Test | |
@Category(IntegrationTest.class) | |
public void makeSureThatGoogleIsUp() { | |
given().when().get("http://www.google.com").then().statusCode(200); | |
} | |
@Test | |
@Category(IntegrationTest.class) | |
public void jsonEchoTest() { | |
//https://jsonplaceholder.typicode.com | |
given(). | |
when().get("https://jsonplaceholder.typicode.com/users"). | |
then().assertThat() | |
.contentType(JSON) | |
.body("username[0]",equalTo("Bret")) | |
.body("email[0]",equalTo("Sincere@april.biz")) | |
.statusCode(200); | |
} | |
@Test | |
@Category(IntegrationTest.class) | |
public void jsonSizeCheckTest() { | |
//https://jsonplaceholder.typicode.com/posts | |
ValidatableResponse response = given() | |
.when().get("https://jsonplaceholder.typicode.com/posts") | |
.then().assertThat() | |
.contentType(JSON) | |
.statusCode(200); | |
assertThat(response.extract().jsonPath().getList("$").size(), equalTo(100)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment