예제 #1
0
 /** Test getting customers. */
 public final void testGetCustomers() {
   // get single customer
   Customer c1 = null;
   try {
     c1 = bank.getCustomer("120");
   } catch (BankException e) {
     e.printStackTrace();
   }
   assertEquals(c1.getFirstName(), "A");
   assertEquals(c1.getLastName(), "Customer");
   // force exception
   try {
     c1 = bank.getCustomer("201");
     fail("getCustomer hasn't caused an exception when it should");
   } catch (BankException e) {
     // ignore
   }
   // get all customers
   try {
     List<Customer> customers = bank.getCustomers();
     assertEquals(customers.size(), 8); // 6 are in default data set
     assertEquals(customers.get(6).getId(), "120");
     assertEquals(customers.get(7).getId(), "130");
   } catch (BankException e) {
     e.printStackTrace();
   }
 } // testGetCustomers
예제 #2
0
  /** Add some new accounts and customers. */
  protected final void setUp() {
    // get context and facade
    ApplicationContext ctx = new FileSystemXmlApplicationContext("build/applicationContext.xml");
    bank = (BankingFacade) ctx.getBean("bankManager");

    // create test accounts and customers
    try {
      bank.addCustomer("120", "Mr", "A", "Customer");
      bank.addCustomer("130", "Mr", "Ano", "Customer");
      bank.addAccount("120-2001", "120", "Checking");
      bank.addAccount("120-2002", "120", "Savings");
      bank.addAccount("120-2010", "130", "Checking");
      bank.addAccount("120-2011", "130", "Savings");
      bank.addAccount("120-2012", "130", "Savings");
      bank.deposit("120-2002", new BigDecimal("100.00"));
      delay(5);
      bank.deposit("120-2002", new BigDecimal("50.00"));
      delay(5);
      bank.deposit("120-2010", new BigDecimal("1000.45"));
      delay(5);
      bank.deposit("120-2011", new BigDecimal("123.69"));
    } catch (BankException ex) {
      ex.printStackTrace();
    }
  } // setUp
예제 #3
0
 /** Test adding and deleting a customer. */
 public final void testAddDeleteCustomer() {
   // add customer
   try {
     bank.addCustomer("201", "Mr", "New", "Customer");
   } catch (BankException e) {
     e.printStackTrace();
   }
   // delete customer
   try {
     Customer c1 = bank.getCustomer("201");
     assertNotNull(c1);
     c1 = bank.deleteCustomer("201");
     assertNull(c1);
   } catch (BankException e) {
     e.printStackTrace();
   }
   // force exception
   try {
     Customer c2 = bank.deleteCustomer("999");
     // TODO: cause exception
     // fail("deleteCustomer hasn't caused an exception as it should");
   } catch (BankException e) {
     // ignore
   }
 } // testAddDeleteCustomer
예제 #4
0
 /** Test adding and deleting an account. */
 public final void testAddDeleteAccount() {
   // add account
   try {
     bank.addAccount("120-1111", "120", "C");
   } catch (BankException e) {
     e.printStackTrace();
   }
   // delete account
   try {
     Account a1 = bank.getAccount("120-1111");
     assertNotNull(a1);
     a1 = bank.deleteAccount("120-1111");
     assertNull(a1);
   } catch (BankException e) {
     e.printStackTrace();
   }
   // force exception
   try {
     Account a2 = bank.deleteAccount("120-999");
     // TODO: cause exception
     // fail("deleteAccount hasn't caused an exception as it should");
   } catch (BankException ex) {
     // ignore
   }
 } // testAddDeleteAccount
예제 #5
0
 /** Test transfering funds. */
 public final void testTransfer() {
   // transfer
   try {
     BigDecimal balance = bank.transfer("120-2002", "120-2001", new BigDecimal("10.00"));
     assertEquals(balance, new BigDecimal("140.00"));
   } catch (Exception e) {
     e.printStackTrace();
   }
   // transfer too much - exception
   try {
     BigDecimal balance = bank.transfer("120-2002", "120-2001", new BigDecimal("500.00"));
     fail("transfer hasn't caused an exception as it should");
   } catch (Exception ex) {
     // ignore
   }
   // force exception
   try {
     BigDecimal balance = bank.transfer("120-999", "120-2001", new BigDecimal("100.00"));
     fail("transfer hasn't caused an exception as it should");
   } catch (Exception e) {
     // ignore
   }
   // and again
   try {
     BigDecimal balance = bank.transfer("120-2002", "120-999", new BigDecimal("100.00"));
     fail("transfer hasn't caused an exception as it should");
   } catch (Exception e) {
     // ignore
   }
 } // testTransfer
예제 #6
0
 /** Test getting accounts. */
 public final void testGetAccounts() {
   // get a customers account
   Account a1 = null;
   try {
     a1 = bank.getAccount("120-2002");
   } catch (BankException e) {
     e.printStackTrace();
   }
   assertEquals(a1.getType(), "Savings");
   assertEquals(a1.getBalance(), new BigDecimal("150.00"));
   // force exception
   try {
     a1 = bank.getAccount("101-2099");
     fail("getAccount hasn't caused an exception when it should");
   } catch (BankException e) {
     // ignore
   }
   // get all customers accounts
   try {
     List<Account> accounts = bank.getAccounts("120");
     assertEquals(accounts.size(), 2);
     assertEquals(accounts.get(0).getBalance(), new BigDecimal("0"));
     assertEquals(accounts.get(1).getBalance(), new BigDecimal("150.00"));
   } catch (BankException e) {
     e.printStackTrace();
   }
   // force exception
   try {
     List<Account> accounts = bank.getAccounts(null);
     fail("getAccounts hasn't caused an exception when it should");
   } catch (BankException e) {
     // ignore
   }
 } // testGetAccounts
예제 #7
0
  /** Remove the accounts and customers. */
  protected final void tearDown() {
    // delete test accounts and customers
    try {
      bank.deleteAccount("120-2001");
      bank.deleteAccount("120-2002");
      bank.deleteAccount("120-2010");
      bank.deleteAccount("120-2011");
      bank.deleteAccount("120-2012");
      bank.deleteCustomer("120");
      bank.deleteCustomer("130");
    } catch (BankException ex) {
      ex.printStackTrace();
    }

    bank = null;
  } // tearDown
예제 #8
0
 /** Test depositing funds. */
 public final void testDeposit() {
   // deposit
   try {
     BigDecimal balance = bank.deposit("120-2002", new BigDecimal("50.00"));
     assertEquals(balance, new BigDecimal("200.00"));
   } catch (BankException e) {
     e.printStackTrace();
   }
   // force exception
   try {
     BigDecimal balance = bank.deposit("120-999", new BigDecimal("50.00"));
     fail("deposit hasn't caused an exception as it should");
   } catch (BankException ex) {
     // ignore
   }
 } // testDeposit
예제 #9
0
 /** Test getting transactions. */
 public final void testGetTransactions() {
   // get customer account transactions
   try {
     List<TransRecord> transactions = bank.getTransactions("120-2002");
     assertEquals(transactions.size(), 2); // could be a problem here
     assertEquals(transactions.get(0).getTransAmt(), new BigDecimal("50.00"));
     assertEquals(transactions.get(1).getTransAmt(), new BigDecimal("100.00"));
   } catch (BankException e) {
     e.printStackTrace();
   }
   // force exception
   try {
     List<TransRecord> transactions = bank.getTransactions("120-999");
     // fail("getTransactions hasn't caused an exception as it should");
   } catch (BankException e) {
     // ignore
   }
 } // testGetTransactions
예제 #10
0
 /** Test withdrawing funds. */
 public final void testWithdraw() {
   // withdraw
   try {
     BigDecimal balance = bank.withdraw("120-2002", new BigDecimal("75.00"));
     assertEquals(balance, new BigDecimal("75.00"));
   } catch (Exception e) {
     e.printStackTrace();
   }
   // withdraw too much - exception
   try {
     BigDecimal balance = bank.withdraw("120-2002", new BigDecimal("500.00"));
     fail("withdraw hasn't caused an exception as it should");
   } catch (Exception e) {
     // ignore
   }
   // force exception
   try {
     BigDecimal balance = bank.withdraw("120-999", new BigDecimal("50.00"));
     fail("withdraw hasn't caused an exception as it should");
   } catch (Exception e) {
     // ignore
   }
 } // testWithdraw