diff --git a/src/main/java/biz/nynja/account/components/PendingAccountValidator.java b/src/main/java/biz/nynja/account/components/PendingAccountValidator.java index 09c4aae6be2b18492f4da27dd1f97cc96a426c7a..96a74cbddc662f36d67bcde1a486927858d24478 100644 --- a/src/main/java/biz/nynja/account/components/PendingAccountValidator.java +++ b/src/main/java/biz/nynja/account/components/PendingAccountValidator.java @@ -40,12 +40,12 @@ public class PendingAccountValidator { if (request.getUsername() != null && !request.getUsername().trim().isEmpty() && !validator.isUsernameValid(request.getUsername())) { - return Cause.USERNAME_INVALID; + return Cause.INVALID_USERNAME; } if (request.getAccountName() != null && !request.getAccountName().trim().isEmpty() && !validator.isAccountNameValid(request.getAccountName())) { - return Cause.ACCOUNT_NAME_INVALID; + return Cause.INVALID_ACCOUNT_NAME; } return null; diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index fcf8b0c143fe1c8b450cb016ea7f11a6ecf3d28a..ad0e57ea92dca889887f82e735e32b09dadbc8f4 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -123,7 +123,7 @@ public class Validator { public Cause validateAuthProvider(AuthenticationType type, String authProvider) { if (authProvider == null || authProvider.trim().isEmpty()) { - return Cause.MISSING_AUTH_PROVIDER_IDENTIFIER; + return Cause.MISSING_AUTH_PROVIDER_ID; } switch (type) { case MISSING_TYPE: @@ -132,15 +132,15 @@ public class Validator { // We expect to receive phone number in the following format : ":" String[] provider = authProvider.split(":"); if (provider == null || provider.length != 2) { - return Cause.PHONE_NUMBER_INVALID; + return Cause.INVALID_PHONENUMBER; } if (!phoneValidator.isPhoneNumberValid(provider[1], provider[0])) { - return Cause.PHONE_NUMBER_INVALID; + return Cause.INVALID_PHONENUMBER; } break; case EMAIL: if (!isEmailValid(authProvider)) { - return Cause.EMAIL_INVALID; + return Cause.INVALID_EMAIL; } break; default: @@ -152,7 +152,7 @@ public class Validator { public Optional> validateContactInfo(ContactType type, String contactInfoValue) { if (contactInfoValue == null || contactInfoValue.trim().isEmpty()) { return Optional - .of(new ImmutablePair<>(Cause.MISSING_CONTACT_INFO_IDENTIFIER, "Missing contact info identifier")); + .of(new ImmutablePair<>(Cause.MISSING_CONTACT_INFO_ID, "Missing contact info identifier")); } switch (type) { case MISSING_CONTACT_TYPE: @@ -161,15 +161,15 @@ public class Validator { // We expect to receive phone number in the following format : ":" String[] provider = contactInfoValue.split(":"); if (provider == null || provider.length != 2) { - return Optional.of(new ImmutablePair<>(Cause.PHONE_NUMBER_INVALID, "Invalid phone number")); + return Optional.of(new ImmutablePair<>(Cause.INVALID_PHONENUMBER, "Invalid phone number")); } if (!phoneValidator.isPhoneNumberValid(provider[1], provider[0])) { - return Optional.of(new ImmutablePair<>(Cause.PHONE_NUMBER_INVALID, "Invalid phone number")); + return Optional.of(new ImmutablePair<>(Cause.INVALID_PHONENUMBER, "Invalid phone number")); } break; case EMAIL_CONTACT: if (!isEmailValid(contactInfoValue)) { - return Optional.of(new ImmutablePair<>(Cause.EMAIL_INVALID, "Invalid email")); + return Optional.of(new ImmutablePair<>(Cause.INVALID_EMAIL, "Invalid email")); } break; default: @@ -186,7 +186,7 @@ public class Validator { if (request.getUsername() != null && !request.getUsername().trim().isEmpty() && !isUsernameValid(request.getUsername())) { - return Cause.USERNAME_INVALID; + return Cause.INVALID_USERNAME; } if (request.getFirstName() != null && request.getFirstName().trim().isEmpty()) { @@ -202,7 +202,7 @@ public class Validator { if (request.getAccountName() != null && !request.getAccountName().trim().isEmpty() && !isAccountNameValid(request.getAccountName())) { - return Cause.ACCOUNT_NAME_INVALID; + return Cause.INVALID_ACCOUNT_NAME; } if (validateBirthdayIsSet(request.getBirthday())) { @@ -246,7 +246,7 @@ public class Validator { } if (contactDetails.getValue() == null || contactDetails.getValue().isEmpty()) { return Optional - .of(new ImmutablePair<>(Cause.MISSING_CONTACT_INFO_IDENTIFIER, "Missing contact info identifier")); + .of(new ImmutablePair<>(Cause.MISSING_CONTACT_INFO_ID, "Missing contact info identifier")); } if (!isValidUuid(accountId)) { return Optional.of(new ImmutablePair<>(Cause.INVALID_ACCOUNT_ID, "Invalid account id")); diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 9396f1081274136c3baa913a126a6a43721b2ec7..0ad6625f9a25548ad26ef8282f5db4a58cdada88 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -121,7 +121,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas } if (request.getAuthenticationIdentifier() == null || request.getAuthenticationIdentifier().isEmpty()) { logAndBuildGrpcAccountResponse(responseObserver, AccountResponse.newBuilder(), - "Missing authentication provider identifier", "", Cause.MISSING_AUTH_PROVIDER_IDENTIFIER); + "Missing authentication provider identifier", "", Cause.MISSING_AUTH_PROVIDER_ID); return; } Optional account = accountProvider.getAccountResponseByAuthenticationProvider( @@ -149,7 +149,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas } if (!validator.isEmailValid(request.getEmail())) { logAndBuildGrpcSearchResponse(responseObserver, SearchResponse.newBuilder(), "Invalid e-mail!. Value : ", - request.getEmail(), Cause.EMAIL_INVALID); + request.getEmail(), Cause.INVALID_EMAIL); return; } @@ -266,7 +266,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas } if (!validator.isValidUsername(request.getUsername())) { validation.addError( - new ValidationError("Invalid username. Value: " + request.getUsername(), Cause.USERNAME_INVALID)); + new ValidationError("Invalid username. Value: " + request.getUsername(), Cause.INVALID_USERNAME)); } return validation; @@ -506,7 +506,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (request.getAuthenticationProvider().getAuthenticationProvider() == null || request.getAuthenticationProvider().getAuthenticationProvider().isEmpty()) { logAndBuildGrpcStatusResponse(responseObserver, StatusResponse.newBuilder(), - "Missing auth provider identifier", "", Cause.MISSING_AUTH_PROVIDER_IDENTIFIER); + "Missing auth provider identifier", "", Cause.MISSING_AUTH_PROVIDER_ID); return; } Cause cause = validator.validateAddAuthenticationProviderRequest(request); @@ -617,7 +617,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas } logAndBuildGrpcStatusResponse(responseObserver, StatusResponse.newBuilder(), "Contact info was not removed from account {}.", request.getAccountId(), - Cause.ERROR_REMOVING_CONTACT_INFO); + Cause.ERROR_DELETING_CONTACT_INFO); return; } @@ -639,7 +639,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (request.getAuthenticationProvider().getAuthenticationProvider() == null || request.getAuthenticationProvider().getAuthenticationProvider().isEmpty()) { logAndBuildGrpcStatusResponse(responseObserver, StatusResponse.newBuilder(), "Missing auth provider id.", - "", Cause.MISSING_AUTH_PROVIDER_IDENTIFIER); + "", Cause.MISSING_AUTH_PROVIDER_ID); return; } diff --git a/src/test/java/biz/nynja/account/components/ValidatorTests.java b/src/test/java/biz/nynja/account/components/ValidatorTests.java index e5bc6654112bbfa3643df667551d14a7d45ae4ff..737d5d86bb28324f6802ae915de765f4a9a223aa 100644 --- a/src/test/java/biz/nynja/account/components/ValidatorTests.java +++ b/src/test/java/biz/nynja/account/components/ValidatorTests.java @@ -173,13 +173,13 @@ public class ValidatorTests { @Test public void validateAuthProviderInvalidTest() { assertEquals(validator.validateAuthProvider(AuthenticationType.EMAIL, "invalid.E-mail1.@domain_test.com1"), - Cause.EMAIL_INVALID); + Cause.INVALID_EMAIL); } @Test public void validateAuthProviderEmptyProviderIdentifierTest() { assertEquals(validator.validateAuthProvider(AuthenticationType.EMAIL, null), - Cause.MISSING_AUTH_PROVIDER_IDENTIFIER); + Cause.MISSING_AUTH_PROVIDER_ID); } @Test @@ -190,19 +190,19 @@ public class ValidatorTests { @Test public void validateAuthProviderInvalidPhoneNoDotsTest() { assertEquals(validator.validateAuthProvider(AuthenticationType.PHONE, "BG+359881111111"), - Cause.PHONE_NUMBER_INVALID); + Cause.INVALID_PHONENUMBER); } @Test public void validateAuthProviderInvalidPhoneManyDotsTest() { assertEquals(validator.validateAuthProvider(AuthenticationType.PHONE, "BG:+359:879555555"), - Cause.PHONE_NUMBER_INVALID); + Cause.INVALID_PHONENUMBER); } @Test public void validateAuthProviderInvalidPhoneWrongCountryTest() { assertEquals(validator.validateAuthProvider(AuthenticationType.PHONE, "BdasG:+359883456789"), - Cause.PHONE_NUMBER_INVALID); + Cause.INVALID_PHONENUMBER); } @Test @@ -218,7 +218,7 @@ public class ValidatorTests { CompletePendingAccountCreationRequest request = CompletePendingAccountCreationRequest.newBuilder() .setAccountId(Util.ACCOUNT_ID.toString()).setFirstName(Util.FIRST_NAME).setLastName(Util.LAST_NAME) .setUsername("@alabala").build(); - assertEquals(Cause.USERNAME_INVALID, + assertEquals(Cause.INVALID_USERNAME, pendingAccountValidator.validateCompletePendingAccountCreationRequest(request)); } @@ -243,7 +243,7 @@ public class ValidatorTests { CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder() .setAuthenticationType(AuthenticationType.EMAIL) .setAuthenticationProvider("invalid.E-mail1.@domain_test.com1").build(); - assertEquals(Cause.EMAIL_INVALID, pendingAccountValidator.validateCreatePendingAccountRequest(request)); + assertEquals(Cause.INVALID_EMAIL, pendingAccountValidator.validateCreatePendingAccountRequest(request)); } } diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 47b99fafede44b6d4f2f062f8f108cc5b8b976fe..069e24c28679e7cf93b6877102312a36e5d57f99 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -372,8 +372,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_AUTH_PROVIDER_IDENTIFIER), - reply.getError().getCause().equals(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_AUTH_PROVIDER_ID), + reply.getError().getCause().equals(Cause.MISSING_AUTH_PROVIDER_ID)); } @Test @@ -512,8 +512,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final CreatePendingAccountResponse reply = accountServiceBlockingStub.createPendingAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), - reply.getError().getCause().equals(Cause.EMAIL_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), + reply.getError().getCause().equals(Cause.INVALID_EMAIL)); } @Test @@ -525,8 +525,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final CreatePendingAccountResponse reply = accountServiceBlockingStub.createPendingAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_INVALID), - reply.getError().getCause().equals(Cause.PHONE_NUMBER_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_PHONENUMBER), + reply.getError().getCause().equals(Cause.INVALID_PHONENUMBER)); } @Test @@ -591,8 +591,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final AccountResponse respose = accountServiceBlockingStub.completePendingAccountCreation(request); assertNotNull("Reply should not be null", respose); - assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_INVALID), - respose.getError().getCause().equals(Cause.USERNAME_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_USERNAME), + respose.getError().getCause().equals(Cause.INVALID_USERNAME)); } @Test @@ -837,8 +837,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.addAuthenticationProviderToProfile(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_AUTH_PROVIDER_IDENTIFIER), - reply.getError().getCause().equals(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_AUTH_PROVIDER_ID), + reply.getError().getCause().equals(Cause.MISSING_AUTH_PROVIDER_ID)); } @Test @@ -1056,8 +1056,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final StatusResponse reply = accountServiceBlockingStub.addContactInfoToAccount(request); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_CONTACT_INFO_IDENTIFIER), - reply.getError().getCause().equals(Cause.MISSING_CONTACT_INFO_IDENTIFIER)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_CONTACT_INFO_ID), + reply.getError().getCause().equals(Cause.MISSING_CONTACT_INFO_ID)); } @Test @@ -1073,8 +1073,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.addContactInfoToAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_INVALID), - reply.getError().getCause().equals(Cause.PHONE_NUMBER_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_PHONENUMBER), + reply.getError().getCause().equals(Cause.INVALID_PHONENUMBER)); } @Test @@ -1089,8 +1089,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.addContactInfoToAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), - reply.getError().getCause().equals(Cause.EMAIL_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), + reply.getError().getCause().equals(Cause.INVALID_EMAIL)); } @Test @@ -1202,8 +1202,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final StatusResponse reply = accountServiceBlockingStub.deleteContactInfoFromAccount(request); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_CONTACT_INFO_IDENTIFIER), - reply.getError().getCause().equals(Cause.MISSING_CONTACT_INFO_IDENTIFIER)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_CONTACT_INFO_ID), + reply.getError().getCause().equals(Cause.MISSING_CONTACT_INFO_ID)); } @Test @@ -1219,8 +1219,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.deleteContactInfoFromAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_INVALID), - reply.getError().getCause().equals(Cause.PHONE_NUMBER_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_PHONENUMBER), + reply.getError().getCause().equals(Cause.INVALID_PHONENUMBER)); } @Test @@ -1235,8 +1235,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.deleteContactInfoFromAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), - reply.getError().getCause().equals(Cause.EMAIL_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), + reply.getError().getCause().equals(Cause.INVALID_EMAIL)); } @Test @@ -1254,8 +1254,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.deleteContactInfoFromAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.ERROR_REMOVING_CONTACT_INFO), - reply.getError().getCause().equals(Cause.ERROR_REMOVING_CONTACT_INFO)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ERROR_DELETING_CONTACT_INFO), + reply.getError().getCause().equals(Cause.ERROR_DELETING_CONTACT_INFO)); } @Test @@ -1361,8 +1361,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final StatusResponse reply = accountServiceBlockingStub.editContactInfoForAccount(request); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_CONTACT_INFO_IDENTIFIER), - reply.getError().getCause().equals(Cause.MISSING_CONTACT_INFO_IDENTIFIER)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_CONTACT_INFO_ID), + reply.getError().getCause().equals(Cause.MISSING_CONTACT_INFO_ID)); } @Test @@ -1380,8 +1380,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.editContactInfoForAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_INVALID), - reply.getError().getCause().equals(Cause.PHONE_NUMBER_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_PHONENUMBER), + reply.getError().getCause().equals(Cause.INVALID_PHONENUMBER)); } @Test @@ -1399,8 +1399,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final StatusResponse reply = accountServiceBlockingStub.editContactInfoForAccount(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), - reply.getError().getCause().equals(Cause.EMAIL_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), + reply.getError().getCause().equals(Cause.INVALID_EMAIL)); } @Test @@ -1519,8 +1519,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_INVALID), - reply.getError().getCause().equals(Cause.USERNAME_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_USERNAME), + reply.getError().getCause().equals(Cause.INVALID_USERNAME)); } @Test @@ -1654,8 +1654,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), - reply.getError().getCause().equals(Cause.EMAIL_INVALID)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), + reply.getError().getCause().equals(Cause.INVALID_EMAIL)); } @Test