-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23c235d
commit cc87ba7
Showing
9 changed files
with
290 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/cat/udl/eps/softarch/demo/steps/DeleteShelterStepDefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Shelter; | ||
import cat.udl.eps.softarch.demo.repository.ShelterRepository; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
public class DeleteShelterStepDefs { | ||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private ShelterRepository shelterRepository; | ||
|
||
@When("^I delete the shelter with name \"([^\"]*)\"$") | ||
public void iDeleteAShelterWithName(String name) throws Exception { | ||
Shelter shelter = shelterRepository.findByName(name); | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
delete("/shelters/{id}", (shelter != null) ? shelter.getId() : "999") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(shelter)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
|
||
@And("^The shelter with name \"([^\"]*)\" has been deleted$") | ||
public void theShelterWithNameHasBeenDeleted(String name) { | ||
Shelter shelter = shelterRepository.findByName(name); | ||
assertThat(shelter).isNull(); | ||
} | ||
|
||
@And("^The shelter with name \"([^\"]*)\" has not been deleted$") | ||
public void theShelterWithNameHasNotBeenDeleted(String name) { | ||
Shelter shelter = shelterRepository.findByName(name); | ||
assertThat(shelter).isNotNull(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/cat/udl/eps/softarch/demo/steps/GetShelterStepDefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Shelter; | ||
import cat.udl.eps.softarch.demo.repository.ShelterRepository; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
public class GetShelterStepDefs { | ||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private ShelterRepository shelterRepository; | ||
|
||
@When("^I retrieve the shelter with name \"([^\"]*)\"$") | ||
public void iRetrieveShelterWithName(String name) throws Exception { | ||
Shelter shelter = shelterRepository.findByName(name); | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
get("/shelters/{id}", (shelter != null) ? shelter.getId() : "999") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(shelter)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/cat/udl/eps/softarch/demo/steps/UpdateShelterStepDefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Shelter; | ||
import cat.udl.eps.softarch.demo.repository.ShelterRepository; | ||
import io.cucumber.datatable.DataTable; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
public class UpdateShelterStepDefs { | ||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private ShelterRepository shelterRepository; | ||
|
||
@When("^I update the shelter with name \"([^\"]*)\" and new attributes:$") | ||
public void iUpdateShelterWithName(String name, DataTable table) throws Exception { | ||
List<Map<String, String>> attributesList = table.asMaps(String.class, String.class); | ||
|
||
// Assuming only one row of attributes is provided, so taking the first map from the list | ||
Map<String, String> attributes = attributesList.get(0); | ||
|
||
// Fetch attributes from the map | ||
String email = attributes.get("email"); | ||
String mobile = attributes.get("mobile"); | ||
String isActive = attributes.get("isActive"); | ||
|
||
Shelter shelter = shelterRepository.findByName(name); | ||
if (shelter != null) { | ||
if (email != null) shelter.setEmail(email); | ||
if (mobile != null) shelter.setMobile(mobile); | ||
if (isActive != null) shelter.setActive(Boolean.parseBoolean(isActive)); | ||
shelter.setUpdatedAt(java.time.LocalDateTime.now()); | ||
} | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
patch("/shelters/{id}", (shelter != null) ? shelter.getId() : "999") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(shelter)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Feature: Delete Shelter | ||
In order to maintain shelter data | ||
As a user with appropriate permissions | ||
I want to be able to delete a shelter | ||
|
||
Background: | ||
Given There is a registered user with username "username" and password "password" and email "[email protected]" | ||
And There is a registered shelter with name "existing_shelter", email "[email protected]", mobile "+34 123 45 67 89" | ||
|
||
Scenario: Delete existing shelter | ||
Given I can login with username "username" and password "password" | ||
When I delete the shelter with name "existing_shelter" | ||
Then The response code is 200 | ||
And The shelter with name "existing_shelter" has been deleted | ||
|
||
Scenario: Delete shelter when I am not logged in | ||
Given I'm not logged in | ||
When I delete the shelter with name "existing_shelter" | ||
Then The response code is 401 | ||
And The shelter with name "existing_shelter" has not been deleted | ||
|
||
Scenario: Delete non-existent shelter | ||
Given I can login with username "username" and password "password" | ||
When I delete the shelter with name "non_existent_shelter" | ||
Then The response code is 404 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: Get Shelter | ||
In order to retrieve shelter information | ||
As a user with appropriate permissions | ||
I want to be able to get shelter details | ||
|
||
Background: | ||
Given There is a registered user with username "username" and password "password" and email "[email protected]" | ||
|
||
Scenario: Get existing shelter details | ||
Given I can login with username "username" and password "password" | ||
And There is a registered shelter with name "existing_shelter", email "[email protected]", mobile "+34 123 45 67 89" | ||
When I retrieve the shelter with name "existing_shelter" | ||
Then The response code is 200 | ||
|
||
Scenario: Get non-existent shelter details | ||
Given I can login with username "username" and password "password" | ||
When I retrieve the shelter with name "non_existent_shelter" | ||
Then The response code is 404 | ||
|
||
Scenario: Get shelter details when I am not logged in | ||
Given I'm not logged in | ||
When I retrieve the shelter with name "existing_shelter" | ||
Then The response code is 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,64 +3,78 @@ Feature: Register Shelter | |
As a user | ||
I want to register a Shelter | ||
|
||
Scenario: Register existing shelter name | ||
Given There is a registered shelter with name "existing_shelter", email "[email protected]", mobile "+34 123 45 67 89" and isActive True | ||
# And I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "existing_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Background: | ||
Given There is a registered user with username "username" and password "password" and email "[email protected]" | ||
|
||
Scenario: Register existing shelter email | ||
Given I can login with username "username" and password "password" | ||
# And I am a user with role "ShelterVolunteer" | ||
Given There is a registered shelter with name "existing_shelter", email "[email protected]", mobile "+34 123 45 67 89" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 409 | ||
And It has not been created a shelter with name "existing_shelter" | ||
|
||
Scenario: Register shelter when already authenticated | ||
Given I am logged in as "ShelterAdmin" with email "[email protected]" and password "adminpassword" | ||
Scenario: Register shelter with no permission | ||
Given I can login with username "username" and password "password" | ||
# And I am a user with role "User" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 403 | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with empty name | ||
Given I am a user with role "ShelterVolunteer" | ||
Given I can login with username "username" and password "password" | ||
# Given I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
And It has not been created a shelter with name "" | ||
|
||
Scenario: Register shelter with empty email | ||
Given I am a user with role "ShelterVolunteer" | ||
Given I can login with username "username" and password "password" | ||
# Given I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "new_shelter", email "", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with invalid email | ||
Given I am a user with role "ShelterVolunteer" | ||
Given I can login with username "username" and password "password" | ||
# Given I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "new_shelter", email "invalid_email", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 400 | ||
And The error message is "must be a well-formed email address" | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with empty mobile | ||
Given I am a user with role "ShelterVolunteer" | ||
Given I can login with username "username" and password "password" | ||
# Given I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "" and isActive True | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with invalid mobile format | ||
Given I am a user with role "ShelterVolunteer" | ||
Given I can login with username "username" and password "password" | ||
# Given I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "invalid_mobile" and isActive True | ||
Then The response code is 400 | ||
And The error message is "must be a valid mobile number" | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with non-boolean isActive | ||
Given I am a user with role "ShelterVolunteer" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive "active" | ||
Then The response code is 400 | ||
And The error message is "must be a boolean value" | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with existing email | ||
Given There is a registered shelter with name "existing_shelter", email "[email protected]", mobile "+34 123 45 67 89", and isActive True | ||
And I am a user with role "ShelterVolunteer" | ||
Given I can login with username "username" and password "password" | ||
# And I am a user with role "ShelterVolunteer" | ||
Given There is a registered shelter with name "existing_shelter", email "[email protected]", mobile "+34 123 45 67 89" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 409 | ||
And I can login with email "[email protected]" and password "existing_password" | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter when I am not logged in | ||
Given I'm not logged in | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 401 | ||
And It has not been created a shelter with name "new_shelter" | ||
|
||
Scenario: Register shelter with valid attributes | ||
Given I can login with username "username" and password "password" | ||
When I register a new shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56" and isActive True | ||
Then The response code is 201 | ||
And It has been created a shelter with name "new_shelter", email "[email protected]", mobile "+34 567 56 56 56", the isActive is not returned |
Oops, something went wrong.