Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
84 changes: 84 additions & 0 deletions src/test/java/hse/java/restcountries/CountryServiceTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}