@Override public void updateBCD(final String externalKey, final int bcd, final InternalCallContext context) throws AccountApiException { final Account currentAccount = getAccountByKey(externalKey, context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, externalKey); } if (currentAccount.getBillCycleDayLocal() != DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL) { throw new AccountApiException(ErrorCode.ACCOUNT_UPDATE_FAILED); } final MutableAccountData mutableAccountData = currentAccount.toMutableAccountData(); mutableAccountData.setBillCycleDayLocal(bcd); final AccountModelDao accountToUpdate = new AccountModelDao(currentAccount.getId(), mutableAccountData); bcdCacheController.remove(currentAccount.getId()); bcdCacheController.putIfAbsent(currentAccount.getId(), new Integer(bcd)); accountDao.update(accountToUpdate, true, context); }
@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 search") public void testSearch() throws Exception { final MutableAccountData mutableAccountData1 = createAccountData(); mutableAccountData1.setEmail("john@acme.com"); mutableAccountData1.setCompanyName("Acme, Inc."); final AccountModelDao account1ModelDao = new AccountModelDao(UUID.randomUUID(), mutableAccountData1); final AccountData accountData1 = new DefaultAccount(account1ModelDao); mutableAccountData2.setEmail("bob@gmail.com"); mutableAccountData2.setCompanyName("Acme, Inc."); final AccountModelDao account2ModelDao = new AccountModelDao(UUID.randomUUID(), mutableAccountData2); final AccountData accountData2 = new DefaultAccount(account2ModelDao);
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account externalKey throws an exception") public void testShouldntBeAbleToUpdateExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setExternalKey(UUID.randomUUID().toString()); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), 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 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 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()); }
mutableAccountData.setNotes(null);
@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 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 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 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", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account currency throws an exception") public void testShouldntBeAbleToUpdateCurrency() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setCurrency(Currency.GBP); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext); }
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account BCD does throws an exception") public void testShouldntBeAbleToUpdateBillCycleDay() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setBillCycleDayLocal(account.getBillCycleDayLocal() + 2); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext); }
@Override public void updateBCD(final String externalKey, final int bcd, final InternalCallContext context) throws AccountApiException { final Account currentAccount = getAccountByKey(externalKey, context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, externalKey); } if (currentAccount.getBillCycleDayLocal() != DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL) { throw new AccountApiException(ErrorCode.ACCOUNT_UPDATE_FAILED); } final MutableAccountData mutableAccountData = currentAccount.toMutableAccountData(); mutableAccountData.setBillCycleDayLocal(bcd); final AccountModelDao accountToUpdate = new AccountModelDao(currentAccount.getId(), mutableAccountData); bcdCacheController.remove(currentAccount.getId()); bcdCacheController.putIfAbsent(currentAccount.getId(), new Integer(bcd)); accountDao.update(accountToUpdate, true, context); }