@Test public void shouldCreateNonExistentAccount() throws DuplicateAccountException { when(accountRepository.save(testAccount)).thenReturn(testAccount); AccountService accountService = new AccountServiceImpl(accountRepository, passwordEncoder); accountService.create(testAccount); verify(accountRepository, times(1)).save(testAccount); }
@SuppressWarnings("unchecked") @Test @DataSet public void testMassUpdate() { List<Integer> updateKeys = Arrays.asList(1, 2, 3); Account account = new Account(); account.setAssignuser("hai79"); account.setIndustry("aaa"); accountService.massUpdateWithSession(account, updateKeys, 1); AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setSaccountid(new NumberSearchField(1)); List<SimpleAccount> accounts = accountService.findPagableListByCriteria( new SearchRequest<>(criteria, 0, Integer.MAX_VALUE)); assertThat(accounts.size()).isEqualTo(3); assertThat(accounts) .extracting("id", "accountname", "industry", "assignuser") .contains( tuple(1, "xyz", "aaa", "hai79"), tuple(2, "xyz1", "aaa", "hai79"), tuple(3, "xyz2", "aaa", "hai79")); }
@Test public void shouldFindAccountByName() { when(accountRepository.findByUsername(TEST_USERNAME)).thenReturn(testAccount); AccountService accountService = new AccountServiceImpl(accountRepository, passwordEncoder); Account found = accountService.findByUsername(TEST_USERNAME); Assert.assertEquals(testAccount, found); }
/** * Add Cash as a separate, automatic asset class that uses all the cash amounts from the * investment accounts. * * @param assetAllocation Main asset allocation object. */ private void addCash(AssetClass assetAllocation) { // get all investment accounts, their currencies and cash balances. AccountRepository repo = new AccountRepository(getContext()); AccountService accountService = new AccountService(getContext()); List<String> investmentAccounts = new ArrayList<>(); investmentAccounts.add(AccountTypes.INVESTMENT.toString()); CurrencyService currencyService = new CurrencyService(getContext()); int destinationCurrency = currencyService.getBaseCurrencyId(); Money zero = MoneyFactory.fromDouble(0); List<Account> accounts = accountService.loadAccounts(false, false, investmentAccounts); Money sum = MoneyFactory.fromDouble(0); // Get the balances in base currency. for (Account account : accounts) { int sourceCurrency = account.getCurrencyId(); Money amountInBase = currencyService.doCurrencyExchange( destinationCurrency, account.getInitialBalance(), sourceCurrency); sum = sum.add(amountInBase); } // add the cash asset class // todo: the allocation needs to be editable! AssetClass cash = AssetClass.create(getContext().getString(R.string.cash)); cash.setType(ItemType.Cash); cash.setAllocation(zero); cash.setCurrentAllocation(zero); cash.setDifference(zero); cash.setValue(sum); assetAllocation.addChild(cash); }
@Test public void testCreateNewAdminUserStringStringString() { service.createNewAdminUser("robbo", "*****@*****.**", "password"); Account a = service.loadAccountByUserName("robbo"); assertNotNull(a); assertEquals("*****@*****.**", a.getEmail()); }
@Test(expected = DuplicateAccountException.class) public void shouldNotCreateDuplicateAccount() throws DuplicateAccountException { when(accountRepository.findByUsername(TEST_USERNAME)).thenReturn(testAccount); when(testAccount.getUsername()).thenReturn(TEST_USERNAME); AccountService accountService = new AccountServiceImpl(accountRepository, passwordEncoder); accountService.create(testAccount); verify(accountRepository, times(0)).save(testAccount); }
@Test @DataSet public void testRemoveAccounts() { accountService.massRemoveWithSession(Arrays.asList(1, 2), "hai79", 1); AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setSaccountid(new NumberSearchField(1)); Assert.assertEquals(1, accountService.getTotalCount(criteria)); }
@Test public void testCreateNewAdminUserStringStringStringStringString() { service.createNewUser("robbo", "*****@*****.**", "password", "rob", "hinds", Role.ROLE_ADMIN); Account a = service.loadAccountByUserName("robbo"); assertNotNull(a); assertEquals("*****@*****.**", a.getEmail()); assertEquals("rob", a.getFirstName()); assertEquals("hinds", a.getLastName()); }
@Test public void testLoadAccount() { List<Account> accs = service.findAllAccounts(); assertTrue(accs.size() > 0); Account original = accs.get(0); Account a = service.loadAccount(original.getId()); // this is will load // the test account assertNotNull(a); assertEquals(original.getUserName(), a.getUserName()); }
@Test @DataSet public void testUpdateAccount() { Account account = new Account(); account.setId(1); account.setAccountname("abc"); account.setSaccountid(1); accountService.updateWithSession(account, "hai79"); accountService.findById(1, 1); Assert.assertEquals("abc", account.getAccountname()); }
@Test public void testApp() { // ApplicationContext app = new // ClassPathXmlApplicationContext("classpath:com/demo/namespace/application-context.xml", // "classpath:com/demo/namespace/test-infra-context.xml"); ApplicationContext app = new ClassPathXmlApplicationContext("classpath:com/demo/namespace/test-infra-context.xml"); AccountService as = (AccountService) app.getBean("accountservice"); Assert.assertEquals(40000, as.findAccountBalance("123")); System.out.println(as.findAccountBalance("100")); }
@Test @DataSet public void testUpdateAccount() { Account account = new Account(); account.setId(1); account.setAccountname("abc"); account.setSaccountid(1); accountService.updateWithSession(account, "hai79"); SimpleAccount simpleAccount = accountService.findById(1, 1); assertThat(simpleAccount.getAccountname()).isEqualTo("abc"); assertThat(simpleAccount.getIndustry()).isEqualTo(null); }
@Test @DataSet public void testRemoveAccountBySearchCriteria() { AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setIndustries(new SetSearchField<String>(SearchField.AND, new String[] {"a"})); criteria.setSaccountid(new NumberSearchField(1)); accountService.removeByCriteria(criteria, 1); criteria = new AccountSearchCriteria(); criteria.setSaccountid(new NumberSearchField(1)); Assert.assertEquals(1, accountService.getTotalCount(criteria)); }
@Test public void updateUser() { // 如果明文密码不为空,加密密码会被更新. User user = UserData.randomNewUser(); accountService.updateUser(user); assertNotNull(user.getSalt()); // 如果明文密码为空,加密密码无变化。 User user2 = UserData.randomNewUser(); user2.setPlainPassword(null); accountService.updateUser(user2); assertNull(user2.getSalt()); }
/** * 账户更新 * * @param accountInfo * @return * @throws ApiException */ public AccountInfoType updateAccount(AccountInfoType accountInfo) throws ApiException { if (accountInfo == null) return null; AccountInfoType accountInfoType = null; UpdateAccountInfoRequest request = new UpdateAccountInfoRequest(); request.setAccountInfoType(accountInfo); AccountService accountService = commonService.getService(AccountService.class); UpdateAccountInfoResponse response = accountService.updateAccountInfo(request); if (response != null) accountInfoType = response.getAccountInfoType(); return accountInfoType; }
@Test public void registerUser() { User user = UserData.randomNewUser(); Date currentTime = new Date(); accountService.setDateProvider(new ConfigurableDateProvider(currentTime)); accountService.registerUser(user); // 验证user的角色,注册日期和加密后的密码都被自动更新了。 assertEquals("user", user.getRoles()); assertEquals(currentTime, user.getRegisterDate()); assertNotNull(user.getPassword()); assertNotNull(user.getSalt()); }
@Test public void deleteUser() { // 正常删除用户. accountService.deleteUser(2L); Mockito.verify(mockUserDao).delete(2L); // 删除超级管理用户抛出异常, userDao没有被执行 try { accountService.deleteUser(1L); fail("expected ServicExcepton not be thrown"); } catch (ServiceException e) { // expected exception } Mockito.verify(mockUserDao, Mockito.never()).delete(1L); }
@Test @DataSet public void tesSearchAnyCity() { AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setAnyCity(new StringSearchField(SearchField.AND, "ha noi")); criteria.setSaccountid(new NumberSearchField(1)); Assert.assertEquals(2, accountService.getTotalCount(criteria)); Assert.assertEquals( 2, accountService .findPagableListByCriteria( new SearchRequest<AccountSearchCriteria>(criteria, 0, Integer.MAX_VALUE)) .size()); }
@Test @DataSet public void testSearchByAssignUserName() { AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setAssignUserName(new StringSearchField(SearchField.AND, "Nguyen Phuc Hai")); criteria.setSaccountid(new NumberSearchField(1)); Assert.assertEquals(1, accountService.getTotalCount(criteria)); Assert.assertEquals( 1, accountService .findPagableListByCriteria( new SearchRequest<AccountSearchCriteria>(criteria, 0, Integer.MAX_VALUE)) .size()); }
@Test @DataSet public void testSearchWebsite() { AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setWebsite(new StringSearchField(SearchField.AND, "http://www.esofthead.com")); criteria.setSaccountid(new NumberSearchField(1)); Assert.assertEquals(3, accountService.getTotalCount(criteria)); Assert.assertEquals( 3, accountService .findPagableListByCriteria( new SearchRequest<AccountSearchCriteria>(criteria, 0, Integer.MAX_VALUE)) .size()); }
public static void main(String[] args) throws Exception { ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class, args); AccountService service = context.getBean(AccountService.class); AccountRepository repository = context.getBean(AccountRepository.class); service.createAccountAndNotify("josh"); System.out.println("Count is " + repository.count()); try { service.createAccountAndNotify("error"); } catch (Exception ex) { System.out.println(ex.getMessage()); } System.out.println("Count is " + repository.count()); Thread.sleep(100); ((Closeable) context).close(); }
@Test public void shouldInitializeWithTwoDemoUsers() { // act accountService.initialize(); // assert verify(accountRepositoryMock, times(2)).save(any(Account.class)); }
/** * Instantiates a new razor server, its services, and starts the scheduler. This can be replaced * by a dynamic handler manager but has the benefit of simplicity. */ public RazorServer() { super(); SERVICES.put(Service.ACCOUNT, AccountService.getInstance()); SERVICES.put(Service.ALERT, AlertService.getInstance()); SERVICES.put(Service.ASSET, AssetService.getInstance()); SERVICES.put(Service.ATTRIBUTE, AttributeService.getInstance()); SERVICES.put(Service.AUDIT, AuditService.getInstance()); SERVICES.put(Service.CONTRACT, ContractService.getInstance()); SERVICES.put(Service.FINANCE, FinanceService.getInstance()); SERVICES.put(Service.JOURNAL, JournalService.getInstance()); SERVICES.put(Service.IMAGE, ImageService.getInstance()); SERVICES.put(Service.IMAGETEXT, ImageTextService.getInstance()); SERVICES.put(Service.LICENSE, LicenseService.getInstance()); SERVICES.put(Service.LOCATION, LocationService.getInstance()); SERVICES.put(Service.MAIL, MailService.getInstance()); SERVICES.put(Service.MONITOR, MonitorService.getInstance()); SERVICES.put(Service.PARTNER, PartnerService.getInstance()); SERVICES.put(Service.PARTY, PartyService.getInstance()); SERVICES.put(Service.PRICE, PriceService.getInstance()); SERVICES.put(Service.PRODUCT, ProductService.getInstance()); SERVICES.put(Service.RATE, RateService.getInstance()); SERVICES.put(Service.REPORT, ReportService.getInstance()); SERVICES.put(Service.RESERVATION, ReservationService.getInstance()); SERVICES.put(Service.SESSION, SessionService.getInstance()); SERVICES.put(Service.SMS, SmsService.getInstance()); SERVICES.put(Service.TASK, TaskService.getInstance()); SERVICES.put(Service.TAX, TaxService.getInstance()); SERVICES.put(Service.TEXT, TextService.getInstance()); SERVICES.put(Service.WORKFLOW, WorkflowService.getInstance()); // startScheduler(); // PartnerService.startSchedulers(); }
/** 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用. */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal(); User user = accountService.findUserByLoginName(shiroUser.loginName); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); info.addRoles(user.getRoleList()); return info; }
public AccountInfoType getAccountInfo() { try { GetAccountInfoRequest request = new GetAccountInfoRequest(); AccountService accountService = commonService.getService(AccountService.class); GetAccountInfoResponse response = accountService.getAccountInfo(request); if (response == null) { return null; } return response.getAccountInfoType(); } catch (ApiException e) { logger.error("ERROR", e); } return null; }
@Test public void testCreateGroupMembership() { Account account = new Account(); account.setGivenName("Anthony"); account.setSurname("Wolski"); account.setEmail("*****@*****.**"); account.setPassword("password"); account.setUsername("awolski"); accountService.createAccount(account); Group group = new Group(); group.setName("Test Group"); accountService.createGroup(group); GroupMembership groupMembership = new GroupMembership(account, group); accountService.createGroupMembership(groupMembership); List<Account> groupAccounts = accountService.getGroupAccounts(group.getId()); assertEquals(1, groupAccounts.size()); List<Group> accountGroups = accountService.getAccountGroups(account.getId()); assertEquals(1, accountGroups.size()); List<GroupMembership> groupGroupMemberships = accountService.getGroupGroupMemberships(group.getId()); assertEquals(1, groupGroupMemberships.size()); List<GroupMembership> accountGroupMemberships = accountService.getAccountGroupMemberships(account.getId()); assertEquals(1, accountGroupMemberships.size()); }
@DataSet @Test public void testSearchAnyMailField() { AccountSearchCriteria criteria = new AccountSearchCriteria(); criteria.setAnyMail(new StringSearchField(SearchField.AND, "abc")); criteria.setSaccountid(new NumberSearchField(1)); Assert.assertEquals(2, accountService.getTotalCount(criteria)); }
@DataSet @Test public void testSaveAccount() { List accountList = accountService.findPagableListByCriteria( new SearchRequest<AccountSearchCriteria>( new AccountSearchCriteria(), 0, Integer.MAX_VALUE)); System.out.println("List: " + accountList.size()); Account account = new Account(); account.setAccountname("aaa"); account.setSaccountid(1); accountService.saveWithSession(account, "aaa"); accountList = accountService.findPagableListByCriteria( new SearchRequest<AccountSearchCriteria>( new AccountSearchCriteria(), 0, Integer.MAX_VALUE)); System.out.println("List: " + accountList.size()); }
@Test public void testFindAllAccounts() { List<Account> accs = service.findAllAccounts(); assertEquals("Check DB is empty first", 1, accs.size()); // always the // batch // test // account // created - // needed // for // persistence Account a = new Account(); a.setUserName("robb"); a.setPassword("password"); service.storeAccount(a); accs = service.findAllAccounts(); assertEquals("check Account has been created", 2, accs.size()); }
@Override public UserDetails loadUserByUsername(String username) { Account account = accountService.getAccountByUsername(username); UserDetailsAdapter user = new UserDetailsAdapter(account); user.setPassword(userDetailsDao.findPasswordByUsername(username)); return user; }