Skip to content

Commit 02d50f5

Browse files
committed
test(cucumber_get_post): ajout des tests sur le get
1 parent 7af3feb commit 02d50f5

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/main/java/com/xpeho/spring_boot_java_random_user/data/models/db/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@Table("users")
88
public class User {
99
@Id
10+
@Column("id")
1011
private Long id;
1112
@Column("gender")
1213
private String gender;

src/test/java/feature/SpringIntegrationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

src/test/java/feature/StepDefinition.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

0 commit comments

Comments
 (0)