final DefaultMutableAccountData accountData = new DefaultMutableAccountData(this); accountData.setExternalKey(currentAccount.getExternalKey()); accountData.setCurrency(currentAccount.getCurrency()); accountData.setBillCycleDayLocal(billCycleDayLocal); } else { accountData.setBillCycleDayLocal(currentAccount.getBillCycleDayLocal()); accountData.setEmail(email != null ? email : currentAccount.getEmail()); accountData.setName(name != null ? name : currentAccount.getName()); final Integer firstNameLength = this.firstNameLength != null ? this.firstNameLength : currentAccount.getFirstNameLength(); if (firstNameLength != null) { accountData.setFirstNameLength(firstNameLength); accountData.setPaymentMethodId(paymentMethodId != null ? paymentMethodId : currentAccount.getPaymentMethodId()); accountData.setTimeZone(timeZone != null ? timeZone : currentAccount.getTimeZone()); accountData.setLocale(locale != null ? locale : currentAccount.getLocale()); accountData.setAddress1(address1 != null ? address1 : currentAccount.getAddress1()); accountData.setAddress2(address2 != null ? address2 : currentAccount.getAddress2()); accountData.setCompanyName(companyName != null ? companyName : currentAccount.getCompanyName()); accountData.setCity(city != null ? city : currentAccount.getCity()); accountData.setStateOrProvince(stateOrProvince != null ? stateOrProvince : currentAccount.getStateOrProvince()); accountData.setCountry(country != null ? country : currentAccount.getCountry()); accountData.setPostalCode(postalCode != null ? postalCode : currentAccount.getPostalCode()); accountData.setPhone(phone != null ? phone : currentAccount.getPhone()); accountData.setNotes(notes != null ? notes : currentAccount.getNotes()); accountData.setParentAccountId(parentAccountId != null ? parentAccountId : currentAccount.getParentAccountId());
@Override public MutableAccountData toMutableAccountData() { return new DefaultMutableAccountData(this); }
@Override public void updatePaymentMethod(final UUID accountId, final UUID paymentMethodId, final InternalCallContext context) throws AccountApiException { final AccountModelDao currentAccountModelDao = getById(accountId, context); if (currentAccountModelDao == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } final DefaultAccount currentAccount = new DefaultAccount(currentAccountModelDao); final DefaultMutableAccountData updatedAccount = new DefaultMutableAccountData(currentAccount); updatedAccount.setPaymentMethodId(paymentMethodId); update(new AccountModelDao(accountId, updatedAccount), context); }
final DefaultMutableAccountData accountDataWithZeroBCD = new DefaultMutableAccountData(accountDataWithNullBCD); accountDataWithZeroBCD.setBillCycleDayLocal(0); final Account accountWithZeroBCD = new DefaultAccount(accountId, accountDataWithZeroBCD); final DefaultMutableAccountData accountDataWithRealBCD = new DefaultMutableAccountData(accountDataWithNullBCD); accountDataWithRealBCD.setBillCycleDayLocal(12); final Account accountWithRealBCD = new DefaultAccount(accountId, accountDataWithRealBCD); final DefaultMutableAccountData accountDataWithAnotherRealBCD = new DefaultMutableAccountData(accountDataWithNullBCD); accountDataWithAnotherRealBCD.setBillCycleDayLocal(20); final Account accountWithAnotherBCD = new DefaultAccount(accountId, accountDataWithAnotherRealBCD);
private static MutableAccountData createAccountData(final int billCycleDayLocal, final String phone) { final String externalKey = UUID.randomUUID().toString(); final String email = UUID.randomUUID().toString().substring(0, 4) + '@' + UUID.randomUUID().toString().substring(0, 4); final String name = UUID.randomUUID().toString(); final String locale = Locale.GERMANY.toString(); final DateTimeZone timeZone = DateTimeZone.forID("America/Los_Angeles"); final int firstNameLength = name.length(); final Currency currency = Currency.MXN; final UUID paymentMethodId = UUID.randomUUID(); final String address1 = UUID.randomUUID().toString(); final String address2 = UUID.randomUUID().toString(); final String companyName = UUID.randomUUID().toString(); final String city = UUID.randomUUID().toString(); final String stateOrProvince = UUID.randomUUID().toString(); final String country = Locale.GERMANY.getCountry(); final String postalCode = UUID.randomUUID().toString().substring(0, 4); final String notes = UUID.randomUUID().toString(); return new DefaultMutableAccountData(externalKey, email, name, firstNameLength, currency, null, false, billCycleDayLocal, paymentMethodId, null, timeZone, locale, address1, address2, companyName, city, stateOrProvince, country, postalCode, phone, notes, false); } }
final DefaultMutableAccountData accountData = new DefaultMutableAccountData(this); accountData.setExternalKey(currentAccount.getExternalKey()); accountData.setCurrency(currentAccount.getCurrency()); accountData.setBillCycleDayLocal(billCycleDayLocal); } else { accountData.setBillCycleDayLocal(currentAccount.getBillCycleDayLocal()); accountData.setEmail(email != null ? email : currentAccount.getEmail()); accountData.setName(name != null ? name : currentAccount.getName()); final Integer firstNameLength = this.firstNameLength != null ? this.firstNameLength : currentAccount.getFirstNameLength(); if (firstNameLength != null) { accountData.setFirstNameLength(firstNameLength); accountData.setPaymentMethodId(paymentMethodId != null ? paymentMethodId : currentAccount.getPaymentMethodId()); accountData.setTimeZone(timeZone != null ? timeZone : currentAccount.getTimeZone()); accountData.setLocale(locale != null ? locale : currentAccount.getLocale()); accountData.setAddress1(address1 != null ? address1 : currentAccount.getAddress1()); accountData.setAddress2(address2 != null ? address2 : currentAccount.getAddress2()); accountData.setCompanyName(companyName != null ? companyName : currentAccount.getCompanyName()); accountData.setCity(city != null ? city : currentAccount.getCity()); accountData.setStateOrProvince(stateOrProvince != null ? stateOrProvince : currentAccount.getStateOrProvince()); accountData.setCountry(country != null ? country : currentAccount.getCountry()); accountData.setPostalCode(postalCode != null ? postalCode : currentAccount.getPostalCode()); accountData.setPhone(phone != null ? phone : currentAccount.getPhone()); accountData.setNotes(notes != null ? notes : currentAccount.getNotes()); accountData.setParentAccountId(parentAccountId != null ? parentAccountId : currentAccount.getParentAccountId());
@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); }
@Test(groups = "slow", description = "Test failure on resetting externalKey", expectedExceptions = IllegalArgumentException.class) public void testAccountResetExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setExternalKey(null); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test failure on changing externalKey", expectedExceptions = IllegalArgumentException.class) public void testAccountChangeExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setExternalKey("somethingVeryDifferent"); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test failure on resetting BCD", expectedExceptions = IllegalArgumentException.class) public void testAccountResetBCD() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setBillCycleDayLocal(DEFAULT_BILLING_CYCLE_DAY_LOCAL); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test failure on changing timeZone", expectedExceptions = IllegalArgumentException.class) public void testAccountChangingTimeZone() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setTimeZone(DateTimeZone.UTC); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test failure on resetting currency", expectedExceptions = IllegalArgumentException.class) public void testAccountResetCurrency() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setCurrency(null); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test failure on changing currency", expectedExceptions = IllegalArgumentException.class) public void testAccountChangeCurrency() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setCurrency(Currency.AFN); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test failure on resetting timeZone", expectedExceptions = IllegalArgumentException.class) public void testAccountResetTimeZone() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setTimeZone(null); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Test(groups = "slow", description = "Test Account update with null values") public void testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(null, null, null, 0, null, null, false, 0, null, clock.getUTCNow(), null, null, null, null, null, null, null, null, null, null, null, false); final String newAddress1 = UUID.randomUUID().toString(); mutableAccountData.setAddress1(newAddress1); accountUserApi.updateAccount(account.getId(), mutableAccountData, callContext); final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext); Assert.assertEquals(retrievedAccount.getAddress1(), newAddress1); Assert.assertEquals(retrievedAccount.getAddress2(), account.getAddress2()); Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency()); Assert.assertEquals(retrievedAccount.getExternalKey(), account.getExternalKey()); Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal()); }
final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setNotes(null);
@Override public MutableAccountData toMutableAccountData() { return new DefaultMutableAccountData(this); }