@Test(expected = NotEnoughFundsException.class) public void testWithdrawFrom_emptyAccount() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Wally Smith"); service.withdrawFrom(accountId, 100); }
@RequiresPermissions("bankAccount:operate") public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException { assertServiceState(); log.info("Making withdrawal of " + anAmount + " from account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createWithdrawalTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); log.debug("New balance of account " + a.getId() + " after withdrawal is " + a.getBalance()); return a.getBalance(); }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:operate") public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException { assertServiceState(); log.info("Making withdrawal of " + anAmount + " from account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createWithdrawalTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); log.debug("New balance of account " + a.getId() + " after withdrawal is " + a.getBalance()); return a.getBalance(); } }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:operate") public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException { assertServiceState(); log.info("Making withdrawal of " + anAmount + " from account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createWithdrawalTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); log.debug("New balance of account " + a.getId() + " after withdrawal is " + a.getBalance()); return a.getBalance(); } SecureBankService(); }
SecureBankService implements BankService { @RequiresPermissions("bankAccount:operate") public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException { assertServiceState(); log.info("Making withdrawal of " + anAmount + " from account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createWithdrawalTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); log.debug("New balance of account " + a.getId() + " after withdrawal is " + a.getBalance()); return a.getBalance(); } 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:operate") public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException { assertServiceState(); log.info("Making withdrawal of " + anAmount + " from account " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createWithdrawalTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("Created a new transaction " + tx); a.applyTransaction(tx); log.debug("New balance of account " + a.getId() + " after withdrawal is " + a.getBalance()); return a.getBalance(); } 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);  }