Package org.springside.examples.miniweb.entity.account

Examples of org.springside.examples.miniweb.entity.account.User


  private static List<Authority> defaultAuthorityList = null;

  public static User getRandomUser() {
    String userName = DataUtils.randomName("User");

    User user = new User();
    user.setLoginName(userName);
    user.setName(userName);
    user.setPassword(DEFAULT_PASSWORD);
    user.setEmail(userName + "@springside.org.cn");

    return user;
  }
View Full Code Here


    return user;
  }

  public static User getRandomUserWithRole() {
    User user = getRandomUser();
    user.getRoleList().add(getRandomDefaultRole());

    return user;
  }
View Full Code Here

    //打开新增用户页面
    driver.findElement(By.linkText(Gui.MENU_USER)).click();
    driver.findElement(By.linkText("增加新用户")).click();

    //生成待输入的测试用户数据
    User user = AccountData.getRandomUserWithRole();

    //输入数据
    driver.findElement(By.id("loginName")).sendKeys(user.getLoginName());
    driver.findElement(By.id("name")).sendKeys(user.getName());
    driver.findElement(By.id("password")).sendKeys(user.getPassword());
    driver.findElement(By.id("passwordConfirm")).sendKeys(user.getPassword());
    for (Role role : user.getRoleList()) {
      driver.findElement(By.id("checkedRoleIds-" + role.getId())).setSelected();
    }
    driver.findElement(By.xpath(Gui.BUTTON_SUBMIT)).click();

    //校验结果
View Full Code Here

  @Test
  public void loadUserExist() {

    //准备数据
    String authName = "foo";
    User user = AccountData.getRandomUser();
    Role role = AccountData.getRandomRole();
    user.getRoleList().add(role);
    Authority auth = new Authority();
    auth.setName(authName);
    role.getAuthorityList().add(auth);

    //录制脚本
    EasyMock.expect(mockAccountManager.findUserByLoginName(user.getLoginName())).andReturn(user);
    control.replay();

    //执行测试
    UserDetails userDetails = userDetailService.loadUserByUsername(user.getLoginName());

    //校验结果
    assertEquals(user.getLoginName(), userDetails.getUsername());
    assertEquals(user.getPassword(), userDetails.getPassword());
    assertEquals(1, userDetails.getAuthorities().size());
    assertEquals(new GrantedAuthorityImpl(auth.getPrefixedName()), userDetails.getAuthorities().iterator().next());
  }
View Full Code Here

    //新增测试角色并与admin用户绑定.
    Role role = new Role();
    role.setName(DataUtils.randomName("Role"));
    roleDao.save(role);

    User user = userDao.get(1L);
    user.getRoleList().add(role);
    userDao.save(user);
    userDao.flush();

    int oldJoinTableCount = countRowsInTable("ACCT_USER_ROLE");
    int oldUserTableCount = countRowsInTable("ACCT_USER");
View Full Code Here

  @Test
  //如果你需要真正插入数据库,将Rollback设为false
  //@Rollback(false)
  public void crudEntityWithRole() {
    //新建并保存带角色的用户
    User user = AccountData.getRandomUserWithRole();
    entityDao.save(user);
    //强制执行sql语句
    entityDao.flush();

    //获取用户
    user = entityDao.findUniqueBy("id", user.getId());
    assertEquals(1, user.getRoleList().size());

    //删除用户的角色
    user.getRoleList().remove(0);
    entityDao.flush();
    user = entityDao.findUniqueBy("id", user.getId());
    assertEquals(0, user.getRoleList().size());

    //删除用户
    entityDao.delete(user.getId());
    entityDao.flush();
    user = entityDao.findUniqueBy("id", user.getId());
    assertNull(user);
  }
View Full Code Here

  }

  //期望抛出ConstraintViolationException的异常.
  @Test(expected = org.hibernate.exception.ConstraintViolationException.class)
  public void savenUserNotUnique() {
    User user = AccountData.getRandomUser();
    user.setLoginName("admin");
    entityDao.save(user);
    entityDao.flush();
  }
View Full Code Here

  @Override
  protected void prepareModel() throws Exception {
    if (id != null) {
      entity = accountManager.getUser(id);
    } else {
      entity = new User();
    }
  }
View Full Code Here

  /**
   * 获取用户Details信息的回调函数.
   */
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {

    User user = accountManager.findUserByLoginName(username);
    if (user == null) {
      throw new UsernameNotFoundException("用户" + username + " 不存在");
    }

    Set<GrantedAuthority> grantedAuths = obtainGrantedAuthorities(user);

    //-- mini-web示例中无以下属性, 暂时全部设为true. --//
    boolean enabled = true;
    boolean accountNonExpired = true;
    boolean credentialsNonExpired = true;
    boolean accountNonLocked = true;

    UserDetails userdetails = new org.springframework.security.core.userdetails.User(user.getLoginName(), user
        .getPassword(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, grantedAuths);

    return userdetails;
  }
View Full Code Here

public class HibernateUtilsTest {

  @Test
  public void mergeByCheckedIds() {
    User a = new User();
    a.setId(1L);

    User b = new User();
    b.setId(1L);

    List<User> srcList = Lists.newArrayList(a, b);
    List<Long> idList = Lists.newArrayList(1L, 3L);

    HibernateUtils.mergeByCheckedIds(srcList, idList, User.class);
View Full Code Here

TOP

Related Classes of org.springside.examples.miniweb.entity.account.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.