Skip to content

Instantly share code, notes, and snippets.

@berkdulger
Created January 27, 2022 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkdulger/82ddabe9743daa0196f32174263a279f to your computer and use it in GitHub Desktop.
Save berkdulger/82ddabe9743daa0196f32174263a279f to your computer and use it in GitHub Desktop.
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