This repository was archived by the owner on Feb 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParkingTests.java
More file actions
83 lines (61 loc) · 3.12 KB
/
ParkingTests.java
File metadata and controls
83 lines (61 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package dev.wms.pwrapi.parking;
import io.restassured.http.ContentType;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import static io.restassured.RestAssured.*;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import static org.hamcrest.Matchers.*;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ParkingTests {
@Test
public void parkingEndpointShouldReturnValueMatchingJsonSchema(){
get("/api/parking").then().assertThat()
.body(matchesJsonSchemaInClasspath("parking/parking-schema.json"))
.statusCode(200);
}
@Test
public void parkingLeftPlacesShouldContainOnlyPositiveNumbers(){
get("api/parking").then()
.body("[0].leftPlaces", greaterThanOrEqualTo(0))
.body("[1].leftPlaces", greaterThanOrEqualTo(0))
.body("[2].leftPlaces", greaterThanOrEqualTo(0))
.body("[3].leftPlaces", greaterThanOrEqualTo(0))
.body("[4].leftPlaces", greaterThanOrEqualTo(0));
}
@Test
public void allParkingNamesShouldBeAccessible(){
get("api/parking").then()
.body("[0].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[1].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[2].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[3].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[4].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"));
}
@Test
public void responseTypeShouldBeJSON(){
get("api/parking").then()
.contentType(ContentType.JSON);
}
@Test
public void detailsEndpointShouldContainAllParkingNames(){
get("api/parking/raw").then()
.body("[0].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[1].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[2].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[3].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"))
.body("[4].name", oneOf("D20", "Parking Wrońskiego", "C13", "Geocentrum", "Architektura"));
}
@Test
public void historyEndpointShouldBeAnArrayWrappedInString(){
get("api/parking/raw").then()
.body("[0].history", getArrayMatcher())
.body("[1].history", getArrayMatcher())
.body("[2].history", getArrayMatcher())
.body("[3].history", getArrayMatcher())
.body("[4].history", getArrayMatcher());
}
private Matcher<String> getArrayMatcher(){
return allOf(startsWith("["), endsWith("]"), not(containsString("(")), not(containsString(")")));
}
}