diff --git a/pom.xml b/pom.xml index de78097..56681ab 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,12 @@ 2.10.1 compile + + io.rest-assured + rest-assured + 5.3.2 + test + diff --git a/src/test/java/hse/java/restcountries/CountryServiceTest.java b/src/test/java/hse/java/restcountries/CountryServiceTest.java new file mode 100644 index 0000000..a2420d3 --- /dev/null +++ b/src/test/java/hse/java/restcountries/CountryServiceTest.java @@ -0,0 +1,84 @@ +package hse.java.restcountries; + +import io.restassured.RestAssured; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.*; + +class CountryServiceTest { + + private static final String API_BASE_URL = "https://restcountries.com/v3.1"; + + @BeforeAll + static void init() { + RestAssured.baseURI = API_BASE_URL; + } + + @Test + @DisplayName("Verify that the list of all countries is not empty") + void shouldReturnNonEmptyList() { + get("/all") + .then() + .statusCode(200) + .body("$.size()", greaterThan(0)); + } + + @Test + @DisplayName("Verify that Russia has Moscow as its capital") + void checkRussiaCapital() { + given() + .pathParam("name", "russia") + .when() + .get("/name/{name}") + .then() + .statusCode(200) + .body("capital.flatten()", hasItem("Moscow")); + } + + @Test + @DisplayName("Verify country name for alpha code DE") + void checkGermanyByCode() { + get("/alpha/de") + .then() + .statusCode(200) + .body("name.common", contains("Germany")); + } + + @Test + @DisplayName("Should return 404 for non-existent country") + void testNonExistentCountry() { + get("/name/nonexistentcountryxyz") + .then() + .statusCode(404); + } + + @Test + @DisplayName("Verify that every country has a positive population") + void testPopulationValues() { + get("/all") + .then() + .body("population", everyItem(greaterThan(0))); + } + + @Test + @DisplayName("Verify that Estonia is located in Northern Europe") + void verifyEstoniaSubregion() { + get("/name/estonia") + .then() + .statusCode(200) + .body("[0].subregion", equalTo("Northern Europe")); + } + + @Test + @DisplayName("Verify that Switzerland is an independent state") + void verifySwitzerlandIndependence() { + get("/name/switzerland") + .then() + .statusCode(200) + .body("[0].independent", is(true)); + } +}