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
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
<version>2.10.1</version>
<scope>compile</scope>
</dependency>

<!-- Source: https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
108 changes: 108 additions & 0 deletions src/test/java/hse/java/TestRestCountries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.example.demo;

import org.junit.jupiter.api.Test;

import io.restassured.RestAssured.*;

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

public class TestRestCountries {

@Test
void getCountryHappyPath() {
given().baseUri(
"https://restcountries.com/v3.1"
)
.when().get("/name/russia")
.then().statusCode(200)
.body(
"capital[0][0]",
equalTo("Moscow")
)
.body(
"continents[0]",
hasItem("Asia")
);
}

@Test
void getCountryWrongName() {
given().baseUri(
"https://restcountries.com/v3.1"
)
.when().get("/name/wrong-country")
.then().statusCode(404);
}

@Test
void getCountriesByCurrency() {
given().baseUri(
"https://restcountries.com/v3.1"
)
.when().get("/currency/euro")
.then().statusCode(200)
.body(
"name.common",
hasItems(
"France",
"Italy",
"Spain"
)
)
.body(
"name.common",
not(hasItem("USA"))
);
}


@Test
void canGetGermanyByAlphaCode() {
given().baseUri(

"https://restcountries.com/v3.1"

)

.when().get("/alpha/de")

.then().statusCode(200)
.body(
"name.common",
hasItem("Germany")
);
}

@Test
void listOfCountriesIsNotEmptyAndPopulationGreaterThanZero() {
given().baseUri(

"https://restcountries.com/v3.1"

)

.when().get("/all?fields=population")

.then().statusCode(200)
.body(not(empty()))
.body(
"population",
everyItem(greaterThanOrEqualTo(0))
);
}

@Test
void findSerbiaBySubregion() {
given().baseUri(
"https://restcountries.com/v3.1"
)
.when().get("/subregion/East Europe")
.then().statusCode(200)
.body(not(empty()))
.body(
"name.common", hasItem("Serbia")
);
}
}