Пример #1
0
  @Test
  public void shouldReturnCountOfReportingRightOfUser() throws SQLException {
    Long userId = 1L;
    Right right1 = new Right("template1", RightType.REPORTING);
    Right right2 = new Right("template2", RightType.REPORTING);
    Right right3 = new Right("template3", RightType.REPORTING);
    Right right4 = new Right("admin", RightType.REPORTING);
    rightMapper.insertRight(right1);
    rightMapper.insertRight(right2);
    rightMapper.insertRight(right3);
    rightMapper.insertRight(right4);

    Role role = new Role();
    role.setName("New Role");
    roleRightsMapper.insertRole(role);
    queryExecutor.executeUpdate(
        "INSERT INTO role_rights(roleId, rightName) VALUES (?,?)", role.getId(), "template1");
    queryExecutor.executeUpdate(
        "INSERT INTO role_rights(roleId, rightName) VALUES (?,?)", role.getId(), "template2");
    queryExecutor.executeUpdate(
        "INSERT INTO role_rights(roleId, rightName) VALUES (?,?)", role.getId(), "template3");
    queryExecutor.executeUpdate(
        "INSERT INTO role_rights(roleId, rightName) VALUES (?,?)", role.getId(), "admin");

    queryExecutor.executeUpdate(
        "INSERT INTO role_assignments(userId, roleId) VALUES (?,?)", userId, role.getId());

    Integer count = rightMapper.totalReportingRightsFor(userId);

    assertThat(count, is(4));
  }