From d651933d33ba184d6a99990b9573ac4a838d1973 Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 08:20:55 -0600 Subject: [PATCH 1/7] #430 Adding storage options mocks --- .../vetlog/client/GoogleStorageWriter.java | 6 +- .../vetlog/helper/StorageOptionsHelper.java | 12 ++++ .../com/josdem/vetlog/util/UuidGenerator.java | 27 ++++---- .../client/GoogleStorageWriterTest.java | 65 +++++++++++++++++++ 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java create mode 100644 src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java diff --git a/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java b/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java index 3d69d8aa..15a4d797 100644 --- a/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java +++ b/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java @@ -21,8 +21,8 @@ import com.google.cloud.storage.BlobId; import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageOptions; import com.josdem.vetlog.exception.BusinessException; +import com.josdem.vetlog.helper.StorageOptionsHelper; import java.io.IOException; import java.io.InputStream; import javax.annotation.PostConstruct; @@ -35,11 +35,13 @@ public class GoogleStorageWriter { private final CredentialsProvider credentialsProvider; private final GcpProjectIdProvider gcpProjectIdProvider; + private final StorageOptionsHelper storageOptionsHelper; private Storage storage; @PostConstruct void setup() throws IOException { - storage = StorageOptions.newBuilder() + storage = storageOptionsHelper + .getStorageOptions() .setProjectId(gcpProjectIdProvider.getProjectId()) .setCredentials(credentialsProvider.getCredentials()) .build() diff --git a/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java b/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java new file mode 100644 index 00000000..f9fda8b6 --- /dev/null +++ b/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java @@ -0,0 +1,12 @@ +package com.josdem.vetlog.helper; + +import com.google.cloud.storage.StorageOptions; +import org.springframework.stereotype.Component; + +@Component +public class StorageOptionsHelper { + + public StorageOptions.Builder getStorageOptions() { + return StorageOptions.newBuilder(); + } +} diff --git a/src/main/java/com/josdem/vetlog/util/UuidGenerator.java b/src/main/java/com/josdem/vetlog/util/UuidGenerator.java index 72bd0f7d..e7c5fbff 100644 --- a/src/main/java/com/josdem/vetlog/util/UuidGenerator.java +++ b/src/main/java/com/josdem/vetlog/util/UuidGenerator.java @@ -1,29 +1,24 @@ /* -Copyright 2024 Jose Morales contact@josdem.io + Copyright 2024 Jose Morales contact@josdem.io -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ package com.josdem.vetlog.util; import java.util.UUID; public class UuidGenerator { - - private UuidGenerator() { - throw new IllegalStateException("Utility class"); - } - public static String generateUuid() { return UUID.randomUUID().toString(); } diff --git a/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java b/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java new file mode 100644 index 00000000..18f05ceb --- /dev/null +++ b/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java @@ -0,0 +1,65 @@ +package com.josdem.vetlog.client; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.api.gax.core.CredentialsProvider; +import com.google.auth.Credentials; +import com.google.cloud.spring.core.GcpProjectIdProvider; +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageOptions; +import com.josdem.vetlog.helper.StorageOptionsHelper; +import java.io.InputStream; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@Slf4j +class GoogleStorageWriterTest { + + private GoogleStorageWriter googleStorageWriter; + + @Mock + private CredentialsProvider credentialsProvider; + + @Mock + private GcpProjectIdProvider gcpProjectIdProvider; + + @Mock + private StorageOptionsHelper storageOptionsHelper; + + @BeforeEach + void setup() { + MockitoAnnotations.openMocks(this); + googleStorageWriter = new GoogleStorageWriter(credentialsProvider, gcpProjectIdProvider, storageOptionsHelper); + } + + @Test + @DisplayName("Should upload to bucket") + void shouldUploadToBucket(TestInfo testInfo) throws Exception { + log.info(testInfo.getDisplayName()); + var inputStream = mock(InputStream.class); + var builder = mock(StorageOptions.Builder.class); + var credentials = mock(Credentials.class); + var storage = mock(Storage.class); + var storageOptions = mock(StorageOptions.class); + + when(gcpProjectIdProvider.getProjectId()).thenReturn("projectId"); + when(credentialsProvider.getCredentials()).thenReturn(credentials); + + when(storageOptionsHelper.getStorageOptions()).thenReturn(builder); + when(builder.setProjectId("projectId")).thenReturn(builder); + when(builder.setCredentials(credentials)).thenReturn(builder); + when(builder.build()).thenReturn(storageOptions); + when(builder.build().getService()).thenReturn(storage); + + googleStorageWriter.setup(); + googleStorageWriter.uploadToBucket("bucket", "fileName", inputStream, "contentType"); + verify(inputStream).readAllBytes(); + } +} From b5bebdc94e30809c61734536c74ed11183d90bbc Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 08:29:48 -0600 Subject: [PATCH 2/7] #430 Adding negative scenario --- .../vetlog/client/GoogleStorageWriter.java | 22 +++--- .../vetlog/helper/StorageOptionsHelper.java | 16 +++++ .../client/GoogleStorageWriterTest.java | 67 ++++++++++++++++--- 3 files changed, 84 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java b/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java index 15a4d797..3565d8a6 100644 --- a/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java +++ b/src/main/java/com/josdem/vetlog/client/GoogleStorageWriter.java @@ -1,18 +1,18 @@ /* -Copyright 2024 Jose Morales contact@josdem.io + Copyright 2024 Jose Morales contact@josdem.io -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ package com.josdem.vetlog.client; diff --git a/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java b/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java index f9fda8b6..c8d7277a 100644 --- a/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java +++ b/src/main/java/com/josdem/vetlog/helper/StorageOptionsHelper.java @@ -1,3 +1,19 @@ +/* + Copyright 2024 Jose Morales contact@josdem.io + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package com.josdem.vetlog.helper; import com.google.cloud.storage.StorageOptions; diff --git a/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java b/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java index 18f05ceb..a4fb8d37 100644 --- a/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java +++ b/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java @@ -1,6 +1,22 @@ +/* + Copyright 2024 Jose Morales contact@josdem.io + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package com.josdem.vetlog.client; -import static org.mockito.Mockito.mock; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -9,7 +25,10 @@ import com.google.cloud.spring.core.GcpProjectIdProvider; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; +import com.josdem.vetlog.exception.BusinessException; import com.josdem.vetlog.helper.StorageOptionsHelper; + +import java.io.IOException; import java.io.InputStream; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; @@ -33,6 +52,21 @@ class GoogleStorageWriterTest { @Mock private StorageOptionsHelper storageOptionsHelper; + @Mock + private InputStream inputStream; + + @Mock + private Storage storage; + + @Mock + private Credentials credentials; + + @Mock + private StorageOptions storageOptions; + + @Mock + private StorageOptions.Builder builder; + @BeforeEach void setup() { MockitoAnnotations.openMocks(this); @@ -43,12 +77,29 @@ void setup() { @DisplayName("Should upload to bucket") void shouldUploadToBucket(TestInfo testInfo) throws Exception { log.info(testInfo.getDisplayName()); - var inputStream = mock(InputStream.class); - var builder = mock(StorageOptions.Builder.class); - var credentials = mock(Credentials.class); - var storage = mock(Storage.class); - var storageOptions = mock(StorageOptions.class); + setExpectations(); + + googleStorageWriter.setup(); + googleStorageWriter.uploadToBucket("bucket", "fileName", inputStream, "contentType"); + verify(inputStream).readAllBytes(); + } + + @Test + @DisplayName("not upload to bucket due to exception") + void shouldNotUploadToBucket(TestInfo testInfo) throws Exception { + log.info(testInfo.getDisplayName()); + + setExpectations(); + + googleStorageWriter.setup(); + when(inputStream.readAllBytes()).thenThrow(new IllegalStateException("Error")); + assertThrows( + BusinessException.class, + () -> googleStorageWriter.uploadToBucket("bucket", "fileName", inputStream, "contentType")); + } + + private void setExpectations() throws IOException { when(gcpProjectIdProvider.getProjectId()).thenReturn("projectId"); when(credentialsProvider.getCredentials()).thenReturn(credentials); @@ -57,9 +108,5 @@ void shouldUploadToBucket(TestInfo testInfo) throws Exception { when(builder.setCredentials(credentials)).thenReturn(builder); when(builder.build()).thenReturn(storageOptions); when(builder.build().getService()).thenReturn(storage); - - googleStorageWriter.setup(); - googleStorageWriter.uploadToBucket("bucket", "fileName", inputStream, "contentType"); - verify(inputStream).readAllBytes(); } } From 7383bd0cf59ff0573c4132e35eb639af4999e069 Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 09:35:56 -0600 Subject: [PATCH 3/7] #430 Adding not register an adoption due to number not valid --- .../client/GoogleStorageWriterTest.java | 1 - .../controller/TelephoneControllerTest.java | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java b/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java index a4fb8d37..dfe7a3eb 100644 --- a/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java +++ b/src/test/java/com/josdem/vetlog/client/GoogleStorageWriterTest.java @@ -27,7 +27,6 @@ import com.google.cloud.storage.StorageOptions; import com.josdem.vetlog.exception.BusinessException; import com.josdem.vetlog.helper.StorageOptionsHelper; - import java.io.IOException; import java.io.InputStream; import lombok.extern.slf4j.Slf4j; diff --git a/src/test/java/com/josdem/vetlog/controller/TelephoneControllerTest.java b/src/test/java/com/josdem/vetlog/controller/TelephoneControllerTest.java index e6f08412..5934735a 100644 --- a/src/test/java/com/josdem/vetlog/controller/TelephoneControllerTest.java +++ b/src/test/java/com/josdem/vetlog/controller/TelephoneControllerTest.java @@ -4,6 +4,7 @@ import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; @@ -81,4 +82,23 @@ private void registerPet() throws Exception { .andExpect(status().isOk()) .andExpect(view().name("pet/create")); } + + @Test + @Transactional + @DisplayName("not saving adoption due to invalid phone number") + @WithMockUser(username = "josdem", password = "12345678", roles = "USER") + void shouldNotSaveAdoption(TestInfo testInfo) throws Exception { + registerPet(); + + log.info(testInfo.getDisplayName()); + mockMvc.perform(post("/telephone/save") + .with(csrf()) + .param("uuid", PET_UUID) + .param("mobile", "123")) + .andExpect(status().isOk()) + .andExpect(view().name("telephone/adopt")) + .andExpect(model().attributeExists("pet")) + .andExpect(model().attributeExists("telephoneCommand")) + .andExpect(status().isOk()); + } } From 90282b108e8125e0c2af51f722fbd93eef6848e9 Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 09:47:29 -0600 Subject: [PATCH 4/7] #430 Adding error message test --- .../vetlog/controller/TelephoneController.java | 1 + .../resources/templates/telephone/adopt.html | 1 + .../vetlog/controller/PetControllerTest.java | 16 ++++++++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/josdem/vetlog/controller/TelephoneController.java b/src/main/java/com/josdem/vetlog/controller/TelephoneController.java index 14ecffa5..6881dd90 100644 --- a/src/main/java/com/josdem/vetlog/controller/TelephoneController.java +++ b/src/main/java/com/josdem/vetlog/controller/TelephoneController.java @@ -56,6 +56,7 @@ public ModelAndView save( log.info("Saving adoption for pet: {}", telephoneCommand.getUuid()); if (bindingResult.hasErrors()) { ModelAndView modelAndView = new ModelAndView("telephone/adopt"); + modelAndView.addObject("errorMessage", localeService.getMessage("user.error.mobile", request)); return fillPetAndTelephoneCommand(modelAndView, telephoneCommand); } var user = userService.getCurrentUser(); diff --git a/src/main/resources/templates/telephone/adopt.html b/src/main/resources/templates/telephone/adopt.html index ecf505c8..6d889543 100644 --- a/src/main/resources/templates/telephone/adopt.html +++ b/src/main/resources/templates/telephone/adopt.html @@ -14,6 +14,7 @@
+
diff --git a/src/test/java/com/josdem/vetlog/controller/PetControllerTest.java b/src/test/java/com/josdem/vetlog/controller/PetControllerTest.java index 58507d38..ba3d3922 100644 --- a/src/test/java/com/josdem/vetlog/controller/PetControllerTest.java +++ b/src/test/java/com/josdem/vetlog/controller/PetControllerTest.java @@ -86,7 +86,7 @@ void shouldRegisterNewPet(TestInfo testInfo) throws Exception { @DisplayName("showing edit pet form") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldShowEditPetForm(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); // Set up data before the test registerPet(PetStatus.IN_ADOPTION); @@ -104,7 +104,7 @@ void shouldShowEditPetForm(TestInfo testInfo) throws Exception { @DisplayName("updating pet status") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldUpdatePet(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); // Set up data before the test registerPet(PetStatus.IN_ADOPTION); @@ -135,7 +135,7 @@ void shouldUpdatePet(TestInfo testInfo) throws Exception { @DisplayName("listing pets") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldListPets(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/pet/list")) .andExpect(status().isOk()) .andExpect(model().attributeExists("pets")) @@ -147,7 +147,7 @@ void shouldListPets(TestInfo testInfo) throws Exception { @DisplayName("listing for adoption") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldListForAdoption(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/pet/listForAdoption")) .andExpect(status().isOk()) .andExpect(model().attributeExists("pets")) @@ -158,7 +158,7 @@ void shouldListForAdoption(TestInfo testInfo) throws Exception { @DisplayName("giving in adoption") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldGiveForAdoption(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/pet/giveForAdoption")) .andExpect(status().isOk()) .andExpect(model().attributeExists("pets")) @@ -170,7 +170,7 @@ void shouldGiveForAdoption(TestInfo testInfo) throws Exception { @DisplayName("showing create pet form") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldShowCreatePetForm(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/pet/create")) .andExpect(status().isOk()) .andExpect(model().attributeExists("petCommand")) @@ -184,7 +184,7 @@ void shouldShowCreatePetForm(TestInfo testInfo) throws Exception { @DisplayName("not deleting a pet due to is in adoption") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldShowDeletePetForm(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); registerPet(PetStatus.IN_ADOPTION); @@ -217,7 +217,7 @@ private void registerPet(PetStatus status) throws Exception { @DisplayName("deleting a pet successfully") @WithMockUser(username = "josdem", password = "12345678", roles = "USER") void shouldDeletePet(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); // Register a pet with OWNED status registerPet(PetStatus.OWNED); From c5e5fa4988894e3860e4bd7760db9a389fc153a0 Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 09:52:28 -0600 Subject: [PATCH 5/7] #430 Adding logout test --- .../josdem/vetlog/controller/LoginControllerTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/josdem/vetlog/controller/LoginControllerTest.java b/src/test/java/com/josdem/vetlog/controller/LoginControllerTest.java index 202d978b..13f16075 100644 --- a/src/test/java/com/josdem/vetlog/controller/LoginControllerTest.java +++ b/src/test/java/com/josdem/vetlog/controller/LoginControllerTest.java @@ -40,16 +40,23 @@ class LoginControllerTest { @Test @DisplayName("getting login page") void shouldGetLogin(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/login")).andExpect(status().isOk()).andExpect(view().name("login/login")); } @Test @DisplayName("getting login error") void shouldGetLoginErrorMessage(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/login").param("error", "invalid credentials")) .andExpect(status().isOk()) .andExpect(view().name("login/login")); } + + @Test + @DisplayName("logging out") + void shouldLogout(TestInfo testInfo) throws Exception { + log.info(testInfo.getDisplayName()); + mockMvc.perform(get("/logout")).andExpect(status().is3xxRedirection()); + } } From df8d4c7529d86672d621b1b47af1ff68895cd3c1 Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 09:59:59 -0600 Subject: [PATCH 6/7] #430 Deleting unused method --- .../vetlog/controller/RecoveryController.java | 7 ----- .../controller/RecoveryControllerTest.java | 26 +++++++++---------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/josdem/vetlog/controller/RecoveryController.java b/src/main/java/com/josdem/vetlog/controller/RecoveryController.java index 2fbfead9..1544db43 100644 --- a/src/main/java/com/josdem/vetlog/controller/RecoveryController.java +++ b/src/main/java/com/josdem/vetlog/controller/RecoveryController.java @@ -52,13 +52,6 @@ private void initChangeBinder(WebDataBinder binder) { binder.addValidators(changePasswordValidator); } - @GetMapping(value = "/activate/{token}") - public String create(@PathVariable String token) { - log.info("Calling activate token"); - recoveryService.confirmAccountForToken(token); - return LOGIN_VIEW; - } - @PostMapping(value = "/password") public ModelAndView generateTokenToChangePassword( @Valid RecoveryPasswordCommand command, BindingResult bindingResult, HttpServletRequest request) { diff --git a/src/test/java/com/josdem/vetlog/controller/RecoveryControllerTest.java b/src/test/java/com/josdem/vetlog/controller/RecoveryControllerTest.java index e5cf3f76..9c1b21dc 100644 --- a/src/test/java/com/josdem/vetlog/controller/RecoveryControllerTest.java +++ b/src/test/java/com/josdem/vetlog/controller/RecoveryControllerTest.java @@ -42,34 +42,34 @@ class RecoveryControllerTest { @Test @DisplayName("getting email to change password") void shouldRequestEmailToChangePassword(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(get("/recovery/password")) .andExpect(status().isOk()) .andExpect(view().name("recovery/recoveryPassword")); } @Test - @DisplayName("showing change password forms") - void shouldShowChangePasswordForms(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); - mockMvc.perform(get("/recovery/forgot/token")) + @DisplayName("not getting email to change password due to invalid email") + void shouldNotRequestEmailToChangePassword(TestInfo testInfo) throws Exception { + log.info(testInfo.getDisplayName()); + mockMvc.perform(get("/recovery/password").param("email", "notValidEmail")) .andExpect(status().isOk()) - .andExpect(view().name("recovery/changePassword")); + .andExpect(view().name("recovery/recoveryPassword")); } @Test - @DisplayName("user token not found") - void shouldNotFindUserToken(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); - mockMvc.perform(get("/recovery/activate/token")) + @DisplayName("showing change password forms") + void shouldShowChangePasswordForms(TestInfo testInfo) throws Exception { + log.info(testInfo.getDisplayName()); + mockMvc.perform(get("/recovery/forgot/token")) .andExpect(status().isOk()) - .andExpect(view().name("error")); + .andExpect(view().name("recovery/changePassword")); } @Test @DisplayName("not generating token for changing password due to user not found") void shouldNotGenerateTokenToChangePassword(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(post("/recovery/password").with(csrf()).param("email", "contact@josdem.io")) .andExpect(status().isOk()) .andExpect(view().name("error")); @@ -78,7 +78,7 @@ void shouldNotGenerateTokenToChangePassword(TestInfo testInfo) throws Exception @Test @DisplayName("not changing password due to token not found") void shouldNotChangePassword(TestInfo testInfo) throws Exception { - log.info("Running: {}", testInfo.getDisplayName()); + log.info(testInfo.getDisplayName()); mockMvc.perform(post("/recovery/change") .with(csrf()) .param("token", "18c58288-cb57-46dc-b14f-e3ebc2d9b8ce") From 1affc65e12398de59468f0983fed6f96ee0702b8 Mon Sep 17 00:00:00 2001 From: josdem Date: Fri, 20 Dec 2024 10:00:22 -0600 Subject: [PATCH 7/7] #430 Updating version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 22cf26d7..fd2266fe 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ ext { } group = 'com.josdem.vetlog' -version = '2.1.6' +version = '2.1.7' configurations { compileOnly {