From dfaee688ae70c21896c1e672d33db17511b07bad Mon Sep 17 00:00:00 2001 From: VictoriaGrudtsyna Date: Mon, 18 May 2026 23:32:38 +0300 Subject: [PATCH] rest-countries-tests: implement all tests --- pom.xml | 14 ++ .../java/practice/restcountries/AllTests.java | 123 ++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 src/main/java/hse/java/practice/restcountries/AllTests.java diff --git a/pom.xml b/pom.xml index de78097..6da802a 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,20 @@ 2.10.1 compile + + + io.rest-assured + rest-assured + 5.4.0 + test + + + + org.assertj + assertj-core + 3.26.3 + test + diff --git a/src/main/java/hse/java/practice/restcountries/AllTests.java b/src/main/java/hse/java/practice/restcountries/AllTests.java new file mode 100644 index 0000000..a59d321 --- /dev/null +++ b/src/main/java/hse/java/practice/restcountries/AllTests.java @@ -0,0 +1,123 @@ +package hse.java.practice.restcountries; + +import io.restassured.RestAssured; +import io.restassured.response.Response; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +public class AllTests { + + @BeforeAll + static void setupURL() { + RestAssured.baseURI = "https://restcountries.com"; + RestAssured.basePath = "/v3.1"; + } + + // GET /all --> 200, список стран не пустой + @Test + void ShouldReturnCountriesWithNamesAndFlags() { + Response response = RestAssured + .given() + .when() + .get("/all?fields=name,flags"); + + assertThat(response.statusCode()).isEqualTo(200); + + List countries = response.jsonPath().getList("$"); + + assertThat(countries) + .isNotEmpty(); + } + + //GET /name/russia --> 200, есть страна со столицей "Moscow" + @Test + void ShouldReturnRussia() { + Response response = RestAssured + .given() + .when() + .get("/name/Russia"); + + assertThat(response.statusCode()).isEqualTo(200); + + List capitals = response.jsonPath().getList("capital"); + + assertThat(capitals).contains("Moscow"); + } + + //GET /alpha/de --> 200, есть страна с name.common = "Germany" + @Test + void ShoulReturnGermany() { + Response response = RestAssured + .given() + .when() + .get("/alpha/de"); + + assertThat(response.statusCode()).isEqualTo(200); + + String name = response.jsonPath().getString("[0].name.common"); + + assertThat(name).isEqualTo("Germany"); + } + + //GET /name/nonexistentcountryxyz --> 404 + @Test + void ShouldReturn404() { + Response response = RestAssured + .given() + .when() + .get("/name/bangabangara"); + + assertThat(response.statusCode()).isEqualTo(404); + } + + // GET /all --> у каждой страны population > 0 + @Test + void CheckCountriesPopulation() { + Response response = RestAssured + .given() + .when() + .get("/all?fields=population"); + + List countriesPopulation = response.jsonPath().getList("population"); + + for (Integer elem : countriesPopulation) { + assertThat(elem).isGreaterThan(0); + } + } + + // GET /region/europe --> 200, регион у всех стран должен быть Европой + @Test + void ShouldReturnOnlyEuropeanCountries() { + + Response response = RestAssured + .given() + .when() + .get("/region/europe"); + + assertThat(response.statusCode()).isEqualTo(200); + + List regions = response.jsonPath().getList("region"); + + for (String region : regions) { + assertThat(region).isEqualTo("Europe"); + } + } + + // GET /capital/berlin --> 200, найдена страна Japan + @Test + void ShouldFindJapanByCapital() { + + Response response = RestAssured + .given() + .when() + .get("/capital/tokyo"); + + assertThat(response.statusCode()).isEqualTo(200); + + List names = response.jsonPath().getList("name.common"); + + assertThat(names).contains("Japan"); + } +} \ No newline at end of file