Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/test/java/feature/SpringIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ protected void executePost(String path, Object payload) {
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
latestResponse = restTemplate.postForEntity(url, request, String.class);
}

protected void executeDelete(String path) {
String url = "http://localhost:" + port + path;
restTemplate.delete(url);
latestResponse = ResponseEntity.noContent().build();
}
}
18 changes: 18 additions & 0 deletions src/test/java/feature/StepDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,22 @@ public void theClientCallToGetTheCreatedUser() {
assertNotNull(createdUserId, "No user was created before this step");
executeGet("/random-users/" + createdUserId);
}

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

@When("the client call to DELETE /random-users/{int}")
public void theClientCallToDeleteRandomUser(int id) {
executeDelete("/random-users/" + id);
}

@When("the client call to GET the deleted user")
public void theClientCallToGetTheDeletedUser() {
assertNotNull(createdUserId, "No user was created before this step");
String deletedUserPath = String.format("/random-users/%s", createdUserId);
executeGet(deletedUserPath);
}
}
17 changes: 17 additions & 0 deletions src/test/resources/features/delete_user.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Delete user endpoint

Scenario: Delete a user successfully 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 |
When the client call to DELETE the created user
Then the response status should be 204
When the client call to GET the deleted user
Then the response status should be 404

Scenario: Delete a user that does not exist
When the client call to DELETE /random-users/999
Then the response status should be 404
Loading