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

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


    return role;
  }

  public static Role getRandomRoleWithAuthority() {
    Role role = getRandomRole();
    role.getAuthorityList().addAll(getRandomDefaultAuthorityList());
    return role;
  }
View Full Code Here


  }

  public static List<Role> getDefaultRoleList() {
    if (defaultRoleList == null) {
      defaultRoleList = Lists.newArrayList();
      defaultRoleList.add(new Role(1L, "管理员"));
      defaultRoleList.add(new Role(2L, "用户"));
    }
    return defaultRoleList;
  }
View Full Code Here

      SeleniumUtils.uncheck(driver.findElement(By.id("checkedRoleIds-" + role.getId())));
    }
    testUser.getRoleList().clear();

    //增加一个角色
    Role role = AccountData.getRandomDefaultRole();
    driver.findElement(By.id("checkedRoleIds-" + role.getId())).setSelected();
    testUser.getRoleList().add(role);

    driver.findElement(By.xpath(Gui.BUTTON_SUBMIT)).click();

    //校验结果
View Full Code Here

  public void createRole() {
    driver.findElement(By.linkText(Gui.MENU_ROLE)).click();
    driver.findElement(By.linkText("增加新角色")).click();

    //生成测试数据
    Role role = AccountData.getRandomRoleWithAuthority();

    //输入数据
    SeleniumUtils.type(driver.findElement(By.id("name")), role.getName());
    for (Authority authority : role.getAuthorityList()) {
      driver.findElement(By.id("checkedAuthIds-" + authority.getId())).setSelected();
    }
    driver.findElement(By.xpath(Gui.BUTTON_SUBMIT)).click();

    //校验结果
View Full Code Here

    return user;
  }

  public static Role getRandomRole() {
    Role role = new Role();
    role.setName(DataUtils.randomName("Role"));

    return role;
  }
View Full Code Here

  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();
View Full Code Here

   * 测试删除角色时删除用户-角色的中间表.
   */
  @Test
  public void deleteRole() {
    //新增测试角色并与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");

    //删除用户角色, 中间表将减少1条记录,而用户表应该不受影响.
    roleDao.delete(role.getId());
    roleDao.flush();

    int newJoinTableCount = countRowsInTable("ACCT_USER_ROLE");
    int newUserTableCount = countRowsInTable("ACCT_USER");
    assertEquals(1, oldJoinTableCount - newJoinTableCount);
View Full Code Here

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

   * 重载函数,因为Role中没有建立与User的关联,因此需要以较低效率的方式进行删除User与Role的多对多中间表.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void delete(Long id) {
    Role role = get(id);
    //查询出拥有该角色的用户,并删除该用户的角色.
    List<User> users = createQuery(QUERY_USER_BY_ROLEID, role.getId()).list();
    for (User u : users) {
      u.getRoleList().remove(role);
    }
    super.delete(role);
  }
View Full Code Here

TOP

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

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.