diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index afef96b..d387a84 100644 --- a/pom.xml +++ b/pom.xml @@ -20,5 +20,17 @@ rest-assured 5.4.0 + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + org.hamcrest + hamcrest + 2.2 + test + \ No newline at end of file diff --git a/src/test/java/org/example/CardsTest.java b/src/test/java/org/example/CardsTest.java new file mode 100644 index 0000000..1456e78 --- /dev/null +++ b/src/test/java/org/example/CardsTest.java @@ -0,0 +1,39 @@ +package org.example; + +import io.restassured.RestAssured; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; + +public class CardsTest { + + @BeforeAll + public static void testSetup() { + RestAssured.baseURI = "https://api.magicthegathering.io/v1/cards"; + } + + @Test + public void getAllCardsShouldReturnOneHundredElements(){ + when().get().then().statusCode(200).header("Count", equalTo("100")); + } + + @Test + public void getCardsWithInvalidIDShouldReturnErrorNotFound(){ + given().pathParam("id", 0).get("/{id}").then().statusCode(404); + } + + @Test + public void getCardsWithSpecificIDShouldReturnCorrectData(){ + Map expectedNames = Map.of( + 1, "Ankh of Mishra", + 2, "Basalt Monolith", + 3, "Black Lotus"); + expectedNames.keySet().forEach(id -> given().pathParam("id", id).get("/{id}").then().body("card.name", equalTo(expectedNames.get(id)))); + } + +}