@BeforeMethod(groups = "fast") public void setUp() throws Exception { accountDao = new MockAccountDao(Mockito.mock(PersistentBus.class), clock); accountUserApi = new DefaultAccountUserApi(immutableAccountInternalApi, accountDao, nonEntityDao, controllerDispatcher, internalFactory); }
@Override public Account getAccountById(final UUID id, final TenantContext context) throws AccountApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(id, context); return getAccountById(id, internalTenantContext); }
@Override public void updateAccount(final String externalKey, final AccountData accountData, final CallContext context) throws AccountApiException { final Account currentAccount = getAccountByKey(externalKey, context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, externalKey); } updateAccount(currentAccount.getId(), accountData, false, context); }
@Test(groups = "fast", description = "Test ability to add email to Account") public void testAddEmail() throws Exception { final UUID accountId = UUID.randomUUID(); // Verify the initial state Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 0); // Add the first email final String emailAddress1 = UUID.randomUUID().toString(); final AccountEmail email1 = new DefaultAccountEmail(accountId, emailAddress1); accountUserApi.addEmail(accountId, email1, callContext); Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 1); // Add a second one final String emailAddress2 = UUID.randomUUID().toString(); final AccountEmail email2 = new DefaultAccountEmail(accountId, emailAddress2); accountUserApi.addEmail(accountId, email2, callContext); Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 2); // Remove the first second one accountUserApi.removeEmail(accountId, email1, callContext); Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 1); } }
@Override public void updateAccount(final UUID accountId, final AccountData accountData, final CallContext context) throws AccountApiException { updateAccount(accountId, accountData, false, context); }
@Override public Account getAccountByKey(final String key, final TenantContext context) throws AccountApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context); return getAccountByKey(key, internalTenantContext); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { // Not transactional, but there is a db constraint on that column if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) { throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey()); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); if (data.getParentAccountId() != null) { // verify that parent account exists if parentAccountId is not null final ImmutableAccountData immutableAccountData = immutableAccountInternalApi.getImmutableAccountDataById(data.getParentAccountId(), internalContext); if (immutableAccountData == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, data.getParentAccountId()); } } final AccountModelDao account = new AccountModelDao(data); if (null != account.getExternalKey() && account.getExternalKey().length() > 255) { throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultAccount(account); }
city, stateOrProvince, country, postalCode, phone, notes, isMigrated); accountUserApi.createAccount(data, callContext);
@Override public void updateAccount(final Account account, final CallContext context) throws AccountApiException { updateAccount(account.getId(), account, true, context); }
@Override public Account getAccountByKey(final String key, final TenantContext context) throws AccountApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context); return getAccountByKey(key, internalTenantContext); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { // Not transactional, but there is a db constraint on that column if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) { throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey()); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); if (data.getParentAccountId() != null) { // verify that parent account exists if parentAccountId is not null final ImmutableAccountData immutableAccountData = immutableAccountInternalApi.getImmutableAccountDataById(data.getParentAccountId(), internalContext); if (immutableAccountData == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, data.getParentAccountId()); } } final AccountModelDao account = new AccountModelDao(data); if (null != account.getExternalKey() && account.getExternalKey().length() > 255) { throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultAccount(account); }
@Override public void updateAccount(final String externalKey, final AccountData accountData, final CallContext context) throws AccountApiException { final Account currentAccount = getAccountByKey(externalKey, context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, externalKey); } updateAccount(currentAccount.getId(), accountData, false, context); }
@Override public void updateAccount(final UUID accountId, final AccountData accountData, final CallContext context) throws AccountApiException { updateAccount(accountId, accountData, false, context); }
@Override public Account getAccountById(final UUID id, final TenantContext context) throws AccountApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(id, context); return getAccountById(id, internalTenantContext); }
@Override public void updateAccount(final Account account, final CallContext context) throws AccountApiException { updateAccount(account.getId(), account, true, context); }