@Test public void testCRUDAccount() { // Create Account account = new Account(); account.setGivenName("Anthony"); account.setSurname("Wolski"); account.setEmail("*****@*****.**"); account.setPassword("password"); account.setUsername("awolski"); accountService.createAccount(account); assertEquals(new Long(0), account.getVersion()); // Read Account found = accountService.getAccount(account.getId()); assertEquals("Anthony", found.getGivenName()); assertEquals("Wolski", found.getSurname()); assertEquals("*****@*****.**", found.getEmail()); assertEquals("password", found.getPassword()); assertEquals("awolski", found.getUsername()); assertEquals(new Long(0), account.getVersion()); // Update account.setMiddleName("Keith"); accountService.saveAccount(account); account = accountService.getAccount(account.getId()); assertEquals(new Long(1), account.getVersion()); // Delete String accountId = account.getId(); accountService.deleteAccountById(accountId); account = accountService.getAccount(accountId); assertNull(account); }
/** * Creates an account object from another one, given as argument. * * @param o other account to copy */ public static Account create(Account o) { Account a = new AccountImpl(); a.setUid(o.getUid()); a.setCommonName(o.getCommonName()); a.setSurname(o.getSurname()); a.setOrg(o.getOrg()); a.setEmail(o.getEmail()); a.setPhone(o.getPhone()); a.setDescription(o.getDescription()); // passwords / new passwords fields voluntarily omitted: // the password update process should not go through this. a.setGivenName(o.getGivenName()); a.setTitle(o.getTitle()); a.setPostalAddress(o.getPostalAddress()); a.setPostalCode(o.getPostalCode()); a.setRegisteredAddress(o.getRegisteredAddress()); a.setPostOfficeBox(o.getPostOfficeBox()); a.setPhysicalDeliveryOfficeName(o.getPhysicalDeliveryOfficeName()); a.setStreet(o.getStreet()); a.setLocality(o.getLocality()); a.setFacsimile(o.getFacsimile()); a.setMobile(o.getMobile()); a.setRoomNumber(o.getRoomNumber()); a.setStateOrProvince(o.getStateOrProvince()); a.setOrganizationalUnit(o.getOrganizationalUnit()); a.setHomePostalAddress(o.getHomePostalAddress()); return a; }
@Test public void shouldReturnUserDetails() { // arrange Account demoUser = new Account("*****@*****.**", "demo", "ROLE_USER"); when(accountRepositoryMock.findOneByEmail("*****@*****.**")).thenReturn(demoUser); // act UserDetails userDetails = accountService.loadUserByUsername("*****@*****.**"); // assert assertThat(demoUser.getEmail()).isEqualTo(userDetails.getUsername()); assertThat(demoUser.getPassword()).isEqualTo(userDetails.getPassword()); assertThat(hasAuthority(userDetails, demoUser.getRole())).isTrue(); }
@Test public void getAccountTest() throws IOException, VscaleException { Result<Account> query = this.api.account(); Account account = query.get(); assertNotNull(account.getActivationDate()); assertNotNull(account.getCountry()); assertNotNull(account.getId()); assertNotNull(account.getEmail()); assertNotNull(account.getFaceId()); assertNotNull(account.getState()); assertNotNull(account.getLocale()); assertNotNull(account.getMobile()); assertNotNull(account.getName()); assertNotNull(account.getSurname()); }
@Test public void testPostAccountSuccess() throws Exception { Account a = accountManager.findAccount("123456001"); a.setEmail("*****@*****.**"); // Update the email mockMvc .perform( post("/accounts/{acctId}", "123456001") .param("name", a.getName()) // Providing all the params that would have been sent in // the form .param("dateOfBirth", formatDate(a.getDateOfBirth())) .param("email", a.getEmail()) .param("receiveNewsletter", (a.isReceiveNewsletter() ? "1" : "0")) .param("receiveMonthlyEmailUpdate", (a.isReceiveMonthlyEmailUpdate() ? "1" : "0"))) .andExpect(status().isFound()) // Because this is a redirect .andExpect(redirectedUrl("123456001")); // The redirect URL // provided by the // controller }
@Test public void testPostAccountFailValidation() throws Exception { Account a = accountManager.findAccount("123456001"); a.setEmail("bogusemail"); // Update the email with bad email address mockMvc .perform( post("/accounts/{acctId}", "123456001") .param("name", a.getName()) // Providing all the params that would have been sent in // the form .param("dateOfBirth", formatDate(a.getDateOfBirth())) .param("email", a.getEmail()) .param("receiveNewsletter", (a.isReceiveNewsletter() ? "1" : "0")) .param("receiveMonthlyEmailUpdate", (a.isReceiveMonthlyEmailUpdate() ? "1" : "0"))) .andExpect(model().attributeHasErrors("account")) .andExpect(model().attributeErrorCount("account", 1)) .andExpect(model().attributeHasFieldErrors("account", "email")) .andExpect(status().isOk()) // Because this is a forward to the // same view .andExpect(view().name("accounts/edit")); }
private void onDone() { mAccount.setDescription(mAccount.getEmail()); mAccount.setNotifyNewMail(mNotifyView.isChecked()); mAccount.setShowOngoing(mNotifySyncView.isChecked()); mAccount.setAutomaticCheckIntervalMinutes( (Integer) ((SpinnerOption) mCheckFrequencyView.getSelectedItem()).value); mAccount.setDisplayCount((Integer) ((SpinnerOption) mDisplayCountView.getSelectedItem()).value); if (mPushEnable.isChecked()) { mAccount.setFolderPushMode(Account.FolderMode.FIRST_CLASS); } else { mAccount.setFolderPushMode(Account.FolderMode.NONE); } mAccount.save(Preferences.getPreferences(this)); if (mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()) || getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false)) { Preferences.getPreferences(this).setDefaultAccount(mAccount); } K9.setServicesEnabled(this); AccountSetupNames.actionSetNames(this, mAccount); finish(); }
@RequestMapping(value = "request") @Transactional(propagation = Propagation.REQUIRES_NEW) public String recoveryRequestPage( HttpSession session, Model model, @Valid @ModelAttribute("recovery") RecoveryRequestForm form, BindingResult result) { log.info("Recovery password for {}", form); if (form.isRecoveryAccount()) { try { final Account account = accountManager.findByEmail(form.getEmail()); if (account != null) { final RecoveryToken token = recoveryTokenManager.generateToken(account); log.info("Recovery token generated: {}", token); final Map<String, Object> mailModel = new HashMap<>(); mailModel.put("principal", account); mailModel.put("recoveryToken", token.getToken()); final Member member = personalityManager.getMember(account.getId()); notificationService.raiseNotification( "account.recovery", member, NotificationSender.ACCOUNTS, mailModel); session.setAttribute(RECOVERING_PLAYER_EMAIL, account.getEmail()); return "redirect:/account/recovery/confirmation"; } else { result.rejectValue("email", "account.recovery.err.unknown"); } } catch (Exception ex) { log.error("Recovery password email can't be delivered", ex); result.rejectValue("email", "account.recovery.err.system"); } } model.addAttribute("resourceTemplate", "/content/account/recovery/request.ftl"); return "/content/assistance/help"; }
private User createUser(Account account) { return new User( account.getEmail(), account.getPassword(), Collections.singleton(createAuthority(account))); }
/** * @param currentAccount existing account data * @return merged account data */ @Override public Account mergeWithDelegate(final Account currentAccount) { final DefaultMutableAccountData accountData = new DefaultMutableAccountData(this); if (externalKey != null && currentAccount.getExternalKey() != null && !currentAccount.getExternalKey().equals(externalKey)) { throw new IllegalArgumentException( String.format( "Killbill doesn't support updating the account external key yet: new=%s, current=%s", externalKey, currentAccount.getExternalKey())); } else { // Default to current value accountData.setExternalKey(currentAccount.getExternalKey()); } if (currency != null && currentAccount.getCurrency() != null && !currentAccount.getCurrency().equals(currency)) { throw new IllegalArgumentException( String.format( "Killbill doesn't support updating the account currency yet: new=%s, current=%s", currency, currentAccount.getCurrency())); } else { // Default to current value accountData.setCurrency(currentAccount.getCurrency()); } if (billCycleDayLocal != null && billCycleDayLocal != 0 && currentAccount.getBillCycleDayLocal() != 0 && !billCycleDayLocal.equals(currentAccount.getBillCycleDayLocal())) { throw new IllegalArgumentException( String.format( "Killbill doesn't support updating the account BCD yet: new=%s, current=%s", billCycleDayLocal, currentAccount.getBillCycleDayLocal())); } else if (billCycleDayLocal != null && billCycleDayLocal != 0) { // Junction sets it accountData.setBillCycleDayLocal(billCycleDayLocal); } else { // Default to current value accountData.setBillCycleDayLocal(currentAccount.getBillCycleDayLocal()); } // Set all updatable fields with the new values if non null, otherwise defaults to the current // values accountData.setEmail(Objects.firstNonNull(email, currentAccount.getEmail())); accountData.setName(Objects.firstNonNull(name, currentAccount.getName())); accountData.setFirstNameLength( Objects.firstNonNull(firstNameLength, currentAccount.getFirstNameLength())); accountData.setPaymentMethodId( Optional.<UUID>fromNullable(paymentMethodId) .or(Optional.<UUID>fromNullable(currentAccount.getPaymentMethodId())) .orNull()); accountData.setTimeZone(Objects.firstNonNull(timeZone, currentAccount.getTimeZone())); accountData.setLocale(Objects.firstNonNull(locale, currentAccount.getLocale())); accountData.setAddress1(Objects.firstNonNull(address1, currentAccount.getAddress1())); accountData.setAddress2(Objects.firstNonNull(address2, currentAccount.getAddress2())); accountData.setCompanyName(Objects.firstNonNull(companyName, currentAccount.getCompanyName())); accountData.setCity(Objects.firstNonNull(city, currentAccount.getCity())); accountData.setStateOrProvince( Objects.firstNonNull(stateOrProvince, currentAccount.getStateOrProvince())); accountData.setCountry(Objects.firstNonNull(country, currentAccount.getCountry())); accountData.setPostalCode(Objects.firstNonNull(postalCode, currentAccount.getPostalCode())); accountData.setPhone(Objects.firstNonNull(phone, currentAccount.getPhone())); accountData.setIsMigrated(Objects.firstNonNull(isMigrated, currentAccount.isMigrated())); accountData.setIsNotifiedForInvoices( Objects.firstNonNull(isNotifiedForInvoices, currentAccount.isNotifiedForInvoices())); return new DefaultAccount(currentAccount.getId(), accountData); }
public void changeType(Account pAccount, String newType) throws SQLException, ConnectionException, NullAccountException, EmailException { String demotionSql = "DELETE FROM " // cancella vecchie info + pAccount.getTypeAccount() + "WHERE fkAccount = '" + testEmail(pAccount.getSecondaryEmail()) + "'"; String toProfessorSql = "INSERT INTO professor " // se nuovo professor + "(fkAccount,link,department)" + "VALUES ('" + testEmail(pAccount.getSecondaryEmail()) + "'," + "'" + "null" + "'," + "'" + "null" + "'"; String toPhdSql = "INSERT INTO phdstudent " + "(fkAccount,telephone,link,deparment,researchInterest,fkCycle" + "fkCurriculum, fkProfessor )" // nuovo dottorando + "VALUES ('" + testEmail(pAccount.getSecondaryEmail()) + "'," + "'" + "null" + "'," + "'" + "null" + "'," + "'" + "null" + "'," + "'" + "null" + "'," + "'" + "null" + "'," + "'" + "null" + "'," + "'" + "null" + "'"; String changeTypeSql = "UPDATE account" // aggiorna il tipo + "set typeAccount = '" + newType + "' WHERE email = '" + pAccount.getEmail(); Connection connect = null; try { connect = DBConnection.getConnection(); pAccount = testAccount(pAccount); if (newType.equals("phdstudent") && pAccount.getTypeAccount().equals("basic")) { Utility.executeOperation(connect, toPhdSql); // diventa un dottorando Utility.executeOperation(connect, changeTypeSql); // cambia tipo in account } else if (newType.equals("phdstudent") && pAccount.getTypeAccount().equals("professor")) { Utility.executeOperation(connect, demotionSql); // perde info phd Utility.executeOperation(connect, toPhdSql); // nuove info prof Utility.executeOperation(connect, changeTypeSql); } else if (newType.equals("professor") && pAccount.getTypeAccount().equals("basic")) { Utility.executeOperation(connect, toProfessorSql); Utility.executeOperation(connect, changeTypeSql); } else if (newType.equals("professor") && pAccount.getTypeAccount().equals("phdstudent")) { Utility.executeOperation(connect, demotionSql); Utility.executeOperation(connect, toProfessorSql); Utility.executeOperation(connect, changeTypeSql); } else if (newType.equals("basic")) { Utility.executeOperation(connect, demotionSql); Utility.executeOperation(connect, changeTypeSql); } } finally { DBConnection.releaseConnection(connect); } }