From a4591862d5fccc2d305981cd9d5175aae185fff8 Mon Sep 17 00:00:00 2001 From: Ralitsa Todorova Date: Wed, 5 Sep 2018 15:40:22 +0300 Subject: [PATCH 1/2] NY-3113: validation during the Account transformation - add unit tests for get account - get account by account id added Signed-off-by: Ralitsa Todorova --- .../biz/nynja/account/models/Account.java | 43 +- .../account/models/AccountByProfileId.java | 44 +- .../account/services/AccountServiceImpl.java | 35 + .../account/services/AccountServiceTests.java | 821 +++++++++++------- .../java/biz/nynja/account/utils/Util.java | 37 + 5 files changed, 638 insertions(+), 342 deletions(-) diff --git a/src/main/java/biz/nynja/account/models/Account.java b/src/main/java/biz/nynja/account/models/Account.java index cffdbaf..8d1ade3 100644 --- a/src/main/java/biz/nynja/account/models/Account.java +++ b/src/main/java/biz/nynja/account/models/Account.java @@ -285,16 +285,45 @@ public class Account { public AccountDetails toProto() { - Builder builder = AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setAuthenticationIdentifier(getAuthenticationProvider()) - .setAuthenticationType(getAuthenticationProviderType()).setAccountMark(getAccountMark()) - .setAccountName(getAccountName()).setFirstName(getFirstName()).setLastName(getLastName()) - .setUsername(getUsername()).setAccountStatus(getAccountStatus()).setQrCode(getQrCode()); + Builder builder = AccountDetails.newBuilder(); - if (avatar != null) { + 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 (getAvatar() != null) { builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); } - if (communicationProviders != null) { + if (getCommunicationProviders() != null) { for (AuthenticationProvider ap : communicationProviders) { builder.addCommunicationProviders(ap.toProto()); } diff --git a/src/main/java/biz/nynja/account/models/AccountByProfileId.java b/src/main/java/biz/nynja/account/models/AccountByProfileId.java index 21573a3..14b779b 100644 --- a/src/main/java/biz/nynja/account/models/AccountByProfileId.java +++ b/src/main/java/biz/nynja/account/models/AccountByProfileId.java @@ -7,6 +7,10 @@ import java.nio.ByteBuffer; import java.util.Set; import java.util.UUID; +import org.springframework.data.cassandra.core.cql.PrimaryKeyType; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; + +import biz.nynja.account.grpc.AccountDetails; import biz.nynja.account.grpc.AccountDetails.Builder; public class AccountByProfileId { @@ -271,19 +275,45 @@ public class AccountByProfileId { public biz.nynja.account.grpc.AccountDetails toProto() { - Builder builder = biz.nynja.account.grpc.AccountDetails.newBuilder().setAccountId(getAccountId().toString()) - .setProfileId(getProfileId().toString()).setAuthenticationIdentifier(getAuthenticationProvider()) - .setAuthenticationType(getAuthenticationProviderType()).setAccountMark(getAccountMark()) - .setAccountName(getAccountName()).setFirstName(getFirstName()).setLastName(getLastName()) - .setUsername(getUsername()).setAccountStatus(getAccountStatus()); + Builder builder = 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) { + if (getAvatar() != null) { builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); } - if (communicationProviders != null) { + if (getCommunicationProviders() != null) { for (AuthenticationProvider ap : communicationProviders) { builder.addCommunicationProviders(ap.toProto()); } diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index a06dda4..8738c2c 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import biz.nynja.account.components.Validator; +import biz.nynja.account.grpc.AccountByAccountIdRequest; import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; import biz.nynja.account.grpc.AccountDetails; import biz.nynja.account.grpc.AccountResponse; @@ -33,6 +34,7 @@ import biz.nynja.account.models.AccountByProfileId; import biz.nynja.account.models.PendingAccount; 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 io.grpc.stub.StreamObserver; @@ -46,6 +48,8 @@ import io.grpc.stub.StreamObserver; public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBase { private static final Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class); + @Autowired + private AccountRepository accountRepository; @Autowired private AccountByProfileIdRepository accountByProfileIdRepository; @@ -166,6 +170,37 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + @Override + public void getAccountByAccountId(AccountByAccountIdRequest request, + StreamObserver responseObserver) { + logger.info("Getting accounts by account id: {}", request.getAccountId()); + + if ((request.getAccountId() == null) || (request.getAccountId().isEmpty())) { + responseObserver.onNext(AccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_ACCOUNT_ID)).build()); + responseObserver.onCompleted(); + return; + } + + Account account = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); + + if (account.getAccountId() == null) { + responseObserver.onNext(AccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + AccountsResponse response = AccountsResponse.newBuilder() + .setAccountsResponse(AccountsList.newBuilder().addAccountDetails(account.toProto())).build(); + + logger.debug("Returned response: \"{}\".", response); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + return; + } + @Override public void createPendingAccount(CreatePendingAccountRequest request, StreamObserver responseObserver) { diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 47f251a..455f4a5 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -5,7 +5,6 @@ package biz.nynja.account.services; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import java.util.ArrayList; @@ -17,7 +16,6 @@ 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; @@ -25,21 +23,22 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; 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.AccountByAccountIdRequest; import biz.nynja.account.grpc.AccountServiceGrpc; 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.ErrorResponse.Cause; -import biz.nynja.account.grpc.Status; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; +import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.repositories.AccountByProfileIdRepository; +import biz.nynja.account.repositories.AccountRepository; import biz.nynja.account.utils.GrpcServerTestBase; import biz.nynja.account.utils.Util; @@ -49,7 +48,7 @@ import biz.nynja.account.utils.Util; @RunWith(SpringRunner.class) @SpringBootTest(classes = { Util.class, CassandraTestsConfig.class }, - webEnvironment = WebEnvironment.RANDOM_PORT, + webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration" }) @@ -79,327 +78,493 @@ public class AccountServiceTests extends GrpcServerTestBase { @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)); -// } -// + @Autowired + @Qualifier("savedAccountByProfileId") + private AccountByProfileId savedAccountByProfileId; + + @MockBean + private AccountRepository accountRepository; + + @MockBean + private AccountByProfileIdRepository accountByProffileIdRepository; + + // @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 testGetAccountsByEmail() throws ExecutionException, InterruptedException { + // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + // .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); + // + // List usersByEmail = new ArrayList<>(); + // usersByEmail.add(userInfoByEmail); + // given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + // + // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + // + // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); + // + // assertNotNull("Reply should not be null", reply); + // assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), + // reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.EMAIL)); + // } + // + // @Test + // public void testGetAccountsByEmailNotFound() throws ExecutionException, InterruptedException { + // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + // .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); + // + // List usersByEmail = new ArrayList<>(); + // given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); + // + // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + // + // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); + // + // assertNotNull("Reply should not be null", reply); + // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + // } + // + // @Test + // public void testGetAccountsByEmailBadRequest() throws ExecutionException, InterruptedException { + // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + // .setAuthenticationType(AuthenticationType.EMAIL).build(); + // + // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + // + // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); + // + // assertNotNull("Reply should not be null", reply); + // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + // } + // + // @Test + // public void testGetAccountsByPhone() throws ExecutionException, InterruptedException { + // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + // .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); + // + // List usersByPhone = new ArrayList<>(); + // usersByPhone.add(userInfoByPhone); + // given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + // + // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + // + // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); + // + // assertNotNull("Reply should not be null", reply); + // assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), + // reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.PHONE_NUMBER)); + // } + // + // @Test + // public void testGetAccountsByPhoneNotFound() throws ExecutionException, InterruptedException { + // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + // .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); + // + // List usersByPhone = new ArrayList<>(); + // given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); + // + // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + // + // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); + // + // assertNotNull("Reply should not be null", reply); + // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + // } + // + // @Test + // public void testGetAccountsByPhoneBadRequest() throws ExecutionException, InterruptedException { + // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() + // .setAuthenticationType(AuthenticationType.PHONE).build(); + // + // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + // + // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); + // + // assertNotNull("Reply should not be null", reply); + // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), + // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); + // } + + @Test + public void testGetAccountByAccountId() throws ExecutionException, InterruptedException { + final AccountByAccountIdRequest request = AccountByAccountIdRequest.newBuilder() + .setAccountId(Util.ACCOUNT_ID.toString()).build(); + + Account account = savedAccount; + + given(accountRepository.findByAccountId(UUID.fromString(request.getAccountId()))).willReturn(account); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final AccountsResponse reply = accountServiceBlockingStub.getAccountByAccountId(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain profile ID '%s'", Util.ACCOUNT_ID.toString()), + reply.getAccountsResponse().getAccountDetails(0).getAccountId().equals(Util.ACCOUNT_ID.toString())); + } + + @Test + public void testGetAccountByAccountIdNotFound() throws ExecutionException, InterruptedException { + final AccountByAccountIdRequest request = AccountByAccountIdRequest.newBuilder() + .setAccountId(Util.ACCOUNT_ID.toString()).build(); + + Account account = new Account(); + + given(accountRepository.findByAccountId(UUID.fromString(request.getAccountId()))).willReturn(account); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final AccountsResponse reply = accountServiceBlockingStub.getAccountByAccountId(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 testGetAccountByAccountIdBadRequest() throws ExecutionException, InterruptedException { + + final AccountByAccountIdRequest request = AccountByAccountIdRequest.newBuilder().build(); + + final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final AccountsResponse reply = accountServiceBlockingStub.getAccountByAccountId(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_ACCOUNT_ID), + reply.getError().getCause().equals(Cause.MISSING_ACCOUNT_ID)); + } + + @Test + public void testGetAccountsByProfileId() throws ExecutionException, InterruptedException { + final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).build(); + + List accountByProfileId = new ArrayList<>(); + accountByProfileId.add(savedAccountByProfileId); + + given(accountByProffileIdRepository.findAllByProfileId(UUID.fromString(request.getProfileId()))) + .willReturn(accountByProfileId); + + 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 accountsByProfileId = new ArrayList<>(); + + given(accountByProffileIdRepository.findAllByProfileId(Util.PROFILE_ID)).willReturn(accountsByProfileId); + + 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 testGetAccountsByProfileIdBadRequest() throws ExecutionException, InterruptedException { final AccountsByProfileIdRequest request = AccountsByProfileIdRequest.newBuilder().build(); diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 4f964be..6c976e0 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -4,6 +4,9 @@ package biz.nynja.account.utils; +import java.nio.ByteBuffer; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import org.springframework.boot.test.context.TestConfiguration; @@ -12,6 +15,8 @@ import org.springframework.context.annotation.Bean; import biz.nynja.account.grpc.Status; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; +import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.models.AuthenticationProvider; /** * Unit tests variables, beans and help methods. @@ -22,6 +27,16 @@ public class Util { public static final UUID PROFILE_ID = UUID.fromString("12352345-e89b-43d3-d156-456732452200"); public static final UUID ACCOUNT_ID = UUID.fromString("44532732-12b3-132d-e156-223732152200"); + public static final String ACCOUNT_MARK = "AccountMark"; + public static final String AUTHENTICATION_PROVIDER = "Provider"; + public static final String AUTHENTICATION_PROVIDER_TYPE = "ProviderType"; + public static final ByteBuffer AVATAR = ByteBuffer.allocate(42); + public static final String ACCOUNT_NAME = "AccountName"; + public static final String ACCOUNT_STATUS = "active"; + public static final long CREATION_TIMESTAMP = 45; + public static final long LAST_UPDATE_TIMESTAMP = 80; + public static final Set COMMUNICATION_PROVIDERS= new HashSet(); + public static final String QR_CODE = "QRcode"; public static final String EMAIL = "email@test.com"; public static final String USERNAME = "jdoe"; public static final String PASSWORD = "abc123"; @@ -47,6 +62,27 @@ public class Util { account.setAuthenticationProviderType(EMAIL_TYPE); account.setAccountStatus(Status.SUSPENDED.name()); return account; + } + + @Bean + public AccountByProfileId savedAccountByProfileId() { + AccountByProfileId account = new AccountByProfileId(); + account.setAccountId(ACCOUNT_ID); + account.setProfileId(PROFILE_ID); + account.setAccountMark(ACCOUNT_MARK); + account.setAuthenticationProvider(AUTHENTICATION_PROVIDER); + account.setAuthenticationProviderType(AUTHENTICATION_PROVIDER_TYPE); + account.setFirstName(FIRST_NAME); + account.setLastName(LAST_NAME); + account.setAvatar(AVATAR); + account.setAccountName(ACCOUNT_NAME); + account.setAccountStatus(ACCOUNT_STATUS); + account.setUsername(USERNAME); + account.setCreationTimestamp(CREATION_TIMESTAMP); + account.setLastUpdateTimestamp(LAST_UPDATE_TIMESTAMP); + account.setCommunicationProviders(COMMUNICATION_PROVIDERS); + account.setQrCode(QR_CODE); + return account; } @Bean @@ -57,6 +93,7 @@ public class Util { account.setUsername(USERNAME); account.setFirstName(FIRST_NAME); account.setLastName(LAST_NAME); + return account; } -- GitLab From b4c0802301bc5201283f70c0484ff1adf8e6075c Mon Sep 17 00:00:00 2001 From: Ralitsa Todorova Date: Wed, 5 Sep 2018 16:10:49 +0300 Subject: [PATCH 2/2] NY_3113: remove commented code Signed-off-by: Ralitsa Todorova --- .../account/services/AccountServiceTests.java | 384 ------------------ 1 file changed, 384 deletions(-) diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 455f4a5..91c6697 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -88,390 +88,6 @@ public class AccountServiceTests extends GrpcServerTestBase { @MockBean private AccountByProfileIdRepository accountByProffileIdRepository; - // @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 testGetAccountsByEmail() throws ExecutionException, InterruptedException { - // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() - // .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); - // - // List usersByEmail = new ArrayList<>(); - // usersByEmail.add(userInfoByEmail); - // given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - // - // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - // - // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); - // - // assertNotNull("Reply should not be null", reply); - // assertTrue(String.format("Reply should contain email '%s'", Util.EMAIL), - // reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.EMAIL)); - // } - // - // @Test - // public void testGetAccountsByEmailNotFound() throws ExecutionException, InterruptedException { - // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() - // .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationIdentifier(Util.EMAIL).build(); - // - // List usersByEmail = new ArrayList<>(); - // given(userInfoByEmailRepository.findByEmailAddress(Util.EMAIL)).willReturn(usersByEmail); - // - // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - // - // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); - // - // assertNotNull("Reply should not be null", reply); - // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); - // } - // - // @Test - // public void testGetAccountsByEmailBadRequest() throws ExecutionException, InterruptedException { - // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() - // .setAuthenticationType(AuthenticationType.EMAIL).build(); - // - // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - // - // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); - // - // assertNotNull("Reply should not be null", reply); - // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); - // } - // - // @Test - // public void testGetAccountsByPhone() throws ExecutionException, InterruptedException { - // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() - // .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); - // - // List usersByPhone = new ArrayList<>(); - // usersByPhone.add(userInfoByPhone); - // given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - // - // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - // - // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); - // - // assertNotNull("Reply should not be null", reply); - // assertTrue(String.format("Reply should contain phone '%s'", Util.PHONE_NUMBER), - // reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.PHONE_NUMBER)); - // } - // - // @Test - // public void testGetAccountsByPhoneNotFound() throws ExecutionException, InterruptedException { - // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() - // .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationIdentifier(Util.PHONE_NUMBER).build(); - // - // List usersByPhone = new ArrayList<>(); - // given(userInfoByPhoneRepository.findByPhoneNumber(Util.PHONE_NUMBER)).willReturn(usersByPhone); - // - // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - // - // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); - // - // assertNotNull("Reply should not be null", reply); - // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); - // } - // - // @Test - // public void testGetAccountsByPhoneBadRequest() throws ExecutionException, InterruptedException { - // final AccountByAuthenticationProviderRequest request = AccountByAuthenticationProviderRequest.newBuilder() - // .setAuthenticationType(AuthenticationType.PHONE).build(); - // - // final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - // .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - // - // final AccountResponse reply = accountServiceBlockingStub.getAccountByAuthenticationProvider(request); - // - // assertNotNull("Reply should not be null", reply); - // assertTrue(String.format("Reply should contain cause '%s'", Cause.ACCOUNT_NOT_FOUND), - // reply.getError().getCause().equals(Cause.ACCOUNT_NOT_FOUND)); - // } - @Test public void testGetAccountByAccountId() throws ExecutionException, InterruptedException { final AccountByAccountIdRequest request = AccountByAccountIdRequest.newBuilder() -- GitLab