From 028ffacb6d8fca6a1d9983b5a92809b5529cf29c Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Thu, 8 Nov 2018 18:39:44 +0200 Subject: [PATCH 1/4] NY-5010: Unit tests for updating auth provider - added unit tests for updating auth provider; - fixed unit test for edit contact info. Signed-off-by: Stanimir Penkov --- .../account/services/AccountServiceTests.java | 155 +++++++++++++++++- .../java/biz/nynja/account/utils/Util.java | 1 + 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 202a8b4..a7c1361 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -66,6 +66,7 @@ import biz.nynja.account.grpc.Role; import biz.nynja.account.grpc.SearchResponse; import biz.nynja.account.grpc.StatusResponse; import biz.nynja.account.grpc.UpdateAccountRequest; +import biz.nynja.account.grpc.UpdateAuthenticationProviderRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; @@ -1420,7 +1421,7 @@ public class AccountServiceTests extends GrpcServerTestBase { .setEditedContactInfo(ContactDetails.newBuilder().setType(ContactType.EMAIL_CONTACT) .setValue(Util.EMAIL_EDITED).build()) .build(); - given(accountRepositoryAdditional.addContactInfo(Mockito.any(UUID.class), Mockito.any(ContactInfo.class))) + given(accountRepositoryAdditional.editContactInfo(Mockito.any(UUID.class), Mockito.any(ContactInfo.class), Mockito.any(ContactInfo.class))) .willReturn(false); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc @@ -1770,4 +1771,156 @@ public class AccountServiceTests extends GrpcServerTestBase { reply.getError().getCause().equals(Cause.MISSING_PROFILE_ID)); } + @Test + public void testUpdateAuthProviderPhoneForProfileOK() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER_EDITED).build()) + .build(); + given(accountRepositoryAdditional.updateAuthenticationProvider(Mockito.any(UUID.class), + Mockito.any(AuthenticationProvider.class), Mockito.any(AuthenticationProvider.class))).willReturn(true); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertNotNull("Reply should not be null", reply); + assertEquals("SUCCESS", reply.getStatus()); + } + + @Test + public void testUpdateAuthProviderEmailForProfileOK() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.EMAIL) + .setAuthenticationProvider(Util.EMAIL).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.EMAIL) + .setAuthenticationProvider(Util.EMAIL_EDITED).build()) + .build(); + given(accountRepositoryAdditional.updateAuthenticationProvider(Mockito.any(UUID.class), + Mockito.any(AuthenticationProvider.class), Mockito.any(AuthenticationProvider.class))).willReturn(true); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertNotNull("Reply should not be null", reply); + assertEquals("SUCCESS", reply.getStatus()); + } + + @Test + public void testUpdateAuthProviderForProfileErrorUpdatingAuthProvider() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER_EDITED).build()) + .build(); + given(accountRepositoryAdditional.updateAuthenticationProvider(Mockito.any(UUID.class), + Mockito.any(AuthenticationProvider.class), Mockito.any(AuthenticationProvider.class))) + .willReturn(false); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ERROR_UPDATING_AUTH_PROVIDER), + reply.getError().getCause().equals(Cause.ERROR_UPDATING_AUTH_PROVIDER)); + } + + @Test + public void testUpdateAuthProviderForProfileInvalidProfileId() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.INVALID_PROFILE_ID) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER_EDITED).build()) + .build(); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_PROFILE_ID), + reply.getError().getCause().equals(Cause.INVALID_PROFILE_ID)); + } + + @Test + public void testUpdateAuthProviderForProfileMissingProfileId() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER_EDITED).build()) + .build(); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_PROFILE_ID), + reply.getError().getCause().equals(Cause.MISSING_PROFILE_ID)); + } + + @Test + public void testUpdateAuthProviderForProfileMissingAuthProviderType() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER).build()) + .setUpdatedAuthProvider( + AuthProviderDetails.newBuilder().setAuthenticationProvider(Util.PHONE_PROVIDER_EDITED).build()) + .build(); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_AUTH_PROVIDER_TYPE), + reply.getError().getCause().equals(Cause.MISSING_AUTH_PROVIDER_TYPE)); + } + + @Test + public void testUpdateAuthProviderForProfileMissingAuthProviderIdentifier() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider( + AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER_EDITED).build()) + .build(); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_AUTH_PROVIDER_IDENTIFIER), + reply.getError().getCause().equals(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)); + } + + @Test + public void testUpdateAuthProviderForProfileInvalidPhone() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.PHONE_PROVIDER).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.PHONE) + .setAuthenticationProvider(Util.INVALID_PHONE_PROVIDER).build()) + .build(); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(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)); + } + + @Test + public void testUpdateAuthProviderForProfileInvalidEmail() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.EMAIL) + .setAuthenticationProvider(Util.EMAIL).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.EMAIL) + .setAuthenticationProvider(Util.INVALID_EMAIL).build()) + .build(); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(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)); + } } diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 3eeade4..1ae6d9c 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -40,6 +40,7 @@ public class Util { public static final UUID ACCOUNT_ID_NOT_FOUND = UUID.fromString("44532732-12b3-132d-e156-223732152202"); public static final UUID PROFILE_ID_NOT_FOUND = UUID.fromString("12352345-e89b-43d3-d156-456732452202"); public static final String INVALID_ACCOUNT_ID = "111-222"; + public static final String INVALID_PROFILE_ID = "222-333"; public static final String ACCOUNT_MARK = "AccountMark"; public static final String UPDATED_ACCOUNT_MARK = "PRIVATE"; public static final String AUTHENTICATION_PROVIDER = "Provider"; -- GitLab From d0cf9f1224f287514e6cbca0a0943b2b2a15fb42 Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Fri, 16 Nov 2018 17:44:57 +0200 Subject: [PATCH 2/4] NY-5010: One more unit test added Signed-off-by: Stanimir Penkov --- .../account/services/AccountServiceTests.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index a7c1361..040284d 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -1827,6 +1827,33 @@ public class AccountServiceTests extends GrpcServerTestBase { reply.getError().getCause().equals(Cause.ERROR_UPDATING_AUTH_PROVIDER)); } + @Test + public void testUpdateAuthProviderEmailForProfileAuthProviderUsed() { + final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()) + .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.EMAIL) + .setAuthenticationProvider(Util.EMAIL).build()) + .setUpdatedAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationType(AuthenticationType.EMAIL) + .setAuthenticationProvider(Util.EMAIL_EDITED).build()) + .build(); + + given(profileRepository.findByProfileId(Util.PROFILE_ID)).willReturn(profile1AuthProvider); + given(accountRepositoryAdditional + .authenticationProviderAlreadyUsedInAccount(Mockito.any(AuthenticationProvider.class))) + .willReturn(true); + given(accountRepositoryAdditional.updateAuthenticationProvider(Mockito.any(UUID.class), + Mockito.any(AuthenticationProvider.class), Mockito.any(AuthenticationProvider.class))) + .willReturn(false); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.ERROR_UPDATING_AUTH_PROVIDER), + reply.getError().getCause().equals(Cause.ERROR_UPDATING_AUTH_PROVIDER)); + } + @Test public void testUpdateAuthProviderForProfileInvalidProfileId() { final UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() -- GitLab From bd7cd16c5d99969c26cef3a4b6e2617db4bde3a8 Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Tue, 20 Nov 2018 14:41:16 +0200 Subject: [PATCH 3/4] NY-5010: Updated Causes Signed-off-by: Stanimir Penkov --- .../nynja/account/services/AccountServiceTests.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 040284d..8b36171 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -1913,8 +1913,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); - 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 @@ -1930,8 +1930,8 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(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 @@ -1947,7 +1947,7 @@ public class AccountServiceTests extends GrpcServerTestBase { .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final StatusResponse reply = accountServiceBlockingStub.updateAuthenticationProviderForProfile(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)); } } -- GitLab From e5a5203e5ab066e7269240c800ec81aa85e54b4f Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Tue, 20 Nov 2018 15:07:28 +0200 Subject: [PATCH 4/4] NY-5010: Updated info when logging error Signed-off-by: Stanimir Penkov --- .../account/repositories/AccountRepositoryAdditionalImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index d3e18c0..265d52f 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -491,7 +491,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio return false; } if (authenticationProviderAlreadyUsedInProfile(updatedAuthProvider)) { - logger.error("The requested update auth provider for profile {} is already used.", profileId); + logger.error("The requested update auth provider {}:{} for profile {} is already used.", updatedAuthProvider.getType(), updatedAuthProvider.getValue(), profileId); return false; } -- GitLab