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.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
89 changes: 89 additions & 0 deletions src/test/java/hse/java/restcountries/RestCountriesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package hse.java.restcountries;

import io.restassured.RestAssured;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;


import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;

public class RestCountriesTest {
public static final String BASE_URL = "https://restcountries.com/v3.1";

@BeforeAll
public static void setUp() {
RestAssured.baseURI = BASE_URL;
}

@Test
public void shouldReturn200WhenFetchingAllCountries() {
given()
.when()
.get("/all")
.then()
.statusCode(200)
.body("", hasSize(greaterThan(0)));
}

@Test
public void hasCountryWithCapitalMoscow() {
given()
.when()
.get("/name/russia")
.then()
.statusCode(200)
.body("[0].capital", hasItem("Moscow"));

}

@Test
public void hasCountryWithNameGermany() {
given()
.when()
.get("/alpha/de")
.then()
.statusCode(200)
.body("[0].name.common", equalTo("Germany"));

}

@Test
public void notExistingCountry() {
given()
.when()
.get("/name/nonexistentcountryxyz")
.then()
.statusCode(404);

}

@Test
public void everyCountryShouldHavePositivePopulation() {
given()
.when()
.get("/all")
.then()
.body("population", everyItem(greaterThan(0)));
}

@Test
public void officialLanguageInFranceFrench() {
given()
.when()
.get("/name/france")
.then()
.statusCode(200)
.body("[0].languages.values()", hasItem("French"));
}

@Test
public void CanadaShouldHaveOneNeighbour() {
given()
.when()
.get("/name/canada")
.then()
.statusCode(200)
.body("[0].borders", hasSize(1));
}
}