File tree Expand file tree Collapse file tree
main/java/com/xpeho/spring_boot_java_random_user/data/models/db Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77@ Table ("users" )
88public class User {
99 @ Id
10+ @ Column ("id" )
1011 private Long id ;
1112 @ Column ("gender" )
1213 private String gender ;
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ public class SpringIntegrationTest {
3434
3535 protected ResponseEntity <String > latestResponse ;
3636
37+ protected void executeGet (String path ) {
38+ String url = "http://localhost:" + port + path ;
39+ latestResponse = restTemplate .getForEntity (url , String .class );
40+ }
41+
3742 protected void executePost (String path , Object payload ) {
3843 String url = "http://localhost:" + port + path ;
3944 HttpHeaders headers = new HttpHeaders ();
Original file line number Diff line number Diff line change @@ -50,4 +50,9 @@ public void theResponseShouldContainTheFirstname(String expectedFirstname) throw
5050 JsonNode body = objectMapper .readTree (latestResponse .getBody ());
5151 assertEquals (expectedFirstname , body .get ("firstname" ).asText ());
5252 }
53+
54+ @ When ("the client call to GET \\ /random-users\\ /{int}" )
55+ public void theClientCallToGetRandomUser (int id ) {
56+ executeGet ("/random-users/" + id );
57+ }
5358}
Original file line number Diff line number Diff line change 1+ Feature : Get user endpoint
2+
3+ Scenario : Get a user by ID after creation
4+ Given a valid user payload for creation
5+ When the client call to POST /random-users
6+ Then the response status should be 201
7+ When the client call to GET /random-users/1
8+ Then the response status should be 200
9+ And the response should contain the firstname "Emma"
10+
11+ Scenario : Get a user that does not exist
12+ When the client call to GET /random-users/999
13+ Then the response status should be 404
You can’t perform that action at this time.
0 commit comments