diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index cccc9de5563e1c3ec5a1e8c306bc951cc7393168..d8fdc753639e03bd41f00054c4c3423a4b6d864e 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -23,9 +23,6 @@ import org.springframework.stereotype.Component; import biz.nynja.account.grpc.CreateAccountRequest; import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.models.CountryInfo; -import biz.nynja.account.repositories.UserInfoByEmailRepository; -import biz.nynja.account.repositories.UserInfoByPhoneRepository; -import biz.nynja.account.repositories.UserInfoByUsernameRepository; /** * Component which contains all validation methods. @@ -38,15 +35,6 @@ public class Validator { private HashMap countryInfoMap; - @Autowired - private UserInfoByEmailRepository userInfoByEmailRepository; - - @Autowired - private UserInfoByPhoneRepository userInfoByPhoneRepository; - - @Autowired - private UserInfoByUsernameRepository userInfoByUsernameRepository; - @PostConstruct public void loadPhonesBook() { @@ -169,44 +157,44 @@ public class Validator { return isValid; } - public Cause validateCreateAccountRequest(CreateAccountRequest request) { - - if (request.getUsername() != null && !request.getUsername().trim().isEmpty() - && !isUsernameValid(request.getUsername())) { - return Cause.USERNAME_INVALID; - } else if (request.getUsername() != null && !request.getUsername().trim().isEmpty() - && !userInfoByUsernameRepository.findByUsername(request.getUsername()).isEmpty()) { - return Cause.USERNAME_ALREADY_USED; - } - - if (request.getEmailAddress() != null && !request.getEmailAddress().trim().isEmpty() - && !isEmailValid(request.getEmailAddress())) { - return Cause.EMAIL_INVALID; - } else if (request.getEmailAddress() != null && !request.getEmailAddress().trim().isEmpty() - && !userInfoByEmailRepository.findByEmailAddress(request.getEmailAddress()).isEmpty()) { - return Cause.EMAIL_ALREADY_USED; - } - - if (request.getPhoneNumber() != null && !request.getPhoneNumber().trim().isEmpty() - && !isPhoneNumberValid(request.getPhoneNumber(), request.getCountryCode())) { - return Cause.PHONE_NUMBER_INVALID; - } else if (request.getPhoneNumber() != null && !request.getPhoneNumber().trim().isEmpty() - && !userInfoByPhoneRepository.findByPhoneNumber(request.getPhoneNumber()).isEmpty()) { - return Cause.PHONE_NUMBER_ALREADY_USED; - } - - if (request.getFirstName() != null && request.getFirstName().trim().isEmpty()) { - return Cause.MISSING_FIRST_NAME; - } else if (!isFirstNameValid(request.getFirstName())) { - return Cause.INVALID_FIRST_NAME; - } - - if (request.getLastName() != null && !request.getLastName().trim().isEmpty() - && !isLastNameValid(request.getLastName())) { - return Cause.INVALID_LAST_NAME; - } - - return null; - } +// public Cause validateCreateAccountRequest(CreateAccountRequest request) { +// +// if (request.getUsername() != null && !request.getUsername().trim().isEmpty() +// && !isUsernameValid(request.getUsername())) { +// return Cause.USERNAME_INVALID; +// } else if (request.getUsername() != null && !request.getUsername().trim().isEmpty() +// && !userInfoByUsernameRepository.findByUsername(request.getUsername()).isEmpty()) { +// return Cause.USERNAME_ALREADY_USED; +// } +// +// if (request.getEmailAddress() != null && !request.getEmailAddress().trim().isEmpty() +// && !isEmailValid(request.getEmailAddress())) { +// return Cause.EMAIL_INVALID; +// } else if (request.getEmailAddress() != null && !request.getEmailAddress().trim().isEmpty() +// && !userInfoByEmailRepository.findByEmailAddress(request.getEmailAddress()).isEmpty()) { +// return Cause.EMAIL_ALREADY_USED; +// } +// +// if (request.getPhoneNumber() != null && !request.getPhoneNumber().trim().isEmpty() +// && !isPhoneNumberValid(request.getPhoneNumber(), request.getCountryCode())) { +// return Cause.PHONE_NUMBER_INVALID; +// } else if (request.getPhoneNumber() != null && !request.getPhoneNumber().trim().isEmpty() +// && !userInfoByPhoneRepository.findByPhoneNumber(request.getPhoneNumber()).isEmpty()) { +// return Cause.PHONE_NUMBER_ALREADY_USED; +// } +// +// if (request.getFirstName() != null && request.getFirstName().trim().isEmpty()) { +// return Cause.MISSING_FIRST_NAME; +// } else if (!isFirstNameValid(request.getFirstName())) { +// return Cause.INVALID_FIRST_NAME; +// } +// +// if (request.getLastName() != null && !request.getLastName().trim().isEmpty() +// && !isLastNameValid(request.getLastName())) { +// return Cause.INVALID_LAST_NAME; +// } +// +// return null; +// } } diff --git a/src/main/java/biz/nynja/account/configuration/CassandraConfig.java b/src/main/java/biz/nynja/account/configuration/CassandraConfig.java index 0c5a2f2a4bf215870e945582db7f45096d511096..6ea4bd218c36a340ff87f73fa91907a8be0ae20f 100644 --- a/src/main/java/biz/nynja/account/configuration/CassandraConfig.java +++ b/src/main/java/biz/nynja/account/configuration/CassandraConfig.java @@ -43,7 +43,7 @@ public class CassandraConfig extends AbstractCassandraConfiguration { @Override public String[] getEntityBasePackages() { - return new String[] { "biz.nynja.account.grpc.models" }; + return new String[] { "biz.nynja.account.models" }; } /** diff --git a/src/main/java/biz/nynja/account/models/Account.java b/src/main/java/biz/nynja/account/models/Account.java index 0c44ff73f865b4e729a4a49c8feae5bc451928de..cffdbaf24aa438e552a1935e802b55da40f0fe54 100644 --- a/src/main/java/biz/nynja/account/models/Account.java +++ b/src/main/java/biz/nynja/account/models/Account.java @@ -286,7 +286,8 @@ public class Account { public AccountDetails toProto() { Builder builder = AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setAccountMark(getAccountMark()) + .setProfileId(getProfileId().toString()).setAuthenticationIdentifier(getAuthenticationProvider()) + .setAuthenticationType(getAuthenticationProviderType()).setAccountMark(getAccountMark()) .setAccountName(getAccountName()).setFirstName(getFirstName()).setLastName(getLastName()) .setUsername(getUsername()).setAccountStatus(getAccountStatus()).setQrCode(getQrCode()); diff --git a/src/main/java/biz/nynja/account/models/AccountByAuthenticationProvider.java b/src/main/java/biz/nynja/account/models/AccountByAuthenticationProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..7ef1245a020391e54ccc1692652f82704596fd73 --- /dev/null +++ b/src/main/java/biz/nynja/account/models/AccountByAuthenticationProvider.java @@ -0,0 +1,322 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.models; + +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.UUID; + +import biz.nynja.account.grpc.AccountDetails.Builder; + +public class AccountByAuthenticationProvider { + + private UUID profileId; + private UUID accountId; + private String accountMark; + private String authenticationProvider; + private String authenticationProviderType; + private String firstName; + private String lastName; + private ByteBuffer avatar; + private String accountName; + private String username; + private String accountStatus; + private Long creationTimestamp; + private Long lastUpdateTimestamp; + private Set communicationProviders; + private String qrCode; + + 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 getAccountMark() { + return accountMark; + } + + public void setAccountMark(String accountMark) { + this.accountMark = accountMark; + } + + 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 String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public ByteBuffer getAvatar() { + return avatar; + } + + public void setAvatar(ByteBuffer avatar) { + this.avatar = avatar; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(String accountStatus) { + this.accountStatus = accountStatus; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + public Long getLastUpdateTimestamp() { + return lastUpdateTimestamp; + } + + public void setLastUpdateTimestamp(Long lastUpdateTimestamp) { + this.lastUpdateTimestamp = lastUpdateTimestamp; + } + + public Set getCommunicationProviders() { + return communicationProviders; + } + + public void setCommunicationProviders(Set communicationProviders) { + this.communicationProviders = communicationProviders; + } + + public String getQrCode() { + return qrCode; + } + + public void setQrCode(String qrCode) { + this.qrCode = qrCode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((accountMark == null) ? 0 : accountMark.hashCode()); + result = prime * result + ((accountName == null) ? 0 : accountName.hashCode()); + result = prime * result + ((accountStatus == null) ? 0 : accountStatus.hashCode()); + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((avatar == null) ? 0 : avatar.hashCode()); + result = prime * result + ((communicationProviders == null) ? 0 : communicationProviders.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((qrCode == null) ? 0 : qrCode.hashCode()); + result = prime * result + ((username == null) ? 0 : username.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; + AccountByAuthenticationProvider other = (AccountByAuthenticationProvider) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (accountMark == null) { + if (other.accountMark != null) + return false; + } else if (!accountMark.equals(other.accountMark)) + return false; + if (accountName == null) { + if (other.accountName != null) + return false; + } else if (!accountName.equals(other.accountName)) + return false; + if (accountStatus == null) { + if (other.accountStatus != null) + return false; + } else if (!accountStatus.equals(other.accountStatus)) + 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 (avatar == null) { + if (other.avatar != null) + return false; + } else if (!avatar.equals(other.avatar)) + return false; + if (communicationProviders == null) { + if (other.communicationProviders != null) + return false; + } else if (!communicationProviders.equals(other.communicationProviders)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (lastUpdateTimestamp == null) { + if (other.lastUpdateTimestamp != null) + return false; + } else if (!lastUpdateTimestamp.equals(other.lastUpdateTimestamp)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (qrCode == null) { + if (other.qrCode != null) + return false; + } else if (!qrCode.equals(other.qrCode)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("Account [accountId=").append(accountId).append(", profileId=").append(profileId) + .append(", accountMark=").append(accountMark).append(", authenticationProvider=") + .append(authenticationProvider).append(", authenticationProviderType=") + .append(authenticationProviderType).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", avatar=").append(avatar).append(", accountName=").append(accountName) + .append(", username=").append(username).append(", accountStatus=").append(accountStatus) + .append(", creationTimestamp=").append(creationTimestamp).append(", lastUpdateTimestamp=") + .append(lastUpdateTimestamp).append(", communicationProviders=").append(communicationProviders) + .append("]").toString(); + } + + public biz.nynja.account.grpc.AccountDetails toProto() { + + Builder builder = biz.nynja.account.grpc.AccountDetails.newBuilder(); + if (getAccountId() != null) { + builder.setAccountId(getAccountId().toString()); + } + if (getProfileId() != null) { + builder.setProfileId(getProfileId().toString()); + } + if (getAuthenticationProvider() != null) { + builder.setAuthenticationIdentifier(getAuthenticationProvider()); + } + if (getAuthenticationProviderType() != null) { + builder.setAuthenticationType(getAuthenticationProviderType()); + } + if (getAccountMark() != null) { + builder.setAccountMark(getAccountMark()); + } + if (getAccountName() != null) { + builder.setAccountName(getAccountName()); + } + if (getFirstName() != null) { + builder.setFirstName(getFirstName()); + } + if (getLastName() != null) { + builder.setLastName(getLastName()); + } + if (getUsername() != null) { + builder.setUsername(getUsername()); + } + if (getAccountStatus() != null) { + builder.setAccountStatus(getAccountStatus()); + } + if (getQrCode() != null) { + builder.setQrCode(getQrCode()); + } + if (avatar != null) { + builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); + } + if (communicationProviders != null) { + for (AuthenticationProvider ap : communicationProviders) { + builder.addCommunicationProviders(ap.toProto()); + } + } + + return builder.build(); + + } + +} diff --git a/src/main/java/biz/nynja/account/models/AccountByProfileId.java b/src/main/java/biz/nynja/account/models/AccountByProfileId.java index def5fe0ff320e61283bdcd514c08924d86f61a24..21573a34b6b29a97f9cc08217c899643ecfc0383 100644 --- a/src/main/java/biz/nynja/account/models/AccountByProfileId.java +++ b/src/main/java/biz/nynja/account/models/AccountByProfileId.java @@ -272,7 +272,8 @@ public class AccountByProfileId { public biz.nynja.account.grpc.AccountDetails toProto() { Builder builder = biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setAccountMark(getAccountMark()) + .setProfileId(getProfileId().toString()).setAuthenticationIdentifier(getAuthenticationProvider()) + .setAuthenticationType(getAuthenticationProviderType()).setAccountMark(getAccountMark()) .setAccountName(getAccountName()).setFirstName(getFirstName()).setLastName(getLastName()) .setUsername(getUsername()).setAccountStatus(getAccountStatus()); diff --git a/src/main/java/biz/nynja/account/models/UserInfo.java b/src/main/java/biz/nynja/account/models/UserInfo.java deleted file mode 100644 index b5337df327f6dbf633b7a8068bd2d9a4b91c3c62..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/models/UserInfo.java +++ /dev/null @@ -1,268 +0,0 @@ -/** - * Copyright (C) 2018 Nynja Inc. All rights reserved. - */ -package biz.nynja.account.models; - -import java.util.UUID; - -import org.springframework.data.cassandra.core.cql.PrimaryKeyType; -import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.core.mapping.Table; - -import biz.nynja.account.grpc.AuthenticationType; -import biz.nynja.account.grpc.CreateAccountRequest; -import biz.nynja.account.grpc.Status; - -@Table -public class UserInfo { - - @PrimaryKeyColumn(name = "profile_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private UUID profileId; - @PrimaryKeyColumn(name = "account_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) - private UUID accountId; - private String firstName; - private String lastName; - private String middleName; - @PrimaryKeyColumn(name = "username", ordinal = 2, type = PrimaryKeyType.CLUSTERED) - private String username; - private String phoneNumber; - private String emailAddress; - private String password; - private Status status; - @PrimaryKeyColumn(name = "authentication_type", ordinal = 3, type = PrimaryKeyType.CLUSTERED) - private AuthenticationType authenticationType; - @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 4, type = PrimaryKeyType.CLUSTERED) - private String authenticationProviderId; - private String communicationProcviderId; - - public UserInfo() { - } - - public UUID getProfileId() { - return profileId; - } - - public void setProfileId(UUID profileId) { - this.profileId = profileId; - } - - public UUID getAccountId() { - return accountId; - } - - public void setAccountId(UUID accountId) { - this.accountId = accountId; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public AuthenticationType getAuthenticationType() { - return authenticationType; - } - - public void setAuthenticationType(AuthenticationType authenticationType) { - this.authenticationType = authenticationType; - } - - public String getAuthenticationProviderId() { - return authenticationProviderId; - } - - public void setAuthenticationProviderId(String authenticationProviderId) { - this.authenticationProviderId = authenticationProviderId; - } - - public String getCommunicationProcviderId() { - return communicationProcviderId; - } - - public void setCommunicationProcviderId(String communicationProcviderId) { - this.communicationProcviderId = communicationProcviderId; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); - result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); - result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); - result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); - result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); - result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); - result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); - result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); - result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((username == null) ? 0 : username.hashCode()); - result = prime * result + ((password == null) ? 0 : password.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; - UserInfo other = (UserInfo) obj; - if (accountId == null) { - if (other.accountId != null) - return false; - } else if (!accountId.equals(other.accountId)) - return false; - if (authenticationProviderId == null) { - if (other.authenticationProviderId != null) - return false; - } else if (!authenticationProviderId.equals(other.authenticationProviderId)) - return false; - if (authenticationType != other.authenticationType) - return false; - if (communicationProcviderId == null) { - if (other.communicationProcviderId != null) - return false; - } else if (!communicationProcviderId.equals(other.communicationProcviderId)) - return false; - if (emailAddress == null) { - if (other.emailAddress != null) - return false; - } else if (!emailAddress.equals(other.emailAddress)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - if (middleName == null) { - if (other.middleName != null) - return false; - } else if (!middleName.equals(other.middleName)) - return false; - if (phoneNumber == null) { - if (other.phoneNumber != null) - return false; - } else if (!phoneNumber.equals(other.phoneNumber)) - return false; - if (profileId == null) { - if (other.profileId != null) - return false; - } else if (!profileId.equals(other.profileId)) - return false; - if (status != other.status) - return false; - if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - if (password == null) { - if (other.password != null) - return false; - } else if (!password.equals(other.password)) - return false; - return true; - } - - @Override - public String toString() { - return new StringBuilder("UserInfo [profileId=").append(profileId).append(", accountId=").append(accountId) - .append(", firstName=").append(firstName).append(", lastName=").append(lastName).append(", middleName=") - .append(middleName).append(", username=").append(username).append(", password=").append(password) - .append(", phoneNumber=").append(phoneNumber).append(", emailAddress=").append(emailAddress) - .append(", status=").append(status).append(", authenticationType=").append(authenticationType) - .append(", authenticationProviderId=").append(authenticationProviderId).append(", avatar=[]") - .append(", communicationProcviderId=").append(communicationProcviderId).append("]").toString(); - } - - public static UserInfo fromProto(CreateAccountRequest proto) { - UserInfo userInfo = new UserInfo(); - userInfo.setUsername(proto.getUsername()); - userInfo.setEmailAddress(proto.getEmailAddress()); - userInfo.setFirstName(proto.getFirstName()); - userInfo.setLastName(proto.getLastName()); - userInfo.setMiddleName(proto.getMiddleName()); - userInfo.setPhoneNumber(proto.getPhoneNumber()); - userInfo.setAuthenticationType(proto.getAuthenticationType()); - userInfo.setStatus(proto.getStatus()); - userInfo.setPassword(proto.getPassword()); - return userInfo; - } - - public biz.nynja.account.grpc.AccountDetails toProto() { - return biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setUsername(getUsername()) - .setAuthenticationType(getAuthenticationType()).setEmailAddress(getEmailAddress()) - .setFirstName(getFirstName()).setLastName(getLastName()).setMiddleName(getMiddleName()) - .setPhoneNumber(getPhoneNumber()).setStatus(getStatus()).build(); - } -} diff --git a/src/main/java/biz/nynja/account/models/UserInfoByEmail.java b/src/main/java/biz/nynja/account/models/UserInfoByEmail.java deleted file mode 100644 index 9a2a9b0225fde6de0fcc78fe09dd17b8b33a3474..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/models/UserInfoByEmail.java +++ /dev/null @@ -1,250 +0,0 @@ -/** - * Copyright (C) 2018 Nynja Inc. All rights reserved. - */ -package biz.nynja.account.models; - -import java.util.UUID; - -import org.springframework.data.cassandra.core.cql.PrimaryKeyType; -import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.core.mapping.Table; - -import biz.nynja.account.grpc.AuthenticationType; -import biz.nynja.account.grpc.CreateAccountRequest; -import biz.nynja.account.grpc.Status; - -@Table("userinfo_by_email") -public class UserInfoByEmail { - - @PrimaryKeyColumn(name = "emailaddress", ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String emailAddress; - @PrimaryKeyColumn(name = "profile_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) - private UUID profileId; - @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) - private UUID accountId; - @PrimaryKeyColumn(name = "username", ordinal = 3, type = PrimaryKeyType.CLUSTERED) - private String username; - @PrimaryKeyColumn(name = "authentication_type", ordinal = 4, type = PrimaryKeyType.CLUSTERED) - private AuthenticationType authenticationType; - @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 5, type = PrimaryKeyType.CLUSTERED) - private String authenticationProviderId; - private String firstName; - private String lastName; - private String middleName; - private String phoneNumber; - private Status status; - private String communicationProcviderId; - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public UUID getProfileId() { - return profileId; - } - - public void setProfileId(UUID profileId) { - this.profileId = profileId; - } - - public UUID getAccountId() { - return accountId; - } - - public void setAccountId(UUID accountId) { - this.accountId = accountId; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public AuthenticationType getAuthenticationType() { - return authenticationType; - } - - public void setAuthenticationType(AuthenticationType authenticationType) { - this.authenticationType = authenticationType; - } - - public String getAuthenticationProviderId() { - return authenticationProviderId; - } - - public void setAuthenticationProviderId(String authenticationProviderId) { - this.authenticationProviderId = authenticationProviderId; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public String getCommunicationProcviderId() { - return communicationProcviderId; - } - - public void setCommunicationProcviderId(String communicationProcviderId) { - this.communicationProcviderId = communicationProcviderId; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); - result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); - result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); - result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); - result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); - result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); - result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); - result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); - result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((username == null) ? 0 : username.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; - UserInfoByEmail other = (UserInfoByEmail) obj; - if (accountId == null) { - if (other.accountId != null) - return false; - } else if (!accountId.equals(other.accountId)) - return false; - if (authenticationProviderId == null) { - if (other.authenticationProviderId != null) - return false; - } else if (!authenticationProviderId.equals(other.authenticationProviderId)) - return false; - if (authenticationType != other.authenticationType) - return false; - if (communicationProcviderId == null) { - if (other.communicationProcviderId != null) - return false; - } else if (!communicationProcviderId.equals(other.communicationProcviderId)) - return false; - if (emailAddress == null) { - if (other.emailAddress != null) - return false; - } else if (!emailAddress.equals(other.emailAddress)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - if (middleName == null) { - if (other.middleName != null) - return false; - } else if (!middleName.equals(other.middleName)) - return false; - if (phoneNumber == null) { - if (other.phoneNumber != null) - return false; - } else if (!phoneNumber.equals(other.phoneNumber)) - return false; - if (profileId == null) { - if (other.profileId != null) - return false; - } else if (!profileId.equals(other.profileId)) - return false; - if (status != other.status) - return false; - if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - return true; - } - - @Override - public String toString() { - return new StringBuilder("UserInfoByEmail [emailAddress=").append(emailAddress).append(", profileId=") - .append(profileId).append(", accountId=").append(accountId).append(", username=").append(username) - .append(", authenticationType=").append(authenticationType).append(", authenticationProviderId=") - .append(authenticationProviderId).append(", firstName=").append(firstName).append(", lastName=") - .append(lastName).append(", middleName=").append(middleName).append(", phoneNumber=") - .append(phoneNumber).append(", status=").append(status).append(", communicationProcviderId=") - .append(communicationProcviderId).append("]").toString(); - } - - public static UserInfoByEmail fromProto(CreateAccountRequest proto) { - UserInfoByEmail userInfo = new UserInfoByEmail(); - userInfo.setUsername(proto.getUsername()); - userInfo.setEmailAddress(proto.getEmailAddress()); - userInfo.setFirstName(proto.getFirstName()); - userInfo.setLastName(proto.getLastName()); - userInfo.setMiddleName(proto.getMiddleName()); - userInfo.setPhoneNumber(proto.getPhoneNumber()); - userInfo.setAuthenticationType(proto.getAuthenticationType()); - userInfo.setStatus(proto.getStatus()); - return userInfo; - } - - public biz.nynja.account.grpc.AccountDetails toProto() { - return biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setUsername(getUsername()) - .setAuthenticationType(getAuthenticationType()).setEmailAddress(getEmailAddress()) - .setFirstName(getFirstName()).setLastName(getLastName()).setMiddleName(getMiddleName()) - .setPhoneNumber(getPhoneNumber()).setStatus(getStatus()).build(); - } -} diff --git a/src/main/java/biz/nynja/account/models/UserInfoByPhone.java b/src/main/java/biz/nynja/account/models/UserInfoByPhone.java deleted file mode 100644 index 0fefda5ad5239d76f5fe30976054d4e5a3563f3c..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/models/UserInfoByPhone.java +++ /dev/null @@ -1,247 +0,0 @@ -package biz.nynja.account.models; - -import java.util.UUID; - -import org.springframework.data.cassandra.core.cql.PrimaryKeyType; -import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.core.mapping.Table; - -import biz.nynja.account.grpc.AuthenticationType; -import biz.nynja.account.grpc.CreateAccountRequest; -import biz.nynja.account.grpc.Status; - -@Table("userinfo_by_phone") -public class UserInfoByPhone { - - @PrimaryKeyColumn(name = "phonenumber", ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String phoneNumber; - @PrimaryKeyColumn(name = "profile_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) - private UUID profileId; - @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) - private UUID accountId; - @PrimaryKeyColumn(name = "username", ordinal = 3, type = PrimaryKeyType.CLUSTERED) - private String username; - @PrimaryKeyColumn(name = "authentication_type", ordinal = 4, type = PrimaryKeyType.CLUSTERED) - private AuthenticationType authenticationType; - @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 5, type = PrimaryKeyType.CLUSTERED) - private String authenticationProviderId; - private String firstName; - private String lastName; - private String middleName; - private String emailAddress; - private Status status; - private String communicationProcviderId; - - public String getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public UUID getProfileId() { - return profileId; - } - - public void setProfileId(UUID profileId) { - this.profileId = profileId; - } - - public UUID getAccountId() { - return accountId; - } - - public void setAccountId(UUID accountId) { - this.accountId = accountId; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public AuthenticationType getAuthenticationType() { - return authenticationType; - } - - public void setAuthenticationType(AuthenticationType authenticationType) { - this.authenticationType = authenticationType; - } - - public String getAuthenticationProviderId() { - return authenticationProviderId; - } - - public void setAuthenticationProviderId(String authenticationProviderId) { - this.authenticationProviderId = authenticationProviderId; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public String getCommunicationProcviderId() { - return communicationProcviderId; - } - - public void setCommunicationProcviderId(String communicationProcviderId) { - this.communicationProcviderId = communicationProcviderId; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); - result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); - result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); - result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); - result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); - result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); - result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); - result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); - result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((username == null) ? 0 : username.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; - UserInfoByPhone other = (UserInfoByPhone) obj; - if (accountId == null) { - if (other.accountId != null) - return false; - } else if (!accountId.equals(other.accountId)) - return false; - if (authenticationProviderId == null) { - if (other.authenticationProviderId != null) - return false; - } else if (!authenticationProviderId.equals(other.authenticationProviderId)) - return false; - if (authenticationType != other.authenticationType) - return false; - if (communicationProcviderId == null) { - if (other.communicationProcviderId != null) - return false; - } else if (!communicationProcviderId.equals(other.communicationProcviderId)) - return false; - if (emailAddress == null) { - if (other.emailAddress != null) - return false; - } else if (!emailAddress.equals(other.emailAddress)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - if (middleName == null) { - if (other.middleName != null) - return false; - } else if (!middleName.equals(other.middleName)) - return false; - if (phoneNumber == null) { - if (other.phoneNumber != null) - return false; - } else if (!phoneNumber.equals(other.phoneNumber)) - return false; - if (profileId == null) { - if (other.profileId != null) - return false; - } else if (!profileId.equals(other.profileId)) - return false; - if (status != other.status) - return false; - if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - return true; - } - - @Override - public String toString() { - return new StringBuilder("UserInfoByEmail [emailAddress=").append(emailAddress).append(", profileId=") - .append(profileId).append(", accountId=").append(accountId).append(", username=").append(username) - .append(", authenticationType=").append(authenticationType).append(", authenticationProviderId=") - .append(authenticationProviderId).append(", firstName=").append(firstName).append(", lastName=") - .append(lastName).append(", middleName=").append(middleName).append(", phoneNumber=") - .append(phoneNumber).append(", status=").append(status).append(", communicationProcviderId=") - .append(communicationProcviderId).append("]").toString(); - } - - public static UserInfoByPhone fromProto(CreateAccountRequest proto) { - UserInfoByPhone userInfo = new UserInfoByPhone(); - userInfo.setUsername(proto.getUsername()); - userInfo.setEmailAddress(proto.getEmailAddress()); - userInfo.setFirstName(proto.getFirstName()); - userInfo.setLastName(proto.getLastName()); - userInfo.setMiddleName(proto.getMiddleName()); - userInfo.setPhoneNumber(proto.getPhoneNumber()); - userInfo.setAuthenticationType(proto.getAuthenticationType()); - userInfo.setStatus(proto.getStatus()); - return userInfo; - } - - public biz.nynja.account.grpc.AccountDetails toProto() { - return biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setUsername(getUsername()) - .setAuthenticationType(getAuthenticationType()).setEmailAddress(getEmailAddress()) - .setFirstName(getFirstName()).setLastName(getLastName()).setMiddleName(getMiddleName()) - .setPhoneNumber(getPhoneNumber()).setStatus(getStatus()).build(); - } -} diff --git a/src/main/java/biz/nynja/account/models/UserInfoByUsername.java b/src/main/java/biz/nynja/account/models/UserInfoByUsername.java deleted file mode 100644 index 726ee30f573589f1c13860cb041232797a0fbf68..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/models/UserInfoByUsername.java +++ /dev/null @@ -1,226 +0,0 @@ -package biz.nynja.account.models; - -import java.util.UUID; - -import org.springframework.data.cassandra.core.cql.PrimaryKeyType; -import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.core.mapping.Table; - -import biz.nynja.account.grpc.AuthenticationType; -import biz.nynja.account.grpc.Status; - -@Table("userinfo_by_username") -public class UserInfoByUsername { - - @PrimaryKeyColumn(name = "username", ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String username; - @PrimaryKeyColumn(name = "profile_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED) - private UUID profileId; - @PrimaryKeyColumn(name = "account_id", ordinal = 2, type = PrimaryKeyType.CLUSTERED) - private UUID accountId; - @PrimaryKeyColumn(name = "phonenumber", ordinal = 3, type = PrimaryKeyType.CLUSTERED) - private String phoneNumber; - @PrimaryKeyColumn(name = "authentication_type", ordinal = 4, type = PrimaryKeyType.CLUSTERED) - private AuthenticationType authenticationType; - @PrimaryKeyColumn(name = "authnetication_provider_id", ordinal = 5, type = PrimaryKeyType.CLUSTERED) - private String authenticationProviderId; - private String firstName; - private String lastName; - private String middleName; - private String emailAddress; - private Status status; - private String communicationProcviderId; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public UUID getProfileId() { - return profileId; - } - - public void setProfileId(UUID profileId) { - this.profileId = profileId; - } - - public UUID getAccountId() { - return accountId; - } - - public void setAccountId(UUID accountId) { - this.accountId = accountId; - } - - public String getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public AuthenticationType getAuthenticationType() { - return authenticationType; - } - - public void setAuthenticationType(AuthenticationType authenticationType) { - this.authenticationType = authenticationType; - } - - public String getAuthenticationProviderId() { - return authenticationProviderId; - } - - public void setAuthenticationProviderId(String authenticationProviderId) { - this.authenticationProviderId = authenticationProviderId; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public String getCommunicationProcviderId() { - return communicationProcviderId; - } - - public void setCommunicationProcviderId(String communicationProcviderId) { - this.communicationProcviderId = communicationProcviderId; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); - result = prime * result + ((authenticationProviderId == null) ? 0 : authenticationProviderId.hashCode()); - result = prime * result + ((authenticationType == null) ? 0 : authenticationType.hashCode()); - result = prime * result + ((communicationProcviderId == null) ? 0 : communicationProcviderId.hashCode()); - result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode()); - result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); - result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); - result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode()); - result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((username == null) ? 0 : username.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; - UserInfoByUsername other = (UserInfoByUsername) obj; - if (accountId == null) { - if (other.accountId != null) - return false; - } else if (!accountId.equals(other.accountId)) - return false; - if (authenticationProviderId == null) { - if (other.authenticationProviderId != null) - return false; - } else if (!authenticationProviderId.equals(other.authenticationProviderId)) - return false; - if (authenticationType != other.authenticationType) - return false; - if (communicationProcviderId == null) { - if (other.communicationProcviderId != null) - return false; - } else if (!communicationProcviderId.equals(other.communicationProcviderId)) - return false; - if (emailAddress == null) { - if (other.emailAddress != null) - return false; - } else if (!emailAddress.equals(other.emailAddress)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - if (middleName == null) { - if (other.middleName != null) - return false; - } else if (!middleName.equals(other.middleName)) - return false; - if (phoneNumber == null) { - if (other.phoneNumber != null) - return false; - } else if (!phoneNumber.equals(other.phoneNumber)) - return false; - if (profileId == null) { - if (other.profileId != null) - return false; - } else if (!profileId.equals(other.profileId)) - return false; - if (status != other.status) - return false; - if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - return true; - } - - @Override - public String toString() { - return new StringBuilder("UserInfoByEmail [emailAddress=").append(emailAddress).append(", profileId=") - .append(profileId).append(", accountId=").append(accountId).append(", username=").append(username) - .append(", authenticationType=").append(authenticationType).append(", authenticationProviderId=") - .append(authenticationProviderId).append(", firstName=").append(firstName).append(", lastName=") - .append(lastName).append(", middleName=").append(middleName).append(", phoneNumber=") - .append(phoneNumber).append(", status=").append(status).append(", communicationProcviderId=") - .append(communicationProcviderId).append("]").toString(); - } - -} \ No newline at end of file diff --git a/src/main/java/biz/nynja/account/repositories/AccountByAuthenticationProviderRepository.java b/src/main/java/biz/nynja/account/repositories/AccountByAuthenticationProviderRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..73f9cb740a1e0036e686a5f2a2b92d965712198f --- /dev/null +++ b/src/main/java/biz/nynja/account/repositories/AccountByAuthenticationProviderRepository.java @@ -0,0 +1,17 @@ +/** + * 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.AccountByAuthenticationProvider; + +@Repository +public interface AccountByAuthenticationProviderRepository extends CassandraRepository { + + List findAllByAuthenticationProvider(String authenticationProvider); +} diff --git a/src/main/java/biz/nynja/account/repositories/UserInfoByEmailRepository.java b/src/main/java/biz/nynja/account/repositories/UserInfoByEmailRepository.java deleted file mode 100644 index 92630e61950180839f56dcf9c904b338cd226ab7..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/repositories/UserInfoByEmailRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * 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.UserInfoByEmail; - -@Repository -public interface UserInfoByEmailRepository extends CassandraRepository { - - List findByEmailAddress(String email); -} diff --git a/src/main/java/biz/nynja/account/repositories/UserInfoByPhoneRepository.java b/src/main/java/biz/nynja/account/repositories/UserInfoByPhoneRepository.java deleted file mode 100644 index 172f5ce188511e6c02ada6b064d7923f88fab1ea..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/repositories/UserInfoByPhoneRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -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.UserInfoByPhone; - -@Repository -public interface UserInfoByPhoneRepository extends CassandraRepository{ - - List findByPhoneNumber(String phoneNumber); - -} diff --git a/src/main/java/biz/nynja/account/repositories/UserInfoByUsernameRepository.java b/src/main/java/biz/nynja/account/repositories/UserInfoByUsernameRepository.java deleted file mode 100644 index 6abe3ef7e3b550608795befdce4ae2071a4705e5..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/repositories/UserInfoByUsernameRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -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.UserInfoByUsername; - -@Repository -public interface UserInfoByUsernameRepository extends CassandraRepository { - - List findByUsername(String username); - -} diff --git a/src/main/java/biz/nynja/account/repositories/UserInfoRepository.java b/src/main/java/biz/nynja/account/repositories/UserInfoRepository.java deleted file mode 100644 index a089409f3946176acf41208e5436e61f015706a9..0000000000000000000000000000000000000000 --- a/src/main/java/biz/nynja/account/repositories/UserInfoRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (C) 2018 Nynja Inc. All rights reserved. - */ -package biz.nynja.account.repositories; - -import java.util.List; -import java.util.UUID; - -import org.springframework.data.cassandra.repository.CassandraRepository; - -import biz.nynja.account.models.UserInfo; - -public interface UserInfoRepository extends CassandraRepository { - - public List findAllByProfileId(UUID profileId); - -} diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 9cf8573f84354c7f601f0bef30fd70ef0f00abff..a06dda49e7a1060573257205a0d67dcec61cc2e0 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -14,34 +14,27 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import biz.nynja.account.components.Validator; +import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; import biz.nynja.account.grpc.AccountDetails; +import biz.nynja.account.grpc.AccountResponse; import biz.nynja.account.grpc.AccountServiceGrpc; -import biz.nynja.account.grpc.AccountsByAuthenticationProviderRequest; import biz.nynja.account.grpc.AccountsByProfileIdRequest; +import biz.nynja.account.grpc.AccountsList; import biz.nynja.account.grpc.AccountsResponse; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; -import biz.nynja.account.grpc.CompletePendingAccountCreationResponse; import biz.nynja.account.grpc.CreateAccountRequest; -import biz.nynja.account.grpc.CreateAccountResponse; import biz.nynja.account.grpc.CreatePendingAccountRequest; import biz.nynja.account.grpc.CreatePendingAccountResponse; import biz.nynja.account.grpc.ErrorResponse; 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.UserInfo; -import biz.nynja.account.models.UserInfoByEmail; -import biz.nynja.account.models.UserInfoByPhone; +import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.repositories.AccountByProfileIdRepository; -import biz.nynja.account.repositories.AccountRepository; import biz.nynja.account.repositories.AccountRepositoryAdditional; import biz.nynja.account.repositories.PendingAccountRepository; -import biz.nynja.account.repositories.UserInfoByEmailRepository; -import biz.nynja.account.repositories.UserInfoByPhoneRepository; -import biz.nynja.account.repositories.UserInfoRepository; -import biz.nynja.account.grpc.GetAccountsResponse; import io.grpc.stub.StreamObserver; /** @@ -54,17 +47,11 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas private static final Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class); - @Autowired - private UserInfoRepository userInfoRepository; - - @Autowired - private AccountRepository accountRepository; - @Autowired private AccountByProfileIdRepository accountByProfileIdRepository; @Autowired - private UserInfoByEmailRepository userInfoByEmailRepository; + private AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; @Autowired private PendingAccountRepository pendingAccountRepository; @@ -72,128 +59,82 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas @Autowired private AccountRepositoryAdditional accountRepositoryAdditional; - @Autowired - private UserInfoByPhoneRepository userInfoByPhoneRepository; - @Autowired private Validator validator; @Override - public void createAccount(CreateAccountRequest request, StreamObserver responseObserver) { + public void createAccount(CreateAccountRequest request, StreamObserver responseObserver) { - logger.info("Creating account..."); - logger.debug("Creating account: {} ...", request); + // TODO: add method implementation - Cause validationCause = validator.validateCreateAccountRequest(request); - if (validationCause != null) { - responseObserver.onNext(CreateAccountResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(validationCause)).build()); - responseObserver.onCompleted(); - return; - } - - UserInfo userInfo = UserInfo.fromProto(request); - if (request.getProfileId() == null || request.getProfileId().isEmpty()) { - userInfo.setProfileId(UUID.randomUUID()); - } else { - userInfo.setProfileId(UUID.fromString(request.getProfileId())); - } - userInfo.setAccountId(UUID.randomUUID()); - // TODO set authentication provider - userInfo.setAuthenticationProviderId("id"); - - UserInfo savedAccount = userInfoRepository.save(userInfo); - logger.debug("Account \"{}\" saved into the DB", savedAccount.toString()); - - CreateAccountResponse response = CreateAccountResponse.newBuilder().setAccountDetails(savedAccount.toProto()) - .build(); - logger.info("Account created successfully."); - logger.debug("Account: \"{}\" created successfully.", response); - - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; } @Override - public void getAllAccountsByAuthenticationProvider(AccountsByAuthenticationProviderRequest request, - StreamObserver responseObserver) { + public void getAccountByAuthenticationProvider(AccountByAuthenticationProviderRequest request, + StreamObserver responseObserver) { - logger.info("New get all accounts by authentication provider request recieved."); - logger.debug("New get all accounts by authentication provider request recieved: {}", request); - if (request.getAuthenticationType() == null) { - responseObserver.onNext(GetAccountsResponse.newBuilder() + logger.info("Getting account by authentication provider: {}", request); + if (request.getAuthenticationTypeValue() == 0) { + responseObserver.onNext(AccountResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_TYPE)).build()); responseObserver.onCompleted(); return; } - if (request.getAuthenticationIdentifier() == null) { - responseObserver.onNext(GetAccountsResponse.newBuilder() + if (request.getAuthenticationIdentifier() == null || request.getAuthenticationIdentifier().isEmpty()) { + responseObserver.onNext(AccountResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)).build()); responseObserver.onCompleted(); return; } - List accountDetails = new ArrayList(); + AccountDetails accountDetails = null; - switch (request.getAuthenticationType()) { - case PHONE: { - - List relatedAccounts = userInfoByPhoneRepository - .findByPhoneNumber(request.getAuthenticationIdentifier()); - if (relatedAccounts.isEmpty()) { - responseObserver.onNext(GetAccountsResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); - responseObserver.onCompleted(); - return; - } + List accounts = accountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(request.getAuthenticationIdentifier()); - for (UserInfoByPhone account : relatedAccounts) { - accountDetails.add(account.toProto()); - } - GetAccountsResponse response = GetAccountsResponse.newBuilder() - .setAccountsResponse(AccountsResponse.newBuilder().addAllAccountDetails(accountDetails)).build(); - responseObserver.onNext(response); + if (accounts.isEmpty()) { + logger.debug("No matching accounts found for authetntication provider {}: {}", + request.getAuthenticationType(), request.getAuthenticationIdentifier()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); responseObserver.onCompleted(); + return; } - case EMAIL: { - List relatedAccounts = userInfoByEmailRepository - .findByEmailAddress(request.getAuthenticationIdentifier()); - if (relatedAccounts.isEmpty()) { - responseObserver.onNext(GetAccountsResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); - responseObserver.onCompleted(); - return; - } - for (UserInfoByEmail account : relatedAccounts) { - accountDetails.add(account.toProto()); + + // We retrieve accounts by authentication provider identifier from DB where both authentication provider + // identifier and type uniquely identify an account. + // For this reason we need to filter results by authentication provider type. + for (AccountByAuthenticationProvider account : accounts) { + if (account.getAuthenticationProviderType().equals(request.getAuthenticationType().name())) { + accountDetails = account.toProto(); + break; } } - case FACEBOOK: - break; - case GOOGLEPLUS: - break; - case UNRECOGNIZED: - break; - default: - break; - + if (accountDetails == null) { + logger.debug("No matching accounts found for authetntication provider {}: {}", + request.getAuthenticationType(), request.getAuthenticationIdentifier()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; } - GetAccountsResponse response = GetAccountsResponse.newBuilder() - .setAccountsResponse(AccountsResponse.newBuilder().addAllAccountDetails(accountDetails)).build(); + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(accountDetails).build(); + logger.debug("Found result for account by authentication provider {}: {}: \"{}\"", + request.getAuthenticationType(), request.getAuthenticationIdentifier(), response); responseObserver.onNext(response); responseObserver.onCompleted(); + + return; } @Override public void getAllAccountsByProfileId(AccountsByProfileIdRequest request, - StreamObserver responseObserver) { - logger.info("Getting accounts by profile ID..."); + StreamObserver responseObserver) { + logger.info("Getting accounts by profile id: {}", request.getProfileId()); if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { - responseObserver.onNext(GetAccountsResponse.newBuilder() + responseObserver.onNext(AccountsResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); responseObserver.onCompleted(); return; @@ -205,7 +146,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas List responseList = new ArrayList(); if (listAccountsByProfileId.size() == 0) { - responseObserver.onNext(GetAccountsResponse.newBuilder() + responseObserver.onNext(AccountsResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); responseObserver.onCompleted(); return; @@ -215,8 +156,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas responseList.add(account.toProto()); } - GetAccountsResponse response = GetAccountsResponse.newBuilder() - .setAccountsResponse(AccountsResponse.newBuilder().addAllAccountDetails(responseList)).build(); + AccountsResponse response = AccountsResponse.newBuilder() + .setAccountsResponse(AccountsList.newBuilder().addAllAccountDetails(responseList)).build(); logger.debug("Returned response: \"{}\".", response); @@ -252,21 +193,20 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas @Override public void completePendingAccountCreation(CompletePendingAccountCreationRequest request, - StreamObserver responseObserver) { + StreamObserver responseObserver) { logger.info("Complete pending account creation..."); logger.debug("Complete pending account creation...: {} ...", request); Account createdAccount = accountRepositoryAdditional.completePendingAccountCreation(request); if (createdAccount == null) { - responseObserver.onNext(CompletePendingAccountCreationResponse.newBuilder() + responseObserver.onNext(AccountResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_CREATING_ACCOUNT)).build()); responseObserver.onCompleted(); return; } else { logger.debug("Account \"{}\" saved into the DB", createdAccount.toString()); - CompletePendingAccountCreationResponse response = CompletePendingAccountCreationResponse.newBuilder() - .setAccountDetails(createdAccount.toCompletePendingAccountProto()).build(); + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(createdAccount.toProto()).build(); logger.debug("Account: \"{}\" created successfully.", response); responseObserver.onNext(response); diff --git a/src/test/java/biz/nynja/account/ApplicationTests.java b/src/test/java/biz/nynja/account/ApplicationTests.java index 23ac7dfd4ae7ae587268a2ab13008c60ead8b627..45f00f12d7644ce66e8fca486d2ad1949ba23dfb 100644 --- a/src/test/java/biz/nynja/account/ApplicationTests.java +++ b/src/test/java/biz/nynja/account/ApplicationTests.java @@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner; */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = { ApplicationTests.class }) +@ContextConfiguration public class ApplicationTests { @Test diff --git a/src/test/java/biz/nynja/account/components/ValidatorTests.java b/src/test/java/biz/nynja/account/components/ValidatorTests.java index 522a0ba2b6b58106f46b1aaf94f1ef02f49d5615..67156785d1525188c31c1b1435a3bc4b4c303c15 100644 --- a/src/test/java/biz/nynja/account/components/ValidatorTests.java +++ b/src/test/java/biz/nynja/account/components/ValidatorTests.java @@ -10,14 +10,10 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import biz.nynja.account.components.Validator; -import biz.nynja.account.repositories.UserInfoByEmailRepository; -import biz.nynja.account.repositories.UserInfoByPhoneRepository; -import biz.nynja.account.repositories.UserInfoByUsernameRepository; /** * Components unit tests. @@ -30,15 +26,6 @@ public class ValidatorTests { @Autowired private Validator validator; - @MockBean - private UserInfoByEmailRepository userInfoByEmailRepository; - - @MockBean - private UserInfoByPhoneRepository userInfoByPhoneRepository; - - @MockBean - private UserInfoByUsernameRepository userInfoByUsernameRepository; - @Test public void validPhoneNumberTest() { diff --git a/src/test/java/biz/nynja/account/configurations/CassandraTestsConfig.java b/src/test/java/biz/nynja/account/configurations/CassandraTestsConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..f57d3f5524930b8cec693735cb13e539ac4b6f24 --- /dev/null +++ b/src/test/java/biz/nynja/account/configurations/CassandraTestsConfig.java @@ -0,0 +1,48 @@ +package biz.nynja.account.configurations; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.data.cassandra.config.CassandraClusterFactoryBean; +import org.springframework.data.cassandra.core.CassandraOperations; +import org.springframework.data.cassandra.core.CassandraTemplate; +import org.springframework.data.cassandra.core.convert.CassandraConverter; +import org.springframework.data.cassandra.core.convert.MappingCassandraConverter; +import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; +import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver; + +import com.datastax.driver.core.Session; + +@TestConfiguration +public class CassandraTestsConfig { + + @MockBean + private Session session; + + @Bean + public CassandraClusterFactoryBean cluster() { + + CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); + cluster.setContactPoints("127.0.0.1"); + cluster.setPort(1); + + return cluster; + } + + @Bean + public CassandraMappingContext mappingContext() { + CassandraMappingContext mappingContext = new CassandraMappingContext(); + mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cluster().getObject(), "AuthenticationProvider")); + return mappingContext; + } + + @Bean + public CassandraConverter converter() { + return new MappingCassandraConverter(mappingContext()); + } + + @Bean + public CassandraOperations cassandraTemplate() throws Exception { + return new CassandraTemplate(session, converter()); + } +} diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 5b231fe96d6b75c8686e3ffd61912c51b2239ae2..47f251a5aa3e29ff395f85b8e562e01d669b0ef7 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -17,6 +17,7 @@ import java.util.concurrent.ExecutionException; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; @@ -26,23 +27,19 @@ import org.springframework.test.context.junit4.SpringRunner; import com.datastax.driver.core.Session; +import biz.nynja.account.configurations.CassandraTestsConfig; +import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; +import biz.nynja.account.grpc.AccountResponse; import biz.nynja.account.grpc.AccountServiceGrpc; -import biz.nynja.account.grpc.AccountsByAuthenticationProviderRequest; import biz.nynja.account.grpc.AccountsByProfileIdRequest; +import biz.nynja.account.grpc.AccountsResponse; import biz.nynja.account.grpc.AuthenticationType; import biz.nynja.account.grpc.CreateAccountRequest; -import biz.nynja.account.grpc.CreateAccountResponse; import biz.nynja.account.grpc.ErrorResponse.Cause; -import biz.nynja.account.grpc.GetAccountsResponse; import biz.nynja.account.grpc.Status; -import biz.nynja.account.models.UserInfo; -import biz.nynja.account.models.UserInfoByEmail; -import biz.nynja.account.models.UserInfoByPhone; -import biz.nynja.account.models.UserInfoByUsername; -import biz.nynja.account.repositories.UserInfoByEmailRepository; -import biz.nynja.account.repositories.UserInfoByPhoneRepository; -import biz.nynja.account.repositories.UserInfoByUsernameRepository; -import biz.nynja.account.repositories.UserInfoRepository; +import biz.nynja.account.models.Account; +import biz.nynja.account.models.AccountByAuthenticationProvider; +import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.utils.GrpcServerTestBase; import biz.nynja.account.utils.Util; @@ -51,7 +48,7 @@ import biz.nynja.account.utils.Util; */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = Util.class, +@SpringBootTest(classes = { Util.class, CassandraTestsConfig.class }, webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration", @@ -60,468 +57,444 @@ import biz.nynja.account.utils.Util; public class AccountServiceTests extends GrpcServerTestBase { @MockBean - private UserInfoRepository userInfoRepository; - - @MockBean - private UserInfoByEmailRepository userInfoByEmailRepository; - - @MockBean - private UserInfoByPhoneRepository userInfoByPhoneRepository; - - @MockBean - private Session session; - - @MockBean - private UserInfoByUsernameRepository userInfoByUsernameRepository; + private AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; @Autowired - @Qualifier("newAccount") - private UserInfo newAccount; + @Qualifier("accountByPhone") + private AccountByAuthenticationProvider accountByPhone; @Autowired - @Qualifier("savedAccount") - private UserInfo savedAccount; + @Qualifier("accountByEmail") + private AccountByAuthenticationProvider accountByEmail; @Autowired - private UserInfoByEmail userInfoByEmail; + @Qualifier("accountByFacebook") + private AccountByAuthenticationProvider accountByFacebook; @Autowired - private UserInfoByPhone userInfoByPhone; - - @Test - public void testCreateAccountByEmail() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setEmailAddress(Util.EMAIL).setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), - reply.getAccountDetails().getEmailAddress().equals(Util.EMAIL)); - } - - @Test - public void testCreateAccountExistEmail() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setEmailAddress(Util.EMAIL).setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG") - .setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - usersByEmail.add(new UserInfoByEmail()); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_ALREADY_USED), - reply.getError().getCause().equals(Cause.EMAIL_ALREADY_USED)); - } - - @Test - public void testCreateAccountByPhone() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), - reply.getAccountDetails().getPhoneNumber().equals(Util.PHONE_NUMBER)); - } - - @Test - public void testCreateAccountExistPhone() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - usersByPhone.add(new UserInfoByPhone()); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_ALREADY_USED), - reply.getError().getCause().equals(Cause.PHONE_NUMBER_ALREADY_USED)); - } - - @Test - public void testCreateAccountExistUsername() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - usersByUsername.add(new UserInfoByUsername()); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(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 testCreateAccountInvalidUsername() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(".Invalid-Username.") - .setPassword(Util.PASSWORD).setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG") - .setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(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)); - } - - @Test - public void testCreateAccountMissingFirstName() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setLastName(Util.LAST_NAME) - .setMiddleName(Util.MIDDLE_NAME).setAuthenticationType(AuthenticationType.PHONE) - .setUsername(Util.USERNAME).setPassword(Util.PASSWORD).setPhoneNumber(Util.PHONE_NUMBER) - .setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_FIRST_NAME), - reply.getError().getCause().equals(Cause.MISSING_FIRST_NAME)); - } - - @Test - public void testCreateAccountInvalidFirstName() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName("n") - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_FIRST_NAME), - reply.getError().getCause().equals(Cause.INVALID_FIRST_NAME)); - } - - @Test - public void testCreateAccountInvalidLastName() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName("ThisIsNotaValidLastNameIndeedAndItIsNotReal").setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_LAST_NAME), - reply.getError().getCause().equals(Cause.INVALID_LAST_NAME)); - } - - @Test - public void testCreateAccountInvalidEmail() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setEmailAddress(".invalid@email-.com").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(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)); - } - - @Test - public void testCreateAccountInvalidPhone() throws ExecutionException, InterruptedException { - final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) - .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) - .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) - .setPhoneNumber("+45955588833648946512957").setCountryCode("BG").setStatus(Status.SUSPENDED).build(); - - List usersByPhone = new ArrayList<>(); - List usersByEmail = new ArrayList<>(); - List usersByUsername = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); - given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final CreateAccountResponse reply = accountServiceBlockingStub.createAccount(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)); - } + @Qualifier("newAccount") + private Account newAccount; + @Autowired + @Qualifier("savedAccount") + private Account savedAccount; + + // TODO: These tests are commented and left here to be used as a reference + // Should be removed when they are not needed anymore + +// @Test +// public void testCreateAccountByEmail() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setEmailAddress(Util.EMAIL).setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), +// reply.getAccountDetails().getEmailAddress().equals(Util.EMAIL)); +// } +// +// @Test +// public void testCreateAccountExistEmail() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setEmailAddress(Util.EMAIL).setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG") +// .setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// usersByEmail.add(new UserInfoByEmail()); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_ALREADY_USED), +// reply.getError().getCause().equals(Cause.EMAIL_ALREADY_USED)); +// } +// +// @Test +// public void testCreateAccountByPhone() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), +// reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.PHONE_NUMBER)); +// } +// +// @Test +// public void testCreateAccountExistPhone() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// usersByPhone.add(new UserInfoByPhone()); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONE_NUMBER_ALREADY_USED), +// reply.getError().getCause().equals(Cause.PHONE_NUMBER_ALREADY_USED)); +// } +// +// @Test +// public void testCreateAccountExistUsername() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// usersByUsername.add(new UserInfoByUsername()); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(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 testCreateAccountInvalidUsername() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(".Invalid-Username.") +// .setPassword(Util.PASSWORD).setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG") +// .setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(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)); +// } +// +// @Test +// public void testCreateAccountMissingFirstName() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setLastName(Util.LAST_NAME) +// .setMiddleName(Util.MIDDLE_NAME).setAuthenticationType(AuthenticationType.PHONE) +// .setUsername(Util.USERNAME).setPassword(Util.PASSWORD).setPhoneNumber(Util.PHONE_NUMBER) +// .setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_FIRST_NAME), +// reply.getError().getCause().equals(Cause.MISSING_FIRST_NAME)); +// } +// +// @Test +// public void testCreateAccountInvalidFirstName() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName("n") +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_FIRST_NAME), +// reply.getError().getCause().equals(Cause.INVALID_FIRST_NAME)); +// } +// +// @Test +// public void testCreateAccountInvalidLastName() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName("ThisIsNotaValidLastNameIndeedAndItIsNotReal").setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setPhoneNumber(Util.PHONE_NUMBER).setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_LAST_NAME), +// reply.getError().getCause().equals(Cause.INVALID_LAST_NAME)); +// } +// +// @Test +// public void testCreateAccountInvalidEmail() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.EMAIL).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setEmailAddress(".invalid@email-.com").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(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)); +// } +// +// @Test +// public void testCreateAccountInvalidPhone() throws ExecutionException, InterruptedException { +// final CreateAccountRequest request = CreateAccountRequest.newBuilder().setFirstName(Util.FIRST_NAME) +// .setLastName(Util.LAST_NAME).setMiddleName(Util.MIDDLE_NAME) +// .setAuthenticationType(AuthenticationType.PHONE).setUsername(Util.USERNAME).setPassword(Util.PASSWORD) +// .setPhoneNumber("+45955588833648946512957").setCountryCode("BG").setStatus(Status.SUSPENDED).build(); +// +// List usersByPhone = new ArrayList<>(); +// List usersByEmail = new ArrayList<>(); +// List usersByUsername = new ArrayList<>(); +// given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); +// given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); +// given(userInfoByUsernameRepository.findByUsername(Util.USERNAME)).willReturn(usersByUsername); +// given(userInfoRepository.save(any(UserInfo.class))).willReturn(savedAccount); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountResponse reply = accountServiceBlockingStub.createAccount(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 testGetAccountsByProfileId() throws ExecutionException, InterruptedException { +// final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() +// .setProfileId(Util.PROFILE_ID.toString()).build(); +// +// List usersInfo = new ArrayList<>(); +// usersInfo.add(savedAccount); +// given(userInfoRepository.findAllByProfileId(UUID.fromString(request.getProfileId()))).willReturn(usersInfo); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain profile ID '%s'", Util.PROFILE_ID.toString()), +// reply.getAccountsResponse().getAccountDetails(0).getProfileId().equals(Util.PROFILE_ID.toString())); +// } +// +// @Test +// public void testGetAccountsByProfileIdNotFound() throws ExecutionException, InterruptedException { +// final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() +// .setProfileId(Util.PROFILE_ID.toString()).build(); +// +// List usersInfo = new ArrayList<>(); +// +// given(userInfoRepository.findAllByProfileId(Util.PROFILE_ID)).willReturn(usersInfo); +// +// final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc +// .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); +// +// final AccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); +// +// assertNotNull("Reply should not be null", reply); +// assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), +// reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); +// } +// @Test - public void testGetAccountsByEmail() throws ExecutionException, InterruptedException { - final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() - .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); - - List usersByEmail = new ArrayList<>(); - usersByEmail.add(userInfoByEmail); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + public void testGetAccountsByProfileIdBadRequest() throws ExecutionException, InterruptedException { + final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder().build(); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); + final AccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), - reply.getAccountsResponse().getAccountDetails(0).getEmailAddress().equals(Util.EMAIL)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_PROFILE_ID), + reply.getError().getCause().equals(Cause.MISSING_PROFILE_ID)); } @Test - public void testGetAccountsByEmailNotFound() throws ExecutionException, InterruptedException { - final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() - .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); + public void testGetAccountByAuthProviderPhone() { + final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + .setAuthenticationIdentifier(Util.PHONE_NUMBER).setAuthenticationType(AuthenticationType.PHONE).build(); - List usersByEmail = new ArrayList<>(); - given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); - } - - @Test - public void testGetAccountsByEmailBadRequest() throws ExecutionException, InterruptedException { - final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() - .setAuthenticationType(AuthenticationType.EMAIL).build(); + List accList = new ArrayList<>(); + accList.add(accountByPhone); + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(Util.PHONE_NUMBER)) + .willReturn(accList); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); - + final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + assertTrue( + String.format("Reply should contain authentication provider '%s'", + request.getAuthenticationIdentifier()), + reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.PHONE_NUMBER)); + assertTrue(String.format("Reply should contain authentication type '%s'", AuthenticationType.PHONE.name()), + reply.getAccountDetails().getAuthenticationType().equals(AuthenticationType.PHONE.name())); } @Test - public void testGetAccountsByPhone() throws ExecutionException, InterruptedException { - final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() - .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); + public void testGetAccountByAuthProviderMultipleRecords() { + final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + .setAuthenticationIdentifier(Util.EMAIL).setAuthenticationType(AuthenticationType.EMAIL).build(); - List usersByPhone = new ArrayList<>(); - usersByPhone.add(userInfoByPhone); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + List accList = new ArrayList<>(); + accList.add(accountByEmail); + accList.add(accountByFacebook); + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(Util.EMAIL)) + .willReturn(accList); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); - + final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), - reply.getAccountsResponse().getAccountDetails(0).getPhoneNumber().equals(Util.PHONE_NUMBER)); + assertTrue( + String.format("Reply should contain authentication provider '%s'", + request.getAuthenticationIdentifier()), + reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.EMAIL)); + assertTrue(String.format("Reply should contain authentication type '%s'", AuthenticationType.EMAIL.name()), + reply.getAccountDetails().getAuthenticationType().equals(AuthenticationType.EMAIL.name())); } @Test - public void testGetAccountsByPhoneNotFound() throws ExecutionException, InterruptedException { - final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() - .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); - - List usersByPhone = new ArrayList<>(); - given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - + public void testGetAccountByAuthProviderMissingType() { + final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + .build(); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); - + final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + 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 testGetAccountsByPhoneBadRequest() throws ExecutionException, InterruptedException { - final AccountsByAuthenticationProviderRequest request = AccountsByAuthenticationProviderRequest.newBuilder() + public void testGetAccountByAuthProviderMissingIdentifier() { + final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() .setAuthenticationType(AuthenticationType.PHONE).build(); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByAuthenticationProvider(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); - } - - @Test - public void testGetAccountsByProfileId() throws ExecutionException, InterruptedException { - final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() - .setProfileId(Util.PROFILE_ID.toString()).build(); - - List usersInfo = new ArrayList<>(); - usersInfo.add(savedAccount); - given(userInfoRepository.findAllByProfileId(UUID.fromString(request.getProfileId()))).willReturn(usersInfo); - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); - + final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain profile ID '%s'", Util.PROFILE_ID.toString()), - reply.getAccountsResponse().getAccountDetails(0).getProfileId().equals(Util.PROFILE_ID.toString())); + 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 testGetAccountsByProfileIdNotFound() throws ExecutionException, InterruptedException { - final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() - .setProfileId(Util.PROFILE_ID.toString()).build(); - - List usersInfo = new ArrayList<>(); - - given(userInfoRepository.findAllByProfileId(Util.PROFILE_ID)).willReturn(usersInfo); - + public void testGetAccountByAuthProviderNotFound() { + final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + .setAuthenticationIdentifier(Util.EMAIL).setAuthenticationType(AuthenticationType.EMAIL).build(); + List accList = new ArrayList<>(); + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(Util.EMAIL)) + .willReturn(accList); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); - + final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); assertNotNull("Reply should not be null", reply); assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); } - - @Test - public void testGetAccountsByProfileIdBadRequest() throws ExecutionException, InterruptedException { - final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder().build(); - - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - - final GetAccountsResponse reply = accountServiceBlockingStub.getAllAccountsByProfileId(request); - - assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_PROFILE_ID), - reply.getError().getCause().equals(Cause.MISSING_PROFILE_ID)); - } - } diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 6254fa38fc0dd39e5c94bc637e129e09376328bf..4f964be85b735034c22c949d313586fa27fad1ae 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -9,11 +9,9 @@ import java.util.UUID; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; -import biz.nynja.account.grpc.AuthenticationType; import biz.nynja.account.grpc.Status; -import biz.nynja.account.models.UserInfo; -import biz.nynja.account.models.UserInfoByEmail; -import biz.nynja.account.models.UserInfoByPhone;; +import biz.nynja.account.models.Account; +import biz.nynja.account.models.AccountByAuthenticationProvider; /** * Unit tests variables, beans and help methods. @@ -31,69 +29,73 @@ public class Util { public static final String LAST_NAME = "Doe"; public static final String MIDDLE_NAME = "Kass"; public static final String PHONE_NUMBER = "+359887434646"; + public static final String PHONE_TYPE = "PHONE"; + public static final String EMAIL_TYPE = "EMAIL"; + public static final String FACBOOK_TYPE = "FACEBOOK"; + public static final String GOOGLEPLUS_TYPE = "GOOGLEPLUS"; @Bean - public UserInfo newAccount() { - UserInfo userInfo = new UserInfo(); - userInfo.setUsername(USERNAME); - userInfo.setPassword(PASSWORD); - userInfo.setEmailAddress(EMAIL); - userInfo.setFirstName(FIRST_NAME); - userInfo.setLastName(LAST_NAME); - userInfo.setMiddleName(MIDDLE_NAME); - userInfo.setPhoneNumber(PHONE_NUMBER); - userInfo.setAuthenticationType(AuthenticationType.EMAIL); - userInfo.setStatus(Status.SUSPENDED); - return userInfo; + public Account newAccount() { + Account account = new Account(); + account.setUsername(USERNAME); + account.setFirstName(FIRST_NAME); + account.setLastName(LAST_NAME); + account.setUsername(USERNAME); + account.setFirstName(FIRST_NAME); + account.setLastName(LAST_NAME); + account.setAuthenticationProvider(EMAIL); + account.setAuthenticationProviderType(EMAIL_TYPE); + account.setAccountStatus(Status.SUSPENDED.name()); + return account; } @Bean - public UserInfo savedAccount() { - UserInfo userInfo = new UserInfo(); - userInfo.setAccountId(ACCOUNT_ID); - userInfo.setProfileId(PROFILE_ID); - userInfo.setEmailAddress(EMAIL); - userInfo.setUsername(USERNAME); - userInfo.setPassword(PASSWORD); - userInfo.setFirstName(FIRST_NAME); - userInfo.setLastName(LAST_NAME); - userInfo.setMiddleName(MIDDLE_NAME); - userInfo.setPhoneNumber(PHONE_NUMBER); - userInfo.setAuthenticationType(AuthenticationType.EMAIL); - userInfo.setStatus(Status.SUSPENDED); - return userInfo; + public Account savedAccount() { + Account account = new Account(); + account.setAccountId(ACCOUNT_ID); + account.setProfileId(PROFILE_ID); + account.setUsername(USERNAME); + account.setFirstName(FIRST_NAME); + account.setLastName(LAST_NAME); + return account; } @Bean - public UserInfoByEmail accountByEmail() { - UserInfoByEmail userInfoByEmail = new UserInfoByEmail(); - userInfoByEmail.setEmailAddress(EMAIL); - userInfoByEmail.setAccountId(ACCOUNT_ID); - userInfoByEmail.setProfileId(PROFILE_ID); - userInfoByEmail.setUsername(USERNAME); - userInfoByEmail.setFirstName(FIRST_NAME); - userInfoByEmail.setLastName(LAST_NAME); - userInfoByEmail.setMiddleName(MIDDLE_NAME); - userInfoByEmail.setPhoneNumber(PHONE_NUMBER); - userInfoByEmail.setAuthenticationType(AuthenticationType.EMAIL); - userInfoByEmail.setStatus(Status.SUSPENDED); - return userInfoByEmail; + public AccountByAuthenticationProvider accountByPhone() { + AccountByAuthenticationProvider accountByPhone = new AccountByAuthenticationProvider(); + accountByPhone.setAuthenticationProvider(PHONE_NUMBER); + accountByPhone.setAuthenticationProviderType(PHONE_TYPE); + accountByPhone.setAccountId(ACCOUNT_ID); + accountByPhone.setProfileId(PROFILE_ID); + accountByPhone.setUsername(USERNAME); + accountByPhone.setFirstName(FIRST_NAME); + accountByPhone.setLastName(LAST_NAME); + return accountByPhone; } @Bean - public UserInfoByPhone accountByPhone() { - UserInfoByPhone userInfoByPhone = new UserInfoByPhone(); - userInfoByPhone.setPhoneNumber(PHONE_NUMBER); - userInfoByPhone.setEmailAddress(EMAIL); - userInfoByPhone.setAccountId(ACCOUNT_ID); - userInfoByPhone.setProfileId(PROFILE_ID); - userInfoByPhone.setUsername(USERNAME); - userInfoByPhone.setFirstName(FIRST_NAME); - userInfoByPhone.setLastName(LAST_NAME); - userInfoByPhone.setMiddleName(MIDDLE_NAME); - userInfoByPhone.setAuthenticationType(AuthenticationType.EMAIL); - userInfoByPhone.setStatus(Status.SUSPENDED); - return userInfoByPhone; + public AccountByAuthenticationProvider accountByEmail() { + AccountByAuthenticationProvider accountByPhone = new AccountByAuthenticationProvider(); + accountByPhone.setAuthenticationProvider(EMAIL); + accountByPhone.setAuthenticationProviderType(EMAIL_TYPE); + accountByPhone.setAccountId(ACCOUNT_ID); + accountByPhone.setProfileId(PROFILE_ID); + accountByPhone.setUsername(USERNAME); + accountByPhone.setFirstName(FIRST_NAME); + accountByPhone.setLastName(LAST_NAME); + return accountByPhone; } + @Bean + public AccountByAuthenticationProvider accountByFacebook() { + AccountByAuthenticationProvider accountByPhone = new AccountByAuthenticationProvider(); + accountByPhone.setAuthenticationProvider(EMAIL); + accountByPhone.setAuthenticationProviderType(FACBOOK_TYPE); + accountByPhone.setAccountId(ACCOUNT_ID); + accountByPhone.setProfileId(PROFILE_ID); + accountByPhone.setUsername(USERNAME); + accountByPhone.setFirstName(FIRST_NAME); + accountByPhone.setLastName(LAST_NAME); + return accountByPhone; + } }