@Test public void deleteAccount() { Account preDelete = accountDao.findAccountById(Long.valueOf(100001)); accountDao.deleteAccount(preDelete); Account postDelete = accountDao.findAccountById(Long.valueOf(100001)); Assert.assertTrue(postDelete == null); }
@Test public void delete() { Account acc = accountDao.getAccountByUsername("admin"); if (acc != null) { accountDao.delete(acc.getAccountId()); } }
@Test public void createAccount() { Account created = new Account(null, "first", "last", "test", "testagain", null, Gender.FEMALE); accountDao.createAccount(created); Account retrieved = accountDao.findAccountById(created.getId()); Assert.assertEquals(created.getId(), retrieved.getId()); Assert.assertEquals(created.getFirstName(), retrieved.getFirstName()); Assert.assertEquals(created.getLastName(), retrieved.getLastName()); Assert.assertEquals(created.getPassword(), retrieved.getPassword()); }
@Test public void updateAccount() { Account accountToUpdate = accountDao.findAccountById(Long.valueOf(100001)); Assert.assertEquals(accountToUpdate.getLogin(), "upswimsdn"); accountToUpdate.setLogin("butts"); accountDao.createOrUpdateAccount(accountToUpdate); Account accountAfterUpdate = accountDao.findAccountById(Long.valueOf(100001)); Assert.assertEquals(accountToUpdate.getLogin(), accountAfterUpdate.getLogin()); }
@Test public void withdrawWithSufficientBalance() { Account account = new Account(TEST_ACCOUNT_NO, 100); accountDao.findAccount(TEST_ACCOUNT_NO); easyMock.expectLastCall().andReturn(account); // mockControl.setReturnValue(account); account.setBalance(50); accountDao.updateAccount(account); easyMock.replay(); accountService.withdraw(TEST_ACCOUNT_NO, 50); easyMock.verify(); }
@Test public void insert() { Account acc = accountDao.getAccountByUsername("admin"); if (acc != null) { accountDao.delete(acc.getAccountId()); } Account account = new Account(); account.setUsername("admin"); account.setPassword("amdin"); account.setFullName("Grubby"); accountDao.insert(account); }
@Test public void getAccountsByFullNameGenderAndLogin() { List<Account> accounts = accountDao.getAccountsByQuery(Gender.FEMALE, "blue", "i", "j", 0, 10); Assert.assertEquals(0, accounts.size()); accounts = accountDao.getAccountsByQuery(Gender.FEMALE, "i", "i", "j", 0, 10); Assert.assertEquals(1, accounts.size()); Assert.assertEquals("iz", accounts.get(0).getLogin()); Assert.assertEquals(Long.valueOf(100004), accounts.get(0).getId()); Assert.assertEquals("Isabelle", accounts.get(0).getFirstName()); Assert.assertEquals("Johnson", accounts.get(0).getLastName()); }
@Test public void getAcountsByUserNameAndGender() { List<Account> accounts = accountDao.getAccountsByQuery(Gender.FEMALE, "ups", null, null, 0, 10); Assert.assertEquals(0, accounts.size()); accounts = accountDao.getAccountsByQuery(Gender.MALE, "ups", null, null, 0, 10); Assert.assertEquals(1, accounts.size()); Assert.assertEquals("upswimsdn", accounts.get(0).getLogin()); Assert.assertEquals(Long.valueOf(100001), accounts.get(0).getId()); Assert.assertEquals("Jose", accounts.get(0).getFirstName()); Assert.assertEquals("Jose", accounts.get(0).getLastName()); }
@Test public void getAccountsByFirstName() { List<Account> accounts = accountDao.getAccountsByQuery(null, null, "J", null, 0, 10); Assert.assertEquals(1, accounts.size()); Assert.assertEquals("upswimsdn", accounts.get(0).getLogin()); Assert.assertEquals(Long.valueOf(100001), accounts.get(0).getId()); Assert.assertEquals("Jose", accounts.get(0).getFirstName()); Assert.assertEquals("Jose", accounts.get(0).getLastName()); }
@Test public void findAccountById() { Account a = accountDao.findAccountById(Long.valueOf(100001)); Assert.assertEquals(a.getId(), Long.valueOf(100001)); Assert.assertEquals(a.getFirstName(), "Jose"); Assert.assertEquals(a.getLastName(), "Jose"); Assert.assertEquals(a.getLogin(), "upswimsdn"); Assert.assertEquals(a.getPassword(), "aaaaaa"); }
@Test public void getAccountsbyLastName() { List<Account> accounts = accountDao.getAccountsByQuery(null, null, null, "lI", 0, 10); Assert.assertEquals(1, accounts.size()); Assert.assertEquals("lmulion", accounts.get(0).getLogin()); Assert.assertEquals(Long.valueOf(100002), accounts.get(0).getId()); Assert.assertEquals("Ignatius", accounts.get(0).getFirstName()); Assert.assertEquals("Lion", accounts.get(0).getLastName()); }
@Test(expected = InsufficientBalanceException.class) public void testWithdrawWithInsufficientBalance() { Account account = new Account(TEST_ACCOUNT_NO, 100); accountDao.findAccount(TEST_ACCOUNT_NO); easyMock.expectLastCall().andReturn(account); // mockControl.setReturnValue(account); easyMock.replay(); accountService.withdraw(TEST_ACCOUNT_NO, 150); easyMock.verify(); }
@RolesAllowed({"BANKADMIN", "BANKUSER"}) public int createTransaction(Transaction tran, int id) throws InvalidTranException, NotAuthorizedException, NotFoundException { String user = sctx.getCallerPrincipal().getName(); Account account = accountDao.getAccount(id); tran.setAccount(account); if (user.equals(tran.getAccount().getUserId()) || sctx.isCallerInRole("BANKADMIN")) em.persist(tran); return tran.getId(); }
@Test public void testCRUD() { Account account = new Account(); account.setId(1L); account.setName("zhuzhen"); account.setEnable(true); accountDao.save(account); List<Account> list = accountDao.getAll(); Assert.assertEquals(1, list.size()); Assert.assertEquals("zhuzhen", list.get(0).getName()); // account.setName("guolili"); // accountDao.update(account); // list = accountDao.getAll(); // Assert.assertEquals(1, list.size()); // Assert.assertEquals("guolili", list.get(0).getName()); accountDao.deleteById(1L); list = accountDao.getAll(); Assert.assertEquals(0, list.size()); }
@Test public void testFindByPartyAndJoiner() { Party party = new Party(); party.setTitle("testParty"); party.setOwner(accountDao.findByEmail("*****@*****.**")); party = partyDao.save(party); Account account = new Account(); account.setEmail("*****@*****.**"); accountDao.save(account); PartyJoiner partyJoiner = new PartyJoiner(); partyJoiner.setJoiner(account); partyJoiner.setParty(party); partyJoiner.setStatus(PartyJoiner.STATUS_INVITING); partyJoinerDao.save(partyJoiner); PartyJoiner result = partyJoinerDao.findByPartyAndJoiner(party, account); assertEquals("*****@*****.**", result.getJoiner().getEmail()); }
public void testAddAndRemoveUser() throws Exception { User user = new User("testuser"); user.setPassword("testpass"); user.setFirstName("Test"); user.setLastName("Last"); Address address = new Address(); address.setCity("Denver"); address.setProvince("CO"); address.setCountry("USA"); address.setPostalCode("80210"); user.setAddress(address); user.setEmail("*****@*****.**"); user.setWebsite("http://tek42.com"); user.setTimeZone("US/Central"); // Here we are creating an org that should already be in the database... // Ideally, we somehow have an org object... from the other dao or whatever... /* * Account org = new Account(); org.setName("Tek42"); org.setId(1L); */ Account org = adao.get(2L); System.out.println("Have org: " + org); user.setAccount(org); Role role = rdao.getRoleByName(Constants.USER_ROLE); assertNotNull(role.getId()); user.addRole(role); user = dao.saveUser(user); assertNotNull(user.getId()); user = dao.get(user.getId()); assertEquals("Vigilant", user.getAccount().getName()); assertEquals("testpass", user.getPassword()); assertEquals("US/Central", user.getTimeZone()); dao.remove(user.getId()); try { dao.get(user.getId()); fail("getUser didn't throw DataAccessException"); } catch (DataAccessException d) { assertNotNull(d); } }
@Test public void testFindByParty() { Party party = new Party(); party.setTitle("testParty"); party.setOwner(accountDao.findByEmail("*****@*****.**")); party = partyDao.save(party); PartyJoiner partyJoiner = new PartyJoiner(); partyJoiner.setParty(party); partyJoiner.setStatus(PartyJoiner.STATUS_INVITING); partyJoinerDao.save(partyJoiner); List<PartyJoiner> result = partyJoinerDao.findByParty(party); assertEquals(1, result.size()); }
public void testGetUser() throws Exception { User user = dao.get(1L); assertNotNull(user); assertEquals(1, user.getRoles().size()); assertTrue(user.isEnabled()); assertNotNull(user.getAccount()); assertEquals(1L, (long) user.getAccount().getId()); assertEquals("Tek42", user.getAccount().getName()); assertEquals("US/Eastern", user.getTimeZone()); assertTrue(!user.isHasProfile()); user.setAccount(adao.get(1L)); endTransaction(); dao.save(user); }
/** * @param out :转出账号 * @param in :转入账号 * @param money :转账金额 */ @Override public void transfer(String out, String in, Double money) { accountDao.outMoney(out, money); // int i = 1/0; accountDao.inMoney(in, money); }
@Test public void getAccountByUsernameAndPassword() { Account myAccount = new Account("admin", "admin"); Account account = accountDao.getAccountByUsernameAndPassword(myAccount); Assert.assertNotNull(account); }
@Test public void selectOne() { Account account = accountDao.selectByPrimaryKey(1); Assert.assertEquals(account.getUsername(), "test01"); Assert.assertEquals(account.getPassword(), "test01"); }
@Test public void getAccountsByGender() { List<Account> femalesOnly = accountDao.getAccountsByQuery(Gender.FEMALE, null, null, null, 0, 10); Assert.assertEquals(2, femalesOnly.size()); }