diff --git a/EntitiesModel.puml b/EntitiesModel.puml index 876180c..c564854 100644 --- a/EntitiesModel.puml +++ b/EntitiesModel.puml @@ -30,7 +30,7 @@ class Pet { age: String description: String breed: String - + img: String } class Shelter { diff --git a/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java b/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java index f2fd97f..cba52ed 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java +++ b/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java @@ -1,8 +1,12 @@ package cat.udl.eps.softarch.demo.config; + +import cat.udl.eps.softarch.demo.domain.ShelterVolunteer; import cat.udl.eps.softarch.demo.domain.User; import cat.udl.eps.softarch.demo.repository.UserRepository; +import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; + import jakarta.annotation.PostConstruct; import java.util.Arrays; @@ -13,9 +17,11 @@ public class DBInitialization { @Value("${spring.profiles.active:}") private String activeProfiles; private final UserRepository userRepository; + private final ShelterVolunteerRepository shelterVolunteerRepository; - public DBInitialization(UserRepository userRepository) { + public DBInitialization(UserRepository userRepository, ShelterVolunteerRepository shelterVolunteerRepository) { this.userRepository = userRepository; + this.shelterVolunteerRepository = shelterVolunteerRepository; } @PostConstruct @@ -29,6 +35,17 @@ public void initializeDatabase() { user.encodePassword(); userRepository.save(user); } + + // Default ShelterVolunteer + if (!shelterVolunteerRepository.existsById("volunteer")) { + ShelterVolunteer volunteer = new ShelterVolunteer(); + volunteer.setEmail("volunteer@sample.app"); + volunteer.setId("volunteer"); + volunteer.setPassword(defaultPassword); + volunteer.encodePassword(); + shelterVolunteerRepository.save(volunteer); + } + if (Arrays.asList(activeProfiles.split(",")).contains("test")) { // Testing instances if (!userRepository.existsById("test")) { diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java index 4d9f980..2302ee6 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java @@ -10,8 +10,7 @@ @Data public class Pet extends UriEntity { @Id - @NotNull - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; @@ -23,7 +22,7 @@ public class Pet extends UriEntity { String age; String description; String breed; - + String img; @ManyToOne public Shelter isIn; diff --git a/src/test/java/cat/udl/eps/softarch/demo/steps/ShelterVolunteerStepDefs.java b/src/test/java/cat/udl/eps/softarch/demo/steps/ShelterVolunteerStepDefs.java index 98f2e64..a89718f 100644 --- a/src/test/java/cat/udl/eps/softarch/demo/steps/ShelterVolunteerStepDefs.java +++ b/src/test/java/cat/udl/eps/softarch/demo/steps/ShelterVolunteerStepDefs.java @@ -36,6 +36,12 @@ public void thereIsAShelterVolunteerWithUsernameInTheShelter(String username, St volunteer.setPassword(password); volunteer.encodePassword(); shelterVolunteerRepository.save(volunteer); + } else { + shelterVolunteerRepository.findById(username).ifPresent(shelterVolunteer -> { + shelterVolunteer.setUserShelter(shelterRepository.findByName(shelterName).get(0)); + shelterVolunteerRepository.save(shelterVolunteer); + }); + } } diff --git a/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java b/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java index 785278e..4d39f71 100644 --- a/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java +++ b/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java @@ -15,10 +15,7 @@ import org.json.JSONObject; import org.junit.Assert; import org.springframework.beans.factory.annotation.Autowired; - -import java.time.LocalDate; import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; @@ -89,10 +86,9 @@ public void thenAdminShouldVerifyTheCertificateValidityAssociatedWithAShelterWit JSONObject jsonObject = new JSONObject(stepDefs.result.andReturn().getResponse().getContentAsString()); String shelterCertificateUri = jsonObject.getString("uri"); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"); - LocalDate shelterCertificateExpirationDate = LocalDate.parse(jsonObject.getString("expirationDate"), formatter); + ZonedDateTime shelterCertificateExpirationDate = ZonedDateTime.parse(jsonObject.getString("expirationDate")); - boolean isShelterCertificateValid = shelterCertificateExpirationDate.isAfter(LocalDate.now()); + boolean isShelterCertificateValid = shelterCertificateExpirationDate.isAfter(ZonedDateTime.now()); if (!isShelterCertificateValid) { System.out.println("The Shelter Certificate IS not valid!" + stepDefs.result); Assert.fail("The Shelter Certificate IS not valid!"); diff --git a/src/test/resources/features/AddShelterCertificate.feature b/src/test/resources/features/AddShelterCertificate.feature index cfc814b..3a7c7ed 100644 --- a/src/test/resources/features/AddShelterCertificate.feature +++ b/src/test/resources/features/AddShelterCertificate.feature @@ -5,14 +5,14 @@ Feature: Add Shelter Certificate Background: Exists a shelter with name "test" and a shelter volunteer Given A shelter with name "test" - And There is a registered user with username "volunteer" and password "123456789" and email "volunteer@mypets.com" + And There is a registered user with username "volunteer" and password "password" and email "volunteer@mypets.com" Scenario: Adding a Shelter Certificate as a Shelter Volunteer - Given I can login with username "volunteer" and password "123456789" + Given I can login with username "volunteer" and password "password" When I add a Shelter Certificate with valid expiration date to the shelter with name "test" Then The response code is 201 Scenario: Adding a Shelter Certificate as a non Shelter Volunteer Given I cannot login with username "test" and password "wrongPassword" When I add a Shelter Certificate with valid expiration date to the shelter with name "test" - Then The response code is 401 \ No newline at end of file + Then The response code is 401 diff --git a/src/test/resources/features/EditShelter.feature b/src/test/resources/features/EditShelter.feature index 8aa8cc3..4b3099d 100644 --- a/src/test/resources/features/EditShelter.feature +++ b/src/test/resources/features/EditShelter.feature @@ -6,7 +6,7 @@ Feature: Edit Shelter Background: Given There is a registered user with username "user" and password "existing" and email "user@sample.app" Given There is a registered already admin with username "admin" and password "admin" and email "admin@smaple.app" - Given There is a registered volunteer with username "volunteer" and password "volunteer" + Given There is a registered volunteer with username "volunteer" and password "password" And There is already a shelter with name "Shelter 1" email "shelter@sample.com" and mobile "999999999" Scenario: Edit shelter without being logged in @@ -28,7 +28,7 @@ Feature: Edit Shelter Then The response code is 200 Scenario: Edit shelter with volunteer - Given I login as "volunteer" with password "volunteer" + Given I login as "volunteer" with password "password" When I update the shelter with name "Shelter 1" to name "Another Shelter" email "shelter@sample.app" and mobile "123123123" And I get the shelter with name "Another Shelter" Then The response code is 200 diff --git a/src/test/resources/features/KickUserFromShelter.feature b/src/test/resources/features/KickUserFromShelter.feature index e53de1f..4e246a2 100644 --- a/src/test/resources/features/KickUserFromShelter.feature +++ b/src/test/resources/features/KickUserFromShelter.feature @@ -4,28 +4,28 @@ Feature: Kick ShelterVolunteer from Shelter I want to be able to kick a volunteer from my shelter but not able to kick volunteers from other shelters Background: - Given There is a registered user with username "user" and password "pass" and email "user@user.com" + Given There is a registered user with username "user" and password "password" and email "user@user.com" And There is already a shelter with name "shelter1" email "shelter@shelter.com" and mobile "12345678" - And There is a shelter volunteer with username "volunteer" and password "pass" in the shelter "shelter1" - And There is a shelter volunteer with username "volunteer1" and password "pass" in the shelter "shelter1" + And There is a shelter volunteer with username "volunteer" and password "password" in the shelter "shelter1" + And There is a shelter volunteer with username "volunteer1" and password "password" in the shelter "shelter1" And There is already a shelter with name "shelter2" email "shelter2@shelter.com" and mobile "12345679" - And There is a shelter volunteer with username "volunteer2" and password "pass" in the shelter "shelter2" + And There is a shelter volunteer with username "volunteer2" and password "password" in the shelter "shelter2" Scenario: Kick volunteer from shelter - Given I can login with username "volunteer" and password "pass" + Given I can login with username "volunteer" and password "password" When I kick user "volunteer1" from shelter "shelter" Then The response code is 200 - And I cannot login with username "volunteer1" and password "pass" + And I cannot login with username "volunteer1" and password "password" Scenario: Kick volunteer from shelter as user - And I can login with username "user" and password "pass" + And I can login with username "user" and password "password" When I kick user "volunteer1" from shelter "shelter" Then The response code is 403 - And I can login with username "volunteer1" and password "pass" + And I can login with username "volunteer1" and password "password" Scenario: Kick volunteer from shelter as volunteer in another shelter - Given I can login with username "volunteer" and password "pass" + Given I can login with username "volunteer" and password "password" When I kick user "volunteer2" from shelter "shelter" Then The response code is 412 - And I can login with username "volunteer2" and password "pass" + And I can login with username "volunteer2" and password "password"