|
3 | 3 | import com.fasterxml.jackson.databind.JsonNode; |
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 5 | import com.xpeho.spring_boot_java_random_user.domain.entities.UserRequest; |
| 6 | +import io.cucumber.datatable.DataTable; |
6 | 7 | import io.cucumber.java.en.And; |
7 | 8 | import io.cucumber.java.en.Given; |
8 | 9 | import io.cucumber.java.en.Then; |
9 | 10 | import io.cucumber.java.en.When; |
10 | 11 |
|
| 12 | +import java.util.List; |
| 13 | + |
11 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals; |
12 | 15 |
|
13 | 16 | public class StepDefinition extends SpringIntegrationTest { |
@@ -39,16 +42,13 @@ public void theResponseStatusShouldBe(int expectedStatus) { |
39 | 42 | assertEquals(expectedStatus, latestResponse.getStatusCode().value()); |
40 | 43 | } |
41 | 44 |
|
42 | | - @And("the response should contain the created user id {long}") |
43 | | - public void theResponseShouldContainTheCreatedUserId(long expectedId) throws Exception { |
44 | | - JsonNode body = objectMapper.readTree(latestResponse.getBody()); |
45 | | - assertEquals(expectedId, body.get("id").asLong()); |
46 | | - } |
47 | | - |
48 | | - @And("the response should contain the firstname {string}") |
49 | | - public void theResponseShouldContainTheFirstname(String expectedFirstname) throws Exception { |
| 45 | + @And("the user profile") |
| 46 | + public void theUserProfile(DataTable table) throws Exception{ |
50 | 47 | JsonNode body = objectMapper.readTree(latestResponse.getBody()); |
51 | | - assertEquals(expectedFirstname, body.get("firstname").asText()); |
| 48 | + List<List<String>> rows = table.asLists(String.class); |
| 49 | + for (List<String> row : rows) { |
| 50 | + assertEquals(row.get(1), body.get(row.get(0)).asText()); |
| 51 | + } |
52 | 52 | } |
53 | 53 |
|
54 | 54 | @When("the client call to GET \\/random-users\\/{int}") |
|
0 commit comments