@Test(groups = "slow", description = "Test Account: verify minimal set of required fields") public void testMinimalFields() throws Exception { final String email = UUID.randomUUID().toString(); final String name = UUID.randomUUID().toString(); final AccountData accountData = new DefaultMutableAccountData(null, email, name, 0, null, null, false, 0, null, clock.getUTCNow(), null, null, null, null, null, null, null, null, null, null, null, false); final AccountModelDao account = new AccountModelDao(UUID.randomUUID(), accountData); accountDao.create(account, internalCallContext); final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext); checkAccountsEqual(retrievedAccount, account); // Verify a default external key was set Assert.assertEquals(retrievedAccount.getExternalKey(), retrievedAccount.getId().toString()); // Verify a default time zone was set Assert.assertEquals(retrievedAccount.getTimeZone(), DateTimeZone.UTC); }
public void mergeWithDelegate(final AccountModelDao currentAccount) { setExternalKey(currentAccount.getExternalKey()); setCurrency(currentAccount.getCurrency()); if (currentAccount.getBillingCycleDayLocal() == DEFAULT_BILLING_CYCLE_DAY_LOCAL && // There is *not* already a BCD set setBillingCycleDayLocal(billingCycleDayLocal); } else { setBillingCycleDayLocal(currentAccount.getBillingCycleDayLocal()); setEmail(email != null ? email : currentAccount.getEmail()); setName(name != null ? name : currentAccount.getName()); final Integer firstNameLength = this.firstNameLength != null ? this.firstNameLength : currentAccount.getFirstNameLength(); if (firstNameLength != null) { setFirstNameLength(firstNameLength); setPaymentMethodId(paymentMethodId != null ? paymentMethodId : currentAccount.getPaymentMethodId()); setTimeZone(timeZone != null ? timeZone : currentAccount.getTimeZone()); setLocale(locale != null ? locale : currentAccount.getLocale()); setAddress1(address1 != null ? address1 : currentAccount.getAddress1()); setAddress2(address2 != null ? address2 : currentAccount.getAddress2()); setCompanyName(companyName != null ? companyName : currentAccount.getCompanyName()); setCity(city != null ? city : currentAccount.getCity()); setStateOrProvince(stateOrProvince != null ? stateOrProvince : currentAccount.getStateOrProvince()); setCountry(country != null ? country : currentAccount.getCountry()); setPostalCode(postalCode != null ? postalCode : currentAccount.getPostalCode()); setPhone(phone != null ? phone : currentAccount.getPhone()); setNotes(notes != null ? notes : currentAccount.getNotes()); setParentAccountId(parentAccountId != null ? parentAccountId : currentAccount.getParentAccountId());
public DefaultImmutableAccountData(final AccountModelDao account) { this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone(), AccountDateTimeUtils.getFixedOffsetTimeZone(account), account.getReferenceTime()); }
public DefaultAccount(final AccountModelDao accountModelDao) { this(accountModelDao.getId(), accountModelDao.getCreatedDate(), accountModelDao.getUpdatedDate(), accountModelDao.getExternalKey(), accountModelDao.getEmail(), accountModelDao.getName(), accountModelDao.getFirstNameLength(), accountModelDao.getCurrency(), accountModelDao.getParentAccountId(), accountModelDao.getIsPaymentDelegatedToParent(), accountModelDao.getBillingCycleDayLocal(), accountModelDao.getPaymentMethodId(), accountModelDao.getReferenceTime(), accountModelDao.getTimeZone(), accountModelDao.getLocale(), accountModelDao.getAddress1(), accountModelDao.getAddress2(), accountModelDao.getCompanyName(), accountModelDao.getCity(), accountModelDao.getStateOrProvince(), accountModelDao.getCountry(), accountModelDao.getPostalCode(), accountModelDao.getPhone(), accountModelDao.getNotes(), accountModelDao.getMigrated()); }
final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); final AccountModelDao createdAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); List<AuditLogWithHistory> auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(account.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsWithHistory.size(), 1); Assert.assertEquals(history1.getAccountRecordId(), createdAccount.getRecordId()); Assert.assertEquals(history1.getTenantRecordId(), createdAccount.getTenantRecordId()); Assert.assertEquals(history1.getExternalKey(), createdAccount.getExternalKey()); Assert.assertEquals(history1.getMigrated(), createdAccount.getMigrated()); Assert.assertEquals(history1.getTimeZone(), createdAccount.getTimeZone()); Assert.assertEquals(history1.getLocale(), createdAccount.getLocale()); final AccountModelDao updatedAccount = new AccountModelDao(account.getId(), accountData); accountDao.update(updatedAccount, true, internalCallContext); final AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); checkAccountsEqual(retrievedAccount, updatedAccount); auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsWithHistory.size(), 2); Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT); Assert.assertEquals(auditLogsWithHistory.get(1).getChangeType(), ChangeType.UPDATE); Assert.assertEquals(history2.getAccountRecordId(), retrievedAccount.getRecordId()); Assert.assertEquals(history2.getTenantRecordId(), retrievedAccount.getTenantRecordId()); Assert.assertEquals(history2.getExternalKey(), retrievedAccount.getExternalKey()); Assert.assertEquals(history2.getMigrated(), retrievedAccount.getMigrated());
currentAccount.getExternalKey() != null && !currentAccount.getExternalKey().equals(externalKey)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account external key: new=%s, current=%s", externalKey, currentAccount.getExternalKey())); currentAccount.getCurrency() != null && !currentAccount.getCurrency().equals(currency)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account currency: new=%s, current=%s", currency, currentAccount.getCurrency())); currentAccount.getBillingCycleDayLocal() != DEFAULT_BILLING_CYCLE_DAY_LOCAL && // There is already a BCD set !currentAccount.getBillingCycleDayLocal().equals(billingCycleDayLocal)) { // and it does not match we we have throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account BCD: new=%s, current=%s", billingCycleDayLocal, currentAccount.getBillingCycleDayLocal())); currentAccount.getTimeZone() != null && !currentAccount.getTimeZone().equals(timeZone)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account timeZone: new=%s, current=%s", timeZone, currentAccount.getTimeZone())); if (referenceTime != null && currentAccount.getReferenceTime().withMillisOfDay(0).compareTo(referenceTime.withMillisOfDay(0)) != 0) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account referenceTime: new=%s, current=%s", referenceTime, currentAccount.getReferenceTime()));
AccountModelDao childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount); childAccountModelDao.setParentAccountId(parentAccount.getId()); childAccountModelDao.setIsPaymentDelegatedToParent(false); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext); childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount); childAccountModelDao.setIsPaymentDelegatedToParent(true); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
@Override public Pagination<AccountModelDao> searchAccounts(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) { final Collection<AccountModelDao> results = new LinkedList<AccountModelDao>(); int maxNbRecords = 0; for (final AccountModelDao account : getAll(context)) { maxNbRecords++; if ((account.getName() != null && account.getName().contains(searchKey)) || (account.getEmail() != null && account.getEmail().contains(searchKey)) || (account.getExternalKey() != null && account.getExternalKey().contains(searchKey)) || (account.getCompanyName() != null && account.getCompanyName().contains(searchKey))) { results.add(account); } } return DefaultPagination.<AccountModelDao>build(offset, limit, maxNbRecords, results); }
private void updateAccount(final UUID accountId, final AccountData account, final boolean treatNullValueAsReset, final CallContext context) throws AccountApiException { final AccountModelDao updatedAccountModelDao = new AccountModelDao(accountId, null, null, account, false); accountDao.update(updatedAccountModelDao, treatNullValueAsReset, internalCallContextFactory.createInternalCallContext(accountId, context)); }
childAccountModelDao1.setId(childAccount1.getId()); childAccountModelDao1.setParentAccountId(parentAccount.getId()); childAccountModelDao1.setIsPaymentDelegatedToParent(true); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext); childAccountModelDao1.setParentAccountId(null); childAccountModelDao1.setIsPaymentDelegatedToParent(false); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext); childAccountModelDao2.setId(childAccount2.getId()); childAccountModelDao2.setParentAccountId(parentAccount.getId()); childAccountModelDao2.setIsPaymentDelegatedToParent(true); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao2), callContext);
@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); }
@Test(groups = "slow", description = "Test Account create Parent and Child") public void testCreateParentAndChildAccounts() throws Exception { final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext); final AccountModelDao childAccountModel = createTestAccount(); childAccountModel.setParentAccountId(parentAccount.getId()); childAccountModel.setIsPaymentDelegatedToParent(true); final AccountData childAccountData = new DefaultAccount(childAccountModel); final Account childAccount = accountUserApi.createAccount(childAccountData, callContext); final Account retrievedChildAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); Assert.assertNull(parentAccount.getParentAccountId()); Assert.assertNotNull(retrievedChildAccount.getParentAccountId()); Assert.assertEquals(retrievedChildAccount.getId(), childAccount.getId()); Assert.assertEquals(retrievedChildAccount.getParentAccountId(), parentAccount.getId()); Assert.assertEquals(retrievedChildAccount.isPaymentDelegatedToParent(), childAccount.isPaymentDelegatedToParent()); }
@Test(groups = "slow", description = "Test Account DAO: basic update (2)") public void testShouldBeAbleToUpdateSomeFields() throws Exception { final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); final MutableAccountData otherAccount = new DefaultAccount(account).toMutableAccountData(); otherAccount.setAddress1(UUID.randomUUID().toString()); otherAccount.setEmail(UUID.randomUUID().toString()); final AccountModelDao newAccount = new AccountModelDao(account.getId(), otherAccount); accountDao.update(newAccount, true, internalCallContext); final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext); checkAccountsEqual(retrievedAccount, newAccount); }
@Test(groups = "slow", description = "Test Account create Child with a non existing Parent", expectedExceptions = AccountApiException.class, expectedExceptionsMessageRegExp = "Account does not exist for id .*") public void testCreateChildAccountWithInvalidParent() throws Exception { final AccountModelDao childAccountModel = createTestAccount(); childAccountModel.setParentAccountId(UUID.randomUUID()); final AccountData childAccountData = new DefaultAccount(childAccountModel); final Account childAccount = accountUserApi.createAccount(childAccountData, callContext); }
@Override public Integer getAccountBCD(final UUID accountId, final InternalTenantContext context) { final AccountModelDao account = getById(accountId, context); return account != null ? account.getBillingCycleDayLocal() : 0; }
public DefaultAccountData(final AccountModelDao d) { this(d.getExternalKey(), d.getName(), d.getFirstNameLength(), d.getEmail(), d.getBillingCycleDayLocal(), d.getCurrency() != null ? d.getCurrency().name() : null, d.getParentAccountId(), d.getIsPaymentDelegatedToParent(), d.getPaymentMethodId(), d.getReferenceTime() != null ? d.getReferenceTime().toString() : null, d.getTimeZone() != null ? d.getTimeZone().getID() : null, d.getLocale(), d.getAddress1(), d.getAddress2(), d.getCompanyName(), d.getCity(), d.getStateOrProvince(), d.getPostalCode(), d.getCountry(), d.getPhone(), d.getNotes(), d.getMigrated()); }
public DefaultImmutableAccountData(final AccountModelDao account) { this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone(), AccountDateTimeUtils.getFixedOffsetTimeZone(account), account.getReferenceTime()); }
currentAccount.getExternalKey() != null && !currentAccount.getExternalKey().equals(externalKey)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account external key: new=%s, current=%s", externalKey, currentAccount.getExternalKey())); currentAccount.getCurrency() != null && !currentAccount.getCurrency().equals(currency)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account currency: new=%s, current=%s", currency, currentAccount.getCurrency())); currentAccount.getBillingCycleDayLocal() != DEFAULT_BILLING_CYCLE_DAY_LOCAL && // There is already a BCD set !currentAccount.getBillingCycleDayLocal().equals(billingCycleDayLocal)) { // and it does not match we we have throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account BCD: new=%s, current=%s", billingCycleDayLocal, currentAccount.getBillingCycleDayLocal())); currentAccount.getTimeZone() != null && !currentAccount.getTimeZone().equals(timeZone)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account timeZone: new=%s, current=%s", timeZone, currentAccount.getTimeZone())); if (referenceTime != null && currentAccount.getReferenceTime().withMillisOfDay(0).compareTo(referenceTime.withMillisOfDay(0)) != 0) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account referenceTime: new=%s, current=%s", referenceTime, currentAccount.getReferenceTime()));
final AccountModelDao childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount); childAccountModelDao.setParentAccountId(null); childAccountModelDao.setIsPaymentDelegatedToParent(false); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
public static void checkAccountsEqual(final AccountData retrievedAccount, final AccountData account) { final UUID fakeId = UUID.randomUUID(); checkAccountsEqual(new AccountModelDao(fakeId, retrievedAccount), new AccountModelDao(fakeId, account)); }