From c5668bee08a71681b333e5a072ea189c5d10a854 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Sun, 20 Oct 2024 00:15:41 +0300 Subject: [PATCH 1/5] AYS-455 | `USER_EMAIL_ADDRESS` Has Been Replaced with `USER_ID` --- src/main/java/org/ays/common/model/entity/BaseEntity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/ays/common/model/entity/BaseEntity.java b/src/main/java/org/ays/common/model/entity/BaseEntity.java index bf3fd3dcc..16f2ab9d3 100644 --- a/src/main/java/org/ays/common/model/entity/BaseEntity.java +++ b/src/main/java/org/ays/common/model/entity/BaseEntity.java @@ -37,13 +37,13 @@ * *

* This class utilizes Spring Security's {@link SecurityContextHolder} to fetch the currently - * authenticated user's email address and sets it as the {@code createdUser} or {@code updatedUser}. + * authenticated user's id and sets it as the {@code createdUser} or {@code updatedUser}. * It also sets the timestamps {@code createdAt} and {@code updatedAt}. *

* *
  * Note: Ensure that Spring Security's context is properly configured to use JWTs and that the
- * principal contains a claim for the user's email address.
+ * principal contains a claim for the user's id.
  * 
* * @see SecurityContextHolder @@ -69,7 +69,7 @@ public void prePersist() { .map(Authentication::getPrincipal) .filter(user -> !"anonymousUser".equals(user)) .map(Jwt.class::cast) - .map(jwt -> jwt.getClaim(AysTokenClaims.USER_EMAIL_ADDRESS.getValue()).toString()) + .map(jwt -> jwt.getClaim(AysTokenClaims.USER_ID.getValue()).toString()) .orElse("AYS"); this.createdAt = Optional.ofNullable(this.createdAt) .orElse(LocalDateTime.now()); @@ -88,7 +88,7 @@ public void preUpdate() { .map(Authentication::getPrincipal) .filter(user -> !"anonymousUser".equals(user)) .map(Jwt.class::cast) - .map(jwt -> jwt.getClaim(AysTokenClaims.USER_EMAIL_ADDRESS.getValue()).toString()) + .map(jwt -> jwt.getClaim(AysTokenClaims.USER_ID.getValue()).toString()) .orElse("AYS"); this.updatedAt = LocalDateTime.now(); } From b5a47553da59badf964bcbfc02e8b7c0ea6b672e Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 31 Oct 2024 01:46:38 +0300 Subject: [PATCH 2/5] AYS-455 | Tests Have Been Updated --- .../AdminRegistrationApplicationEndToEndTest.java | 7 ++++++- .../ays/auth/controller/AysAuthEndToEndTest.java | 15 ++++++++++++--- .../ays/auth/controller/AysRoleEndToEndTest.java | 12 ++++++++++++ .../ays/auth/controller/AysUserEndToEndTest.java | 9 +++++++++ ...mergencyEvacuationApplicationEndToEndTest.java | 11 +++++++++-- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java index f349e5313..3b48381a1 100644 --- a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java @@ -49,6 +49,7 @@ import java.util.List; import java.util.Optional; +import java.util.regex.Pattern; class AdminRegistrationApplicationEndToEndTest extends AysEndToEndTest { @@ -77,6 +78,7 @@ class AdminRegistrationApplicationEndToEndTest extends AysEndToEndTest { private final AdminRegistrationApplicationToSummaryResponseMapper adminRegistrationApplicationToSummaryResponseMapper = AdminRegistrationApplicationToSummaryResponseMapper.initialize(); private final AdminRegistrationApplicationToCreateResponseMapper adminRegistrationApplicationToCreateResponseMapper = AdminRegistrationApplicationToCreateResponseMapper.initialize(); + private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); private static final String BASE_PATH = "/api/v1"; @@ -281,6 +283,7 @@ void givenValidAdminRegistrationApplicationCreateRequest_whenCreatingAdminRegist Assertions.assertEquals(AdminRegistrationApplicationStatus.WAITING, registrationApplication.get().getStatus()); Assertions.assertEquals(institution.getId(), registrationApplication.get().getInstitution().getId()); Assertions.assertNull(registrationApplication.get().getUser()); + Assertions.assertTrue(UUID_REGEX.matcher(registrationApplication.get().getCreatedUser()).matches()); } @Test @@ -355,7 +358,7 @@ void givenValidAdminRegistrationApplicationCompleteRequest_whenAdminRegistered_t // Then String endpoint = BASE_PATH.concat("/admin-registration-application/").concat(applicationId).concat("/complete"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, completeRequest); + .post(endpoint, superAdminToken.getAccessToken(), completeRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -371,6 +374,7 @@ void givenValidAdminRegistrationApplicationCompleteRequest_whenAdminRegistered_t Assertions.assertTrue(applicationFromDatabase.isPresent()); Assertions.assertEquals(AdminRegistrationApplicationStatus.COMPLETED, applicationFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(applicationFromDatabase.get().getUpdatedUser()).matches()); List permissionsFromDatabase = permissionReadPort.findAllByIsSuperFalse(); @@ -680,6 +684,7 @@ void givenValidAdminRegistrationApplicationRejectRequest_whenRejectingAdminRegis Assertions.assertTrue(applicationFromDatabase.isPresent()); Assertions.assertEquals(AdminRegistrationApplicationStatus.REJECTED, applicationFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(applicationFromDatabase.get().getUpdatedUser()).matches()); } @Test diff --git a/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java index 685767fed..20efa7987 100644 --- a/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java @@ -34,6 +34,7 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.regex.Pattern; class AysAuthEndToEndTest extends AysEndToEndTest { @@ -47,6 +48,8 @@ class AysAuthEndToEndTest extends AysEndToEndTest { private AysRoleReadPort roleReadPort; + private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + private static final String BASE_PATH = "/api/v1/authentication"; @@ -161,7 +164,7 @@ void givenValidForgotPasswordRequest_whenUserHasNotPasswordAndPasswordCreatedWit // Then String endpoint = BASE_PATH.concat("/password/forgot"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, mockForgotPasswordRequest); + .post(endpoint, userToken.getAccessToken(), mockForgotPasswordRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -176,6 +179,7 @@ void givenValidForgotPasswordRequest_whenUserHasNotPasswordAndPasswordCreatedWit .orElseThrow(); AysUser.Password passwordFromDatabase = userFromDatabase.getPassword(); + Assertions.assertNotNull(passwordFromDatabase); Assertions.assertNotNull(passwordFromDatabase.getValue()); Assertions.assertNotNull(passwordFromDatabase.getForgotAt()); @@ -184,6 +188,7 @@ void givenValidForgotPasswordRequest_whenUserHasNotPasswordAndPasswordCreatedWit Assertions.assertNotNull(passwordFromDatabase.getCreatedAt()); Assertions.assertNull(passwordFromDatabase.getUpdatedUser()); Assertions.assertNull(passwordFromDatabase.getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(passwordFromDatabase.getCreatedUser()).matches()); } @Test @@ -222,7 +227,7 @@ void givenValidForgotPasswordRequest_whenUserHasPasswordAndPasswordCreatedWithLa // Then String endpoint = BASE_PATH.concat("/password/forgot"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, mockForgotPasswordRequest); + .post(endpoint, userToken.getAccessToken(), mockForgotPasswordRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -237,6 +242,7 @@ void givenValidForgotPasswordRequest_whenUserHasPasswordAndPasswordCreatedWithLa .orElseThrow(); AysUser.Password passwordFromDatabase = userFromDatabase.getPassword(); + Assertions.assertNotNull(passwordFromDatabase); Assertions.assertNotNull(passwordFromDatabase.getValue()); Assertions.assertEquals(password.getValue(), passwordFromDatabase.getValue()); @@ -246,6 +252,7 @@ void givenValidForgotPasswordRequest_whenUserHasPasswordAndPasswordCreatedWithLa Assertions.assertNotNull(passwordFromDatabase.getCreatedAt()); Assertions.assertNull(passwordFromDatabase.getUpdatedUser()); Assertions.assertNull(passwordFromDatabase.getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(passwordFromDatabase.getCreatedUser()).matches()); } @@ -333,7 +340,7 @@ void givenValidPasswordCreateRequest_whenPasswordCreated_thenReturnSuccessRespon // Then String endpoint = BASE_PATH.concat("/password/").concat(mockId); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, mockPasswordCreateRequest); + .post(endpoint, userToken.getAccessToken(), mockPasswordCreateRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -348,6 +355,7 @@ void givenValidPasswordCreateRequest_whenPasswordCreated_thenReturnSuccessRespon .orElseThrow(); AysUser.Password passwordFromDatabase = userFromDatabase.getPassword(); + Assertions.assertNotNull(passwordFromDatabase); Assertions.assertNotEquals(mockId, passwordFromDatabase.getId()); Assertions.assertNotNull(passwordFromDatabase.getValue()); @@ -356,6 +364,7 @@ void givenValidPasswordCreateRequest_whenPasswordCreated_thenReturnSuccessRespon Assertions.assertNotNull(passwordFromDatabase.getCreatedAt()); Assertions.assertNull(passwordFromDatabase.getUpdatedUser()); Assertions.assertNull(passwordFromDatabase.getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(passwordFromDatabase.getCreatedUser()).matches()); } } diff --git a/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java index 622fba23f..b8b3f783d 100644 --- a/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; class AysRoleEndToEndTest extends AysEndToEndTest { @@ -57,6 +58,8 @@ class AysRoleEndToEndTest extends AysEndToEndTest { private final AysRoleToResponseMapper roleToResponseMapper = AysRoleToResponseMapper.initialize(); + private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + private static final String BASE_PATH = "/api/v1"; @@ -329,6 +332,7 @@ void givenValidRoleCreateRequest_whenSuperRoleCreated_thenReturnSuccess() throws role.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); + Assertions.assertTrue(UUID_REGEX.matcher(role.get().getCreatedUser()).matches()); } @Test @@ -370,6 +374,7 @@ void givenValidRoleCreateRequest_whenRoleCreated_thenReturnSuccess() throws Exce role.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); + Assertions.assertTrue(UUID_REGEX.matcher(role.get().getCreatedUser()).matches()); } @Test @@ -457,6 +462,7 @@ void givenValidIdAndRoleUpdateRequest_whenSuperRoleUpdated_thenReturnSuccess() t roleFromDatabase.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); + Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); } @Test @@ -511,6 +517,8 @@ void givenValidRoleUpdateRequest_whenRoleUpdated_thenReturnSuccess() throws Exce roleFromDatabase.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); + Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + } @Test @@ -567,6 +575,7 @@ void givenValidRoleUpdateRequest_whenPermissionsUpdatedAndNameUnchanged_thenRetu roleFromDatabase.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); + Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); } @Test @@ -659,6 +668,7 @@ void givenId_whenRoleActivated_thenReturnSuccess() throws Exception { Assertions.assertTrue(roleFromDatabase.isPresent()); Assertions.assertEquals(roleFromDatabase.get().getId(), id); Assertions.assertEquals(AysRoleStatus.ACTIVE, roleFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); } @@ -704,6 +714,7 @@ void givenId_whenRolePassivated_thenReturnSuccess() throws Exception { Assertions.assertTrue(roleFromDatabase.isPresent()); Assertions.assertEquals(roleFromDatabase.get().getId(), id); Assertions.assertEquals(AysRoleStatus.PASSIVE, roleFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); } @@ -745,6 +756,7 @@ void givenValidId_whenRoleDeleted_thenReturnSuccess() throws Exception { Assertions.assertTrue(roleFromDatabase.isPresent()); Assertions.assertNotNull(roleFromDatabase.get().getId()); Assertions.assertEquals(AysRoleStatus.DELETED, roleFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); } } diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index 057841a3b..c7c9b7fa7 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; class AysUserEndToEndTest extends AysEndToEndTest { @@ -53,6 +54,8 @@ class AysUserEndToEndTest extends AysEndToEndTest { private final AysUserToResponseMapper userToResponseMapper = AysUserToResponseMapper.initialize(); + private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + private static final String BASE_PATH = "/api/v1"; @@ -302,6 +305,7 @@ void givenUserCreateRequest_whenUserCreated_thenReturnSuccess() throws Exception Assertions.assertNotNull(userFromDatabase.get().getCreatedAt()); Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); Assertions.assertNull(userFromDatabase.get().getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getCreatedUser()).matches()); } @@ -373,6 +377,7 @@ void givenValidIdAndUserUpdateRequest_whenUserUpdated_thenReturnSuccess() throws ); Assertions.assertNotNull(userFromDatabase.get().getUpdatedUser()); Assertions.assertNotNull(userFromDatabase.get().getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); } @Test @@ -445,6 +450,7 @@ void givenValidIdAndUserUpdateRequest_whenRolesUpdatedOnly_thenReturnSuccess() t ); Assertions.assertNotNull(userFromDatabase.get().getUpdatedUser()); Assertions.assertNotNull(userFromDatabase.get().getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); } @@ -490,6 +496,7 @@ void givenValidId_whenActivateUser_thenReturnSuccess() throws Exception { Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.ACTIVE, userFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); } @@ -542,6 +549,7 @@ void givenValidId_whenUserDeleted_thenReturnSuccess() throws Exception { Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertNotNull(userFromDatabase.get().getId()); Assertions.assertEquals(AysUserStatus.DELETED, userFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); } @@ -587,6 +595,7 @@ void givenValidId_whenPassivateUser_thenReturnSuccess() throws Exception { Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.PASSIVE, userFromDatabase.get().getStatus()); + Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); } } diff --git a/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java b/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java index 015622f2d..6e2f40284 100644 --- a/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java +++ b/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.regex.Pattern; class EmergencyEvacuationApplicationEndToEndTest extends AysEndToEndTest { @@ -49,8 +50,11 @@ class EmergencyEvacuationApplicationEndToEndTest extends AysEndToEndTest { private final EmergencyEvacuationApplicationToApplicationResponseMapper emergencyEvacuationApplicationToApplicationResponseMapper = EmergencyEvacuationApplicationToApplicationResponseMapper.initialize(); + private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + private static final String BASE_PATH = "/api/v1"; + @Test void givenValidEmergencyEvacuationApplicationListRequest_whenApplicationsFound_thenReturnAysPageResponseOfEmergencyEvacuationApplicationsResponse() throws Exception { @@ -320,7 +324,7 @@ void givenValidEmergencyEvacuationApplicationRequest_whenApplicationSaved_thenRe // Then String endpoint = BASE_PATH.concat("/emergency-evacuation-application"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, applicationRequest); + .post(endpoint, adminToken.getAccessToken(), applicationRequest); AysResponse mockResponse = AysResponseBuilder.success(); aysMockMvc.perform(mockHttpServletRequestBuilder, mockResponse) @@ -362,6 +366,7 @@ void givenValidEmergencyEvacuationApplicationRequest_whenApplicationSaved_thenRe Assertions.assertFalse(application.get().getIsInPerson()); Assertions.assertNull(application.get().getHasObstaclePersonExist()); Assertions.assertNull(application.get().getNotes()); + Assertions.assertTrue(UUID_REGEX.matcher(application.get().getCreatedUser()).matches()); } @Test @@ -377,7 +382,7 @@ void givenValidEmergencyEvacuationApplicationRequestWithoutApplicant_whenApplica // Then String endpoint = BASE_PATH.concat("/emergency-evacuation-application"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, applicationRequest); + .post(endpoint, adminToken.getAccessToken(), applicationRequest); AysResponse mockResponse = AysResponseBuilder.success(); aysMockMvc.perform(mockHttpServletRequestBuilder, mockResponse) @@ -419,6 +424,7 @@ void givenValidEmergencyEvacuationApplicationRequestWithoutApplicant_whenApplica Assertions.assertTrue(application.get().getIsInPerson()); Assertions.assertNull(application.get().getHasObstaclePersonExist()); Assertions.assertNull(application.get().getNotes()); + Assertions.assertTrue(UUID_REGEX.matcher(application.get().getCreatedUser()).matches()); } @@ -471,6 +477,7 @@ void givenValidIdAndValidUpdateRequest_whenApplicationUpdated_thenReturnSuccessR Assertions.assertEquals(applicationFromDatabase.get().getNotes(), updateRequest.getNotes()); Assertions.assertNotNull(applicationFromDatabase.get().getUpdatedUser()); Assertions.assertNotNull(applicationFromDatabase.get().getUpdatedAt()); + Assertions.assertTrue(UUID_REGEX.matcher(applicationFromDatabase.get().getUpdatedUser()).matches()); } } From c20aa236cb7c6a6df110098934c80efc247cd7a7 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 31 Oct 2024 01:49:36 +0300 Subject: [PATCH 3/5] AYS-455 | Refactored --- src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java index b8b3f783d..7f8425ee7 100644 --- a/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java @@ -518,7 +518,6 @@ void givenValidRoleUpdateRequest_whenRoleUpdated_thenReturnSuccess() throws Exce .anyMatch(permission -> permission.getId().equals(permissionId)) )); Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); - } @Test From 3145bfdfbe839bb1a2087bb42022954336f690c8 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 31 Oct 2024 18:00:54 +0300 Subject: [PATCH 4/5] AYS-455 | Regex and Tests Are Refactored --- ...inRegistrationApplicationEndToEndTest.java | 12 +++++------ .../auth/controller/AysAuthEndToEndTest.java | 15 ++++++-------- .../auth/controller/AysRoleEndToEndTest.java | 20 +++++++++---------- .../auth/controller/AysUserEndToEndTest.java | 16 +++++++-------- ...encyEvacuationApplicationEndToEndTest.java | 14 ++++++------- src/test/java/org/ays/util/UUIDTestUtil.java | 13 ++++++++++++ 6 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 src/test/java/org/ays/util/UUIDTestUtil.java diff --git a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java index 3b48381a1..789c09591 100644 --- a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java @@ -42,6 +42,7 @@ import org.ays.institution.port.InstitutionSavePort; import org.ays.util.AysMockMvcRequestBuilders; import org.ays.util.AysMockResultMatchersBuilders; +import org.ays.util.UUIDTestUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -49,7 +50,6 @@ import java.util.List; import java.util.Optional; -import java.util.regex.Pattern; class AdminRegistrationApplicationEndToEndTest extends AysEndToEndTest { @@ -78,10 +78,10 @@ class AdminRegistrationApplicationEndToEndTest extends AysEndToEndTest { private final AdminRegistrationApplicationToSummaryResponseMapper adminRegistrationApplicationToSummaryResponseMapper = AdminRegistrationApplicationToSummaryResponseMapper.initialize(); private final AdminRegistrationApplicationToCreateResponseMapper adminRegistrationApplicationToCreateResponseMapper = AdminRegistrationApplicationToCreateResponseMapper.initialize(); - private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); private static final String BASE_PATH = "/api/v1"; + @Test void givenValidAdminRegistrationApplicationListRequest_whenAdminRegistrationApplicationsFound_thenReturnAdminRegistrationApplicationsResponse() throws Exception { @@ -283,7 +283,7 @@ void givenValidAdminRegistrationApplicationCreateRequest_whenCreatingAdminRegist Assertions.assertEquals(AdminRegistrationApplicationStatus.WAITING, registrationApplication.get().getStatus()); Assertions.assertEquals(institution.getId(), registrationApplication.get().getInstitution().getId()); Assertions.assertNull(registrationApplication.get().getUser()); - Assertions.assertTrue(UUID_REGEX.matcher(registrationApplication.get().getCreatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(registrationApplication.get().getCreatedUser())); } @Test @@ -358,7 +358,7 @@ void givenValidAdminRegistrationApplicationCompleteRequest_whenAdminRegistered_t // Then String endpoint = BASE_PATH.concat("/admin-registration-application/").concat(applicationId).concat("/complete"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, superAdminToken.getAccessToken(), completeRequest); + .post(endpoint, completeRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -374,7 +374,7 @@ void givenValidAdminRegistrationApplicationCompleteRequest_whenAdminRegistered_t Assertions.assertTrue(applicationFromDatabase.isPresent()); Assertions.assertEquals(AdminRegistrationApplicationStatus.COMPLETED, applicationFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(applicationFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertEquals(applicationFromDatabase.get().getUpdatedUser(), "AYS"); List permissionsFromDatabase = permissionReadPort.findAllByIsSuperFalse(); @@ -684,7 +684,7 @@ void givenValidAdminRegistrationApplicationRejectRequest_whenRejectingAdminRegis Assertions.assertTrue(applicationFromDatabase.isPresent()); Assertions.assertEquals(AdminRegistrationApplicationStatus.REJECTED, applicationFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(applicationFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(applicationFromDatabase.get().getUpdatedUser())); } @Test diff --git a/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java index 20efa7987..2cc38f39d 100644 --- a/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysAuthEndToEndTest.java @@ -34,7 +34,6 @@ import java.time.LocalDateTime; import java.util.List; -import java.util.regex.Pattern; class AysAuthEndToEndTest extends AysEndToEndTest { @@ -48,8 +47,6 @@ class AysAuthEndToEndTest extends AysEndToEndTest { private AysRoleReadPort roleReadPort; - private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); - private static final String BASE_PATH = "/api/v1/authentication"; @@ -164,7 +161,7 @@ void givenValidForgotPasswordRequest_whenUserHasNotPasswordAndPasswordCreatedWit // Then String endpoint = BASE_PATH.concat("/password/forgot"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, userToken.getAccessToken(), mockForgotPasswordRequest); + .post(endpoint, mockForgotPasswordRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -188,7 +185,7 @@ void givenValidForgotPasswordRequest_whenUserHasNotPasswordAndPasswordCreatedWit Assertions.assertNotNull(passwordFromDatabase.getCreatedAt()); Assertions.assertNull(passwordFromDatabase.getUpdatedUser()); Assertions.assertNull(passwordFromDatabase.getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(passwordFromDatabase.getCreatedUser()).matches()); + Assertions.assertEquals(passwordFromDatabase.getCreatedUser(), "AYS"); } @Test @@ -227,7 +224,7 @@ void givenValidForgotPasswordRequest_whenUserHasPasswordAndPasswordCreatedWithLa // Then String endpoint = BASE_PATH.concat("/password/forgot"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, userToken.getAccessToken(), mockForgotPasswordRequest); + .post(endpoint, mockForgotPasswordRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -252,7 +249,7 @@ void givenValidForgotPasswordRequest_whenUserHasPasswordAndPasswordCreatedWithLa Assertions.assertNotNull(passwordFromDatabase.getCreatedAt()); Assertions.assertNull(passwordFromDatabase.getUpdatedUser()); Assertions.assertNull(passwordFromDatabase.getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(passwordFromDatabase.getCreatedUser()).matches()); + Assertions.assertEquals(passwordFromDatabase.getCreatedUser(), "AYS"); } @@ -340,7 +337,7 @@ void givenValidPasswordCreateRequest_whenPasswordCreated_thenReturnSuccessRespon // Then String endpoint = BASE_PATH.concat("/password/").concat(mockId); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, userToken.getAccessToken(), mockPasswordCreateRequest); + .post(endpoint, mockPasswordCreateRequest); AysResponse mockResponse = AysResponseBuilder.success(); @@ -364,7 +361,7 @@ void givenValidPasswordCreateRequest_whenPasswordCreated_thenReturnSuccessRespon Assertions.assertNotNull(passwordFromDatabase.getCreatedAt()); Assertions.assertNull(passwordFromDatabase.getUpdatedUser()); Assertions.assertNull(passwordFromDatabase.getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(passwordFromDatabase.getCreatedUser()).matches()); + Assertions.assertEquals(passwordFromDatabase.getCreatedUser(), "AYS"); } } diff --git a/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java index 7f8425ee7..fb6a50670 100644 --- a/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java @@ -29,6 +29,7 @@ import org.ays.util.AysMockMvcRequestBuilders; import org.ays.util.AysMockResultMatchersBuilders; import org.ays.util.AysValidTestData; +import org.ays.util.UUIDTestUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -40,7 +41,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; class AysRoleEndToEndTest extends AysEndToEndTest { @@ -58,8 +58,6 @@ class AysRoleEndToEndTest extends AysEndToEndTest { private final AysRoleToResponseMapper roleToResponseMapper = AysRoleToResponseMapper.initialize(); - private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); - private static final String BASE_PATH = "/api/v1"; @@ -332,7 +330,7 @@ void givenValidRoleCreateRequest_whenSuperRoleCreated_thenReturnSuccess() throws role.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); - Assertions.assertTrue(UUID_REGEX.matcher(role.get().getCreatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(role.get().getCreatedUser())); } @Test @@ -374,7 +372,7 @@ void givenValidRoleCreateRequest_whenRoleCreated_thenReturnSuccess() throws Exce role.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); - Assertions.assertTrue(UUID_REGEX.matcher(role.get().getCreatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(role.get().getCreatedUser())); } @Test @@ -462,7 +460,7 @@ void givenValidIdAndRoleUpdateRequest_whenSuperRoleUpdated_thenReturnSuccess() t roleFromDatabase.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); - Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(roleFromDatabase.get().getUpdatedUser())); } @Test @@ -517,7 +515,7 @@ void givenValidRoleUpdateRequest_whenRoleUpdated_thenReturnSuccess() throws Exce roleFromDatabase.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); - Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(roleFromDatabase.get().getUpdatedUser())); } @Test @@ -574,7 +572,7 @@ void givenValidRoleUpdateRequest_whenPermissionsUpdatedAndNameUnchanged_thenRetu roleFromDatabase.get().getPermissions().stream() .anyMatch(permission -> permission.getId().equals(permissionId)) )); - Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(roleFromDatabase.get().getUpdatedUser())); } @Test @@ -667,7 +665,7 @@ void givenId_whenRoleActivated_thenReturnSuccess() throws Exception { Assertions.assertTrue(roleFromDatabase.isPresent()); Assertions.assertEquals(roleFromDatabase.get().getId(), id); Assertions.assertEquals(AysRoleStatus.ACTIVE, roleFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(roleFromDatabase.get().getUpdatedUser())); } @@ -713,7 +711,7 @@ void givenId_whenRolePassivated_thenReturnSuccess() throws Exception { Assertions.assertTrue(roleFromDatabase.isPresent()); Assertions.assertEquals(roleFromDatabase.get().getId(), id); Assertions.assertEquals(AysRoleStatus.PASSIVE, roleFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(roleFromDatabase.get().getUpdatedUser())); } @@ -755,7 +753,7 @@ void givenValidId_whenRoleDeleted_thenReturnSuccess() throws Exception { Assertions.assertTrue(roleFromDatabase.isPresent()); Assertions.assertNotNull(roleFromDatabase.get().getId()); Assertions.assertEquals(AysRoleStatus.DELETED, roleFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(roleFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(roleFromDatabase.get().getUpdatedUser())); } } diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index c7c9b7fa7..2f56f316f 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -28,6 +28,7 @@ import org.ays.util.AysMockMvcRequestBuilders; import org.ays.util.AysMockResultMatchersBuilders; import org.ays.util.AysValidTestData; +import org.ays.util.UUIDTestUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +37,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; class AysUserEndToEndTest extends AysEndToEndTest { @@ -54,8 +54,6 @@ class AysUserEndToEndTest extends AysEndToEndTest { private final AysUserToResponseMapper userToResponseMapper = AysUserToResponseMapper.initialize(); - private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); - private static final String BASE_PATH = "/api/v1"; @@ -305,7 +303,7 @@ void givenUserCreateRequest_whenUserCreated_thenReturnSuccess() throws Exception Assertions.assertNotNull(userFromDatabase.get().getCreatedAt()); Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); Assertions.assertNull(userFromDatabase.get().getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getCreatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getCreatedUser())); } @@ -377,7 +375,7 @@ void givenValidIdAndUserUpdateRequest_whenUserUpdated_thenReturnSuccess() throws ); Assertions.assertNotNull(userFromDatabase.get().getUpdatedUser()); Assertions.assertNotNull(userFromDatabase.get().getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } @Test @@ -450,7 +448,7 @@ void givenValidIdAndUserUpdateRequest_whenRolesUpdatedOnly_thenReturnSuccess() t ); Assertions.assertNotNull(userFromDatabase.get().getUpdatedUser()); Assertions.assertNotNull(userFromDatabase.get().getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } @@ -496,7 +494,7 @@ void givenValidId_whenActivateUser_thenReturnSuccess() throws Exception { Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.ACTIVE, userFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } @@ -549,7 +547,7 @@ void givenValidId_whenUserDeleted_thenReturnSuccess() throws Exception { Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertNotNull(userFromDatabase.get().getId()); Assertions.assertEquals(AysUserStatus.DELETED, userFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } @@ -595,7 +593,7 @@ void givenValidId_whenPassivateUser_thenReturnSuccess() throws Exception { Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.PASSIVE, userFromDatabase.get().getStatus()); - Assertions.assertTrue(UUID_REGEX.matcher(userFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } } diff --git a/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java b/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java index 6e2f40284..a8d4e9883 100644 --- a/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java +++ b/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationEndToEndTest.java @@ -24,6 +24,7 @@ import org.ays.util.AysMockMvcRequestBuilders; import org.ays.util.AysMockResultMatchersBuilders; import org.ays.util.AysValidTestData; +import org.ays.util.UUIDTestUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +34,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.regex.Pattern; class EmergencyEvacuationApplicationEndToEndTest extends AysEndToEndTest { @@ -50,8 +50,6 @@ class EmergencyEvacuationApplicationEndToEndTest extends AysEndToEndTest { private final EmergencyEvacuationApplicationToApplicationResponseMapper emergencyEvacuationApplicationToApplicationResponseMapper = EmergencyEvacuationApplicationToApplicationResponseMapper.initialize(); - private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); - private static final String BASE_PATH = "/api/v1"; @@ -324,7 +322,7 @@ void givenValidEmergencyEvacuationApplicationRequest_whenApplicationSaved_thenRe // Then String endpoint = BASE_PATH.concat("/emergency-evacuation-application"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, adminToken.getAccessToken(), applicationRequest); + .post(endpoint, applicationRequest); AysResponse mockResponse = AysResponseBuilder.success(); aysMockMvc.perform(mockHttpServletRequestBuilder, mockResponse) @@ -366,7 +364,7 @@ void givenValidEmergencyEvacuationApplicationRequest_whenApplicationSaved_thenRe Assertions.assertFalse(application.get().getIsInPerson()); Assertions.assertNull(application.get().getHasObstaclePersonExist()); Assertions.assertNull(application.get().getNotes()); - Assertions.assertTrue(UUID_REGEX.matcher(application.get().getCreatedUser()).matches()); + Assertions.assertEquals(application.get().getCreatedUser(), "AYS"); } @Test @@ -382,7 +380,7 @@ void givenValidEmergencyEvacuationApplicationRequestWithoutApplicant_whenApplica // Then String endpoint = BASE_PATH.concat("/emergency-evacuation-application"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders - .post(endpoint, adminToken.getAccessToken(), applicationRequest); + .post(endpoint, applicationRequest); AysResponse mockResponse = AysResponseBuilder.success(); aysMockMvc.perform(mockHttpServletRequestBuilder, mockResponse) @@ -424,7 +422,7 @@ void givenValidEmergencyEvacuationApplicationRequestWithoutApplicant_whenApplica Assertions.assertTrue(application.get().getIsInPerson()); Assertions.assertNull(application.get().getHasObstaclePersonExist()); Assertions.assertNull(application.get().getNotes()); - Assertions.assertTrue(UUID_REGEX.matcher(application.get().getCreatedUser()).matches()); + Assertions.assertEquals(application.get().getCreatedUser(), "AYS"); } @@ -477,7 +475,7 @@ void givenValidIdAndValidUpdateRequest_whenApplicationUpdated_thenReturnSuccessR Assertions.assertEquals(applicationFromDatabase.get().getNotes(), updateRequest.getNotes()); Assertions.assertNotNull(applicationFromDatabase.get().getUpdatedUser()); Assertions.assertNotNull(applicationFromDatabase.get().getUpdatedAt()); - Assertions.assertTrue(UUID_REGEX.matcher(applicationFromDatabase.get().getUpdatedUser()).matches()); + Assertions.assertTrue(UUIDTestUtil.isValid(applicationFromDatabase.get().getUpdatedUser())); } } diff --git a/src/test/java/org/ays/util/UUIDTestUtil.java b/src/test/java/org/ays/util/UUIDTestUtil.java new file mode 100644 index 000000000..8e768552f --- /dev/null +++ b/src/test/java/org/ays/util/UUIDTestUtil.java @@ -0,0 +1,13 @@ +package org.ays.util; + +import java.util.regex.Pattern; + +public class UUIDTestUtil { + + private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + + public static boolean isValid(String uuid) { + return UUID_REGEX.matcher(uuid).matches(); + } + +} From 9911f01cf5040dad2d22242c26378f8f92aa9668 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Fri, 1 Nov 2024 15:06:46 +0300 Subject: [PATCH 5/5] AYS-455 | `@UtilityClass` Annotation Has Been Added --- src/test/java/org/ays/util/UUIDTestUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/ays/util/UUIDTestUtil.java b/src/test/java/org/ays/util/UUIDTestUtil.java index 8e768552f..b9b5f021a 100644 --- a/src/test/java/org/ays/util/UUIDTestUtil.java +++ b/src/test/java/org/ays/util/UUIDTestUtil.java @@ -1,7 +1,10 @@ package org.ays.util; +import lombok.experimental.UtilityClass; + import java.util.regex.Pattern; +@UtilityClass public class UUIDTestUtil { private static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");