Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/test/java/feature/SpringIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ protected void executeDelete(String path) {
String url = "http://localhost:" + port + path;
latestResponse = restTemplate.exchange(url, HttpMethod.DELETE, HttpEntity.EMPTY, String.class);
}

protected void executePut(String path, Object payload) {
String url = "http://localhost:" + port + path;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
latestResponse = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
}
}
25 changes: 25 additions & 0 deletions src/test/java/feature/StepDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ public void theClientCallToDeleteTheCreatedUser() {
executeDelete("/random-users/" + createdUserId);
}

@Given("a valid user payload for update")
public void aValidUserPayloadForUpdate() {
payload = new UserRequest(
"male",
"John",
"Doe",
"Mr",
"john.doe@example.com",
"0611111111",
"john.jpg",
"US"
);
}

@When("the client call to PUT the created user")
public void theClientCallToPutTheCreatedUser() {
assertNotNull(createdUserId, "No user was created before this step");
executePut("/random-users/" + createdUserId, payload);
}

@When("the client call to PUT \\/random-users\\/{int}")
public void theClientCallToPutRandomUser(int id) {
executePut("/random-users/" + id, payload);
}

@And("the response contains a list of users")
public void theResponseContainsAListOfUsers() throws Exception {
JsonNode body = objectMapper.readTree(latestResponse.getBody());
Expand Down
21 changes: 21 additions & 0 deletions src/test/resources/features/update_user.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Update user endpoint

Scenario: Update a user by ID after creation
Given a valid user payload for creation
When the client call to POST /random-users
Then the response status should be 201
And the user profile
| id | <generated_id> |
| firstname | Emma |
Given a valid user payload for update
When the client call to PUT the created user
Then the response status should be 200
And the user profile
| firstname | John |
| lastname | Doe |

Scenario: Update a user that does not exist
Given a valid user payload for update
When the client call to PUT /random-users/999999
Then the response status should be 404

Loading