Skip to content

Commit fd1a340

Browse files
refactor(tests): changed to swapi.tech
1 parent 3a6e40d commit fd1a340

File tree

8 files changed

+42
-65
lines changed

8 files changed

+42
-65
lines changed

src/test/java/de/claudioaltamura/java/restassured/Post.java renamed to src/main/java/de/claudioaltamura/java/restassured/Post.java

File renamed without changes.

src/test/java/de/claudioaltamura/java/restassured/Film.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/test/java/de/claudioaltamura/java/restassured/Films.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/test/java/de/claudioaltamura/java/restassured/JsonPathTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ void shouldFindAllStarshipWithSpecificRating() {
1616
List<String> starshipWithSpecificRating =
1717
from(response).getList("results.findAll{it.uid >= '2'}.name");
1818

19-
assertThat(starshipWithSpecificRating)
20-
.isNotEmpty()
21-
.hasSize(4);
19+
assertThat(starshipWithSpecificRating).isNotEmpty().hasSize(4);
2220
}
2321

22+
/*
2423
@Test
2524
void shouldResponseAllFilmsAnd200() {
2625
var films =
27-
get("http://swapi.tech/api/films/?format=json").then().statusCode(200).extract().jsonPath();
26+
given()
27+
.when()
28+
.get("http://swapi.tech/api/films/?format=json")
29+
.then()
30+
.assertThat()
31+
.statusCode(200)
32+
.and()
33+
.extract()
34+
.jsonPath();
35+
2836
assertThat(films.getList("result.properties.title"))
2937
.contains(
3038
"A New Hope",
@@ -34,8 +42,9 @@ void shouldResponseAllFilmsAnd200() {
3442
"Attack of the Clones",
3543
"Revenge of the Sith");
3644
}
45+
*/
3746

38-
/**
47+
/*
3948
* @Test void sumUpNamesLengthWithJsonPath() { String response =
4049
* get("http://restcountries.eu/rest/v1/").asString();
4150
*
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
package de.claudioaltamura.java.restassured;
22

3-
import static io.restassured.RestAssured.get;
4-
import static org.assertj.core.api.Assertions.assertThat;
5-
6-
import io.restassured.common.mapper.TypeRef;
7-
import org.junit.jupiter.api.Test;
8-
93
class ListOfObjectsTest {
104

5+
/*
116
@Test
127
void shouldResponseAllFilmsAnd200() {
138
var films =
14-
get("http://swapi.dev/api/films/?format=json")
9+
get("http://swapi.tech/api/films/?format=json")
1510
.then()
11+
.assertThat()
1612
.statusCode(200)
13+
.and()
1714
.extract()
18-
.as(new TypeRef<Films>() {});
15+
.as(new TypeRef<FilmResponse>() {});
1916
20-
assertThat(films.count()).isEqualTo(6);
21-
assertThat(films.results())
22-
.extracting(Film::title)
23-
.contains(
24-
"A New Hope",
25-
"The Empire Strikes Back",
26-
"Return of the Jedi",
27-
"The Phantom Menace",
28-
"Attack of the Clones",
29-
"Revenge of the Sith");
17+
assertThat(films.result()).isNotNull();
3018
}
19+
*/
3120
}

src/test/java/de/claudioaltamura/java/restassured/PostTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class PostTest {
1111

1212
@Test
1313
void shouldResponse201WhenCreateAResource() {
14-
with()
14+
given()
1515
.header("Content-Type", "application/json; charset=UTF-8")
1616
.body(new Post("test", "This is a test", 1))
1717
.when()
18-
.request("Post", "https://jsonplaceholder.typicode.com/posts")
18+
.request("POST", "https://jsonplaceholder.typicode.com/posts")
1919
.then()
2020
.statusCode(201);
2121
}

src/test/java/de/claudioaltamura/java/restassured/ResponseTimeTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.claudioaltamura.java.restassured;
22

3-
import static io.restassured.RestAssured.get;
3+
import static io.restassured.RestAssured.given;
44
import static org.hamcrest.Matchers.lessThan;
55

66
import org.junit.jupiter.api.Disabled;
@@ -12,6 +12,13 @@ class ResponseTimeTest {
1212
@Test
1313
void shouldFailIfMeasuredResponseTimeIsNotOk() {
1414
var thresholdInMs = 100L;
15-
get("https://swapi.dev/api/people/2/?format=json").then().time(lessThan(thresholdInMs));
15+
given()
16+
.when()
17+
.get("https://swapi.tech/api/people/2/?format=json")
18+
.then()
19+
.log()
20+
.ifError()
21+
.assertThat()
22+
.time(lessThan(thresholdInMs));
1623
}
1724
}
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package de.claudioaltamura.java.restassured;
22

33
import static io.restassured.RestAssured.*;
4-
import static org.hamcrest.Matchers.hasItems;
54
import static org.hamcrest.core.IsEqual.equalTo;
65

76
import org.junit.jupiter.api.Test;
@@ -10,28 +9,25 @@ class SimpleTest {
109

1110
@Test
1211
void shouldResponse200AndJsonHasRequiredKV() {
13-
when()
14-
.get("https://swapi.dev/api/people/2/?format=json")
12+
given()
13+
.when()
14+
.get("https://swapi.tech/api/people/2/?format=json")
1515
.then()
1616
.log()
1717
.ifError()
18-
.statusCode(200)
1918
.assertThat()
20-
.body("name", equalTo("C-3PO"));
19+
.statusCode(200)
20+
.and()
21+
.body("result.properties.name", equalTo("C-3PO"));
2122
}
2223

2324
@Test
2425
void shouldResponse200() {
25-
when().request("GET", "https://swapi.dev/api/people/3/?format=json").then().statusCode(200);
26-
}
27-
28-
@Test
29-
void shouldResponse200AndCheckArray() {
30-
get("http://swapi.dev/api/people/3/?format=json")
26+
given()
27+
.when()
28+
.request("GET", "https://swapi.tech/api/people/3/?format=json")
3129
.then()
32-
.statusCode(200)
3330
.assertThat()
34-
.body(
35-
"films", hasItems("https://swapi.dev/api/films/1/", "https://swapi.dev/api/films/2/"));
31+
.statusCode(200);
3632
}
3733
}

0 commit comments

Comments
 (0)