From 20473d8493be710a5b1a924b161688fca4327afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pol=20Escol=C3=A0=20Curc=C3=B3?= Date: Fri, 7 Jun 2024 13:50:01 +0200 Subject: [PATCH 1/2] added new volunteer --- .../demo/config/DBInitialization.java | 73 +++++++++++-------- 1 file changed, 44 insertions(+), 29 deletions(-) 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 3fca76d..c600827 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 @@ -81,38 +81,53 @@ public void initializeDatabase() { shelter.setActive(true); shelterRepository.save(shelter); - if (!shelterVolunteerRepository.existsById("volunteer")) { - ShelterVolunteer volunteer = new ShelterVolunteer(); - volunteer.setEmail("volunteer@dbsample.app"); - volunteer.setId("volunteer"); - volunteer.setPassword(defaultPassword); - volunteer.encodePassword(); - volunteer.setUserShelter(shelter); - shelterVolunteerRepository.save(volunteer); - } - if (!shelterVolunteerRepository.existsById("volunteer1")) { - ShelterVolunteer volunteer = new ShelterVolunteer(); - volunteer.setEmail("volunteer1@dbsample.app"); - volunteer.setId("volunteer1"); - volunteer.setPassword(defaultPassword); - volunteer.setUserShelter(shelter); - volunteer.encodePassword(); - shelterVolunteerRepository.save(volunteer); - } - - if (!shelterVolunteerRepository.existsById("volunteer2")) { - ShelterVolunteer volunteer = new ShelterVolunteer(); - volunteer.setEmail("volunteer2@dbsample.app"); - volunteer.setId("volunteer2"); - volunteer.setPassword(defaultPassword); - volunteer.setUserShelter(shelter); - volunteer.encodePassword(); - shelterVolunteerRepository.save(volunteer); - } + if (!shelterVolunteerRepository.existsById("volunteer")) { + ShelterVolunteer volunteer = new ShelterVolunteer(); + volunteer.setEmail("volunteer@dbsample.app"); + volunteer.setId("volunteer"); + volunteer.setPassword(defaultPassword); + volunteer.encodePassword(); + volunteer.setUserShelter(shelter); + shelterVolunteerRepository.save(volunteer); + } + if (!shelterVolunteerRepository.existsById("volunteer1")) { + ShelterVolunteer volunteer = new ShelterVolunteer(); + volunteer.setEmail("volunteer1@dbsample.app"); + volunteer.setId("volunteer1"); + volunteer.setPassword(defaultPassword); + volunteer.setUserShelter(shelter); + volunteer.encodePassword(); + shelterVolunteerRepository.save(volunteer); + } + if (!shelterVolunteerRepository.existsById("volunteer2")) { + ShelterVolunteer volunteer = new ShelterVolunteer(); + volunteer.setEmail("volunteer2@dbsample.app"); + volunteer.setId("volunteer2"); + volunteer.setPassword(defaultPassword); + volunteer.setUserShelter(shelter); + volunteer.encodePassword(); + shelterVolunteerRepository.save(volunteer); + } + } + if(shelterRepository.findByEmail("shelter2@dbsample.app").isEmpty()) { + Shelter shelter = new Shelter(); + shelter.setName("shelter2"); + shelter.setEmail("shelter2@dbsample.app"); + shelter.setMobile("420420422"); + shelter.setActive(true); + shelterRepository.save(shelter); + if (!shelterVolunteerRepository.existsById("volunteer3")) { + ShelterVolunteer volunteer = new ShelterVolunteer(); + volunteer.setEmail("volunteer3@dbsample.app"); + volunteer.setId("volunteer3"); + volunteer.setPassword(defaultPassword); + volunteer.setUserShelter(shelter); + volunteer.encodePassword(); + shelterVolunteerRepository.save(volunteer); + } } - if (Arrays.asList(activeProfiles.split(",")).contains("test")) { // Testing instances From 42a188da82c5d8837d318fa8f4dbd245920abab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pol=20Escol=C3=A0=20Curc=C3=B3?= Date: Fri, 7 Jun 2024 13:56:14 +0200 Subject: [PATCH 2/2] test changed for new shelter --- .../cat/udl/eps/softarch/demo/steps/CreateShelterStepDefs.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/cat/udl/eps/softarch/demo/steps/CreateShelterStepDefs.java b/src/test/java/cat/udl/eps/softarch/demo/steps/CreateShelterStepDefs.java index 20d7c82..611734f 100644 --- a/src/test/java/cat/udl/eps/softarch/demo/steps/CreateShelterStepDefs.java +++ b/src/test/java/cat/udl/eps/softarch/demo/steps/CreateShelterStepDefs.java @@ -78,7 +78,8 @@ public void thereIsShelterCreated(int sheltersCreatedNum) { sheltersCreatedNum++; if(!shelterRepository.findByEmail("shelter1@dbsample.app").isEmpty()) sheltersCreatedNum++; - + if(!shelterRepository.findByEmail("shelter2@dbsample.app").isEmpty()) + sheltersCreatedNum++; Assert.assertEquals("Shelters created", sheltersCreatedNum, shelterRepository.count()); }