diff --git a/src/main/java/biz/nynja/account/StartupScriptsListener.java b/src/main/java/biz/nynja/account/StartupScriptsListener.java index d008aa14d4ab26c435d29af7ed35ede30434c637..fb650abfe51de4d10999384627dfd4be359ba7b8 100644 --- a/src/main/java/biz/nynja/account/StartupScriptsListener.java +++ b/src/main/java/biz/nynja/account/StartupScriptsListener.java @@ -52,7 +52,11 @@ public class StartupScriptsListener { + ".accountbyusername AS SELECT * FROM account " + "WHERE username IS NOT NULL " + "PRIMARY KEY (username, accountid);"; + String scriptPendingAccountViewByAuthenticationProvider = "CREATE MATERIALIZED VIEW IF NOT EXISTS " + keyspace + + ".pendingaccountbyauthenticationprovider AS SELECT * FROM pending_account " + "WHERE authentication_provider IS NOT NULL " + + "PRIMARY KEY (authentication_provider, account_id);"; + return Arrays.asList(scriptAccountViewByProfileId, scriptAccountViewByAuthProvider, - scriptAccountViewByАccountName, scriptAccountViewByUsername); + scriptAccountViewByАccountName, scriptAccountViewByUsername, scriptPendingAccountViewByAuthenticationProvider); } } \ No newline at end of file diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index 4f114334cd74b24cda08f114bee605fa351776b3..8bffbe0c9730c69f8bcd4290e450a4ab197c912d 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -27,6 +27,7 @@ import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.CreatePendingAccountRequest; import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.grpc.UpdateAccountRequest; +import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.CountryInfo; import biz.nynja.account.repositories.AccountRepositoryAdditional; @@ -257,10 +258,6 @@ public class Validator { if (request.getUsername() != null && !request.getUsername().trim().isEmpty() && !isUsernameValid(request.getUsername())) { return Cause.USERNAME_INVALID; - } else if (request.getUsername() != null && !request.getUsername().trim().isEmpty() - && accountRepositoryAdditional.foundExistingNotOwnUsername(UUID.fromString(request.getAccountId()), - request.getUsername())) { - return Cause.USERNAME_ALREADY_USED; } if (request.getFirstName() != null && request.getFirstName().trim().isEmpty()) { @@ -274,7 +271,28 @@ public class Validator { return Cause.INVALID_LAST_NAME; } + for (AuthProviderDetails details : request.getCommunicationProvidersList()) { + Cause cause = validateAuthProvider(details.getAuthenticationType(), details.getAuthenticationProvider()); + if (cause != null) { + return cause; + } + } + + if (request.getAccountName() != null && !request.getAccountName().trim().isEmpty() + && !isAccountNameValid(request.getAccountName())) { + return Cause.ACCOUNT_NAME_INVALID; + } + return null; } + public Cause validateUpdateProfileRequest(UpdateProfileRequest request) { + for (AuthProviderDetails details : request.getAuthProvidersList()) { + Cause cause = validateAuthProvider(details.getAuthenticationType(), details.getAuthenticationProvider()); + if (cause != null) { + return cause; + } + } + return null; + } } diff --git a/src/main/java/biz/nynja/account/models/PendingAccountByAuthenticationProvider.java b/src/main/java/biz/nynja/account/models/PendingAccountByAuthenticationProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..8c3dcdca5b4d8df5e9256ead344d88c0156cd10a --- /dev/null +++ b/src/main/java/biz/nynja/account/models/PendingAccountByAuthenticationProvider.java @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.models; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.mapping.Column; + +public class PendingAccountByAuthenticationProvider { + @Column("account_id") + private UUID accountId; + @Column("profile_id") + private UUID profileId; + @Column("authentication_provider") + private String authenticationProvider; + @Column("authentication_provider_type") + private String authenticationProviderType; + @Column("creation_timestamp") + private Long creationTimestamp; + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public String getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(String authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + public String getAuthenticationProviderType() { + return authenticationProviderType; + } + + public void setAuthenticationProviderType(String authenticationProviderType) { + this.authenticationProviderType = authenticationProviderType; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PendingAccountByAuthenticationProvider other = (PendingAccountByAuthenticationProvider) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (authenticationProvider == null) { + if (other.authenticationProvider != null) + return false; + } else if (!authenticationProvider.equals(other.authenticationProvider)) + return false; + if (authenticationProviderType == null) { + if (other.authenticationProviderType != null) + return false; + } else if (!authenticationProviderType.equals(other.authenticationProviderType)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("PendingAccounts [accountId=").append(accountId).append(", profileId=") + .append(profileId).append(", authenticationProvider=").append(authenticationProvider) + .append(", authenticationProviderType=").append(authenticationProviderType) + .append(", creationTimestamp=").append(creationTimestamp).append("]").toString(); + } + +} diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java index 099850881e2166caac0492a7d79f478ba075d2d1..8ab93a2a4edaa5a1d905fdfa5fcad9d200df6316 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java @@ -11,6 +11,8 @@ import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.UpdateAccountRequest; import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; +import biz.nynja.account.models.AuthenticationProvider; +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.models.Profile; @Repository @@ -24,4 +26,8 @@ public interface AccountRepositoryAdditional { boolean foundExistingNotOwnUsername(UUID accountId, String username); + PendingAccountByAuthenticationProvider findSameAuthenticationProviderInPendingAccount(AuthenticationProvider authProvider); + + boolean authenticationProviderAlreadyUsedInAccount(AuthenticationProvider authProvider); + } diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 760f2c1a380b3195230ef4a081556609ba8100c9..c1b1f0efa6e54b59fdfcfe6d677b2fce17e7b9df 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -5,6 +5,7 @@ package biz.nynja.account.repositories; import java.util.Date; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -22,10 +23,12 @@ import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.UpdateAccountRequest; import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; +import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByCommunicationProvider; import biz.nynja.account.models.AccountByUsername; import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.PendingAccount; +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.models.Profile; import biz.nynja.account.models.ProfileByAuthenticationProvider; @@ -49,6 +52,15 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio @Autowired AccountByUsernameRepository accountByUsernameRepository; + @Autowired + AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; + + @Autowired + ProfileByAuthenticationProviderRepository profileByAuthenticationProviderRepository; + + @Autowired + PendingAccountByAuthenticationProviderRepository pendingAccountByAuthenticationProviderRepository; + @Autowired private PendingAccountRepository pendingAccountRepository; @@ -65,6 +77,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio Long checkMinutes = timeCreated - pendingAccount.getCreationTimestamp(); if (checkMinutes > COMPLETE_PENDING_ACCOUNT_TIMEOUT_IN_MINUTES * 60 * 1000) { logger.info("Account creation timeout expired."); + pendingAccountRepository.deleteById(UUID.fromString(request.getAccountId())); return null; } WriteResult wr = null; @@ -415,4 +428,39 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } } + public PendingAccountByAuthenticationProvider findSameAuthenticationProviderInPendingAccount(AuthenticationProvider authProvider) { + List pendingAccounts = pendingAccountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(authProvider.getValue()); + if (pendingAccounts.isEmpty()) { + return null; + } + + //Both authentication provider identifier and type uniquely identify the authentication provider in DB. + //For this reason we need to filter results by authentication provider type. + for (PendingAccountByAuthenticationProvider pendingAccount : pendingAccounts) { + if (pendingAccount.getAuthenticationProviderType().equals(authProvider.getType())) { + return pendingAccount; + } + } + return null; + } + + public boolean authenticationProviderAlreadyUsedInAccount(AuthenticationProvider authProvider) { + List accounts = accountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(authProvider.getValue()); + + if (accounts.isEmpty()) { + return false; + } + + //Both authentication provider identifier and type uniquely identify the authentication provider in DB. + //For this reason we need to filter results by authentication provider type. + for (AccountByAuthenticationProvider account : accounts) { + if (account.getAuthenticationProviderType().equals(authProvider.getType())) { + return true; + } + } + return false; + } + } diff --git a/src/main/java/biz/nynja/account/repositories/PendingAccountByAuthenticationProviderRepository.java b/src/main/java/biz/nynja/account/repositories/PendingAccountByAuthenticationProviderRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..7648c4bb0c5c5b64e44098549706d278af804025 --- /dev/null +++ b/src/main/java/biz/nynja/account/repositories/PendingAccountByAuthenticationProviderRepository.java @@ -0,0 +1,18 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.repositories; + +import java.util.List; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; + +@Repository +public interface PendingAccountByAuthenticationProviderRepository extends CassandraRepository { + + List findAllByAuthenticationProvider(String authenticationProvider); + +} diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index e2a85fed72039fbaca70cbca8f1afceec1fa552d..7aede542969b47fd3f30ada47644eb7a251a29ba 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -31,12 +31,15 @@ import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.PendingAccount; +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.models.Profile; import biz.nynja.account.repositories.AccountByProfileIdRepository; import biz.nynja.account.repositories.AccountRepository; import biz.nynja.account.repositories.AccountRepositoryAdditional; +import biz.nynja.account.repositories.PendingAccountByAuthenticationProviderRepository; import biz.nynja.account.repositories.PendingAccountRepository; import biz.nynja.account.grpc.AccountsResponse; import biz.nynja.account.grpc.UpdateAccountRequest; @@ -67,6 +70,9 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas @Autowired private PendingAccountRepository pendingAccountRepository; + @Autowired + private PendingAccountByAuthenticationProviderRepository pendingAccountByAuthenticationProviderRepository; + @Autowired private AccountRepositoryAdditional accountRepositoryAdditional; @@ -223,7 +229,40 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + PendingAccountByAuthenticationProvider foundExistingPendingAccount = accountRepositoryAdditional + .findSameAuthenticationProviderInPendingAccount( + AuthenticationProvider.createAuthenticationProviderFromStrings( + request.getAuthenticationType().name(), request.getAuthenticationProvider())); + + PendingAccount updatedPendingAccount = new PendingAccount(); + + if (foundExistingPendingAccount != null) { + updatedPendingAccount.setAccountId(foundExistingPendingAccount.getAccountId()); + updatedPendingAccount.setProfileId(foundExistingPendingAccount.getProfileId()); + updatedPendingAccount.setAuthenticationProvider(foundExistingPendingAccount.getAuthenticationProvider()); + updatedPendingAccount + .setAuthenticationProviderType(foundExistingPendingAccount.getAuthenticationProviderType()); + updatedPendingAccount.setCreationTimestamp(new Date().getTime()); + + PendingAccount updatePendingAccount = pendingAccountRepository.save(updatedPendingAccount); + CreatePendingAccountResponse response = CreatePendingAccountResponse.newBuilder() + .setPendingAccountDetails(updatePendingAccount.toProto()).build(); + responseObserver.onNext(response); + responseObserver.onCompleted(); + return; + } + + if (accountRepositoryAdditional.authenticationProviderAlreadyUsedInAccount( + AuthenticationProvider.createAuthenticationProviderFromStrings(request.getAuthenticationType().name(), + request.getAuthenticationProvider()))) { + responseObserver.onNext(CreatePendingAccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_ALREADY_CREATED)).build()); + responseObserver.onCompleted(); + return; + } + PendingAccount pendingAccount = PendingAccount.fromProto(request); + pendingAccount.setAccountId(UUID.randomUUID()); pendingAccount.setProfileId(UUID.randomUUID()); pendingAccount.setCreationTimestamp(new Date().getTime()); @@ -256,6 +295,15 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + if (request.getUsername() != null && !request.getUsername().trim().isEmpty() + && accountRepositoryAdditional.foundExistingNotOwnUsername(UUID.fromString(request.getAccountId()), + request.getUsername())) { + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.USERNAME_ALREADY_USED)).build()); + responseObserver.onCompleted(); + return; + } + Account createdAccount = accountRepositoryAdditional.completePendingAccountCreation(request); if (createdAccount == null) { @@ -295,6 +343,14 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + Cause cause = validator.validateUpdateProfileRequest(request); + if (cause != null) { + responseObserver + .onNext(UpdateProfileResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); + responseObserver.onCompleted(); + return; + } + Profile updatedProfile = accountRepositoryAdditional.updateProfile(request); if (updatedProfile == null) { @@ -332,6 +388,15 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + if (request.getUsername() != null && !request.getUsername().trim().isEmpty() + && accountRepositoryAdditional.foundExistingNotOwnUsername(UUID.fromString(request.getAccountId()), + request.getUsername())) { + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.USERNAME_ALREADY_USED)).build()); + responseObserver.onCompleted(); + return; + } + Account updatedAccount = accountRepositoryAdditional.updateAccount(request); if (updatedAccount == null) { diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index fefb2ba4ddbfcbfef45cc38dffa140edbc45fada..96c314bcb524811602d60ddd0ce46ab296b0e2bb 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -45,6 +45,9 @@ import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.models.AuthenticationProvider; +import biz.nynja.account.models.PendingAccount; +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.models.Profile; import biz.nynja.account.repositories.AccountByProfileIdRepository; import biz.nynja.account.repositories.AccountRepository; @@ -90,6 +93,14 @@ public class AccountServiceTests extends GrpcServerTestBase { @Qualifier("savedPendingAccount") private PendingAccount pendingAccount; + @Autowired + @Qualifier("existingPendingAccount") + private PendingAccount existingPendingAccount; + + @Autowired + @Qualifier("existingPendingAccountByAuthenticationProvider") + private PendingAccountByAuthenticationProvider existingPendingAccountByAuthenticationProvider; + @Autowired @Qualifier("savedAccount") private Account savedAccount; @@ -375,6 +386,39 @@ public class AccountServiceTests extends GrpcServerTestBase { reply.getError().getCause().equals(Cause.USERNAME_ALREADY_USED)); } + @Test + public void testCreatePendingAccountAuthProviderAlreadyUsedInPendingAccount() { + final CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder() + .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationProvider(Util.EMAIL).build(); + given(accountRepositoryAdditional + .findSameAuthenticationProviderInPendingAccount( + AuthenticationProvider.createAuthenticationProviderFromStrings( + request.getAuthenticationType().name(), request.getAuthenticationProvider()))).willReturn(existingPendingAccountByAuthenticationProvider); + given(pendingAccountRepository.save(Mockito.any(PendingAccount.class))).willReturn(existingPendingAccount); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .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 account id '%s'", Util.ACCOUNT_ID), + reply.getPendingAccountDetails().getAccountId().equals(Util.ACCOUNT_ID.toString())); + } + + @Test + public void testCreatePendingAccountAuthProviderAlreadyUsedInAccount() { + final CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder() + .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationProvider(Util.EMAIL).build(); + given(accountRepositoryAdditional + .authenticationProviderAlreadyUsedInAccount( + AuthenticationProvider.createAuthenticationProviderFromStrings( + request.getAuthenticationType().name(), request.getAuthenticationProvider()))).willReturn(true); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .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 account id '%s'", Cause.ACCOUNT_ALREADY_CREATED), + reply.getError().getCause().equals(Cause.ACCOUNT_ALREADY_CREATED)); + } + @Test public void testUpdateProfileAddBackupAuthProvider() throws ExecutionException, InterruptedException { final UpdateProfileRequest request = UpdateProfileRequest.newBuilder().setProfileId(Util.PROFILE_ID.toString()) @@ -523,6 +567,21 @@ public class AccountServiceTests extends GrpcServerTestBase { respose.getError().getCause().equals(Cause.MISSING_FIRST_NAME)); } + @Test + public void testCompletePendingAccountCreationUsernameAlreadyUsed() { + final CompletePendingAccountCreationRequest request = CompletePendingAccountCreationRequest.newBuilder() + .setAccountId(Util.ACCOUNT_ID.toString()).setAccountMark(Util.UPDATED_ACCOUNT_MARK) + .setFirstName(Util.FIRST_NAME).setUsername(Util.USERNAME).build(); + given(accountRepositoryAdditional.foundExistingNotOwnUsername(UUID.fromString(request.getAccountId()), + request.getUsername())).willReturn(true); + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + final AccountResponse reply = accountServiceBlockingStub.completePendingAccountCreation(request); + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_ALREADY_USED), + reply.getError().getCause().equals(Cause.USERNAME_ALREADY_USED)); + } + @Test public void testCompletePendingAccountCreationInvalidLastName() { final CompletePendingAccountCreationRequest request = CompletePendingAccountCreationRequest.newBuilder() diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 9f56e4ba49199ecaa127b810270b90411836b3a1..afbb24fb876b884f71dea409ff3cf3bba2b5d827 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -19,6 +19,7 @@ import biz.nynja.account.models.AccountByProfileId; import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.Profile; import biz.nynja.account.models.PendingAccount; +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; /** * Unit tests variables, beans and help methods. @@ -38,6 +39,7 @@ public class Util { public static final String ACCOUNT_NAME = "AccountName"; public static final String ACCOUNT_STATUS = "active"; public static final long CREATION_TIMESTAMP = 45; + public static final long EXISTING_PENDING_ACCOUNT_TIMESTAMP_UPDATED = 65; public static final long LAST_UPDATE_TIMESTAMP = 80; public static final Set COMMUNICATION_PROVIDERS = new HashSet(); public static final String QR_CODE = "QRcode"; @@ -172,6 +174,29 @@ public class Util { account.setProfileId(PROFILE_ID); account.setAuthenticationProvider(EMAIL); account.setAuthenticationProviderType(EMAIL_TYPE); + account.setCreationTimestamp(CREATION_TIMESTAMP); return account; } + + @Bean + public PendingAccount existingPendingAccount() { + PendingAccount pendingAccount = new PendingAccount(); + pendingAccount.setAccountId(ACCOUNT_ID); + pendingAccount.setProfileId(PROFILE_ID); + pendingAccount.setAuthenticationProvider(EMAIL); + pendingAccount.setAuthenticationProviderType(EMAIL_TYPE); + pendingAccount.setCreationTimestamp(EXISTING_PENDING_ACCOUNT_TIMESTAMP_UPDATED); + return pendingAccount; + } + + @Bean + public PendingAccountByAuthenticationProvider existingPendingAccountByAuthenticationProvider() { + PendingAccountByAuthenticationProvider pendingAccount = new PendingAccountByAuthenticationProvider(); + pendingAccount.setAccountId(ACCOUNT_ID); + pendingAccount.setProfileId(PROFILE_ID); + pendingAccount.setAuthenticationProvider(EMAIL); + pendingAccount.setAuthenticationProviderType(EMAIL_TYPE); + pendingAccount.setCreationTimestamp(EXISTING_PENDING_ACCOUNT_TIMESTAMP_UPDATED); + return pendingAccount; + } }