@Test public void testCloseAccount_withBalance() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Gerry Smith"); makeDepositAndValidateAccount(accountId, 385, "Gerry Smith"); logoutCurrentSubject(); loginAsSuperviser(); double closingBalance = service.closeAccount(accountId); Assert.assertEquals(385, (int)closingBalance); assertAccount("Gerry Smith", false, 0, 2, accountId); }
@RequiresPermissions("bankAccount:close") public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("Closing account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); if (!a.isActive()) { throw new InactiveAccountException("The account " + anAccountId + " is already closed"); } try { AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance()); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); a.setActive(false); log.debug("Account " + a.getId() + " is now closed and an amount of " + tx.getAmount() + " is given to the owner"); return tx.getAmount(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("Should never happen", nefe); } }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:close") public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("Closing account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); if (!a.isActive()) { throw new InactiveAccountException("The account " + anAccountId + " is already closed"); } try { AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance()); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); a.setActive(false); log.debug("Account " + a.getId() + " is now closed and an amount of " + tx.getAmount() + " is given to the owner"); return tx.getAmount(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("Should never happen", nefe); } } }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:close") public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("Closing account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); if (!a.isActive()) { throw new InactiveAccountException("The account " + anAccountId + " is already closed"); } try { AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance()); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); a.setActive(false); log.debug("Account " + a.getId() + " is now closed and an amount of " + tx.getAmount() + " is given to the owner"); return tx.getAmount(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("Should never happen", nefe); } } SecureBankService(); }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:close") public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("Closing account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); if (!a.isActive()) { throw new InactiveAccountException("The account " + anAccountId + " is already closed"); } try { AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance()); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); a.setActive(false); log.debug("Account " + a.getId() + " is now closed and an amount of " + tx.getAmount() + " is given to the owner"); return tx.getAmount(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("Should never happen", nefe); } } SecureBankService(); void start(); void dispose(); int getAccountCount(); @RequiresPermissions("bankAccount:create") long createNewAccount(String anOwnerName); long[] searchAccountIdsByOwner(String anOwnerName); @RequiresPermissions("bankAccount:read") String getOwnerOf(long anAccountId); @RequiresPermissions("bankAccount:read") double getBalanceOf(long anAccountId); @RequiresPermissions("bankAccount:operate") double depositInto(long anAccountId, double anAmount); @RequiresPermissions("bankAccount:operate") double withdrawFrom(long anAccountId, double anAmount); @RequiresPermissions("bankAccount:read") TxLog[] getTxHistoryFor(long anAccountId); @RequiresPermissions("bankAccount:close") double closeAccount(long anAccountId); @RequiresPermissions("bankAccount:read") boolean isAccountActive(long anAccountId); }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:close") public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("Closing account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); if (!a.isActive()) { throw new InactiveAccountException("The account " + anAccountId + " is already closed"); } try { AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance()); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); a.setActive(false); log.debug("Account " + a.getId() + " is now closed and an amount of " + tx.getAmount() + " is given to the owner"); return tx.getAmount(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("Should never happen", nefe); } } SecureBankService(); void start(); void dispose(); int getAccountCount(); @RequiresPermissions("bankAccount:create") long createNewAccount(String anOwnerName); long[] searchAccountIdsByOwner(String anOwnerName); @RequiresPermissions("bankAccount:read") String getOwnerOf(long anAccountId); @RequiresPermissions("bankAccount:read") double getBalanceOf(long anAccountId); @RequiresPermissions("bankAccount:operate") double depositInto(long anAccountId, double anAmount); @RequiresPermissions("bankAccount:operate") double withdrawFrom(long anAccountId, double anAmount); @RequiresPermissions("bankAccount:read") TxLog[] getTxHistoryFor(long anAccountId); @RequiresPermissions("bankAccount:close") double closeAccount(long anAccountId); @RequiresPermissions("bankAccount:read") boolean isAccountActive(long anAccountId);  }