Ejemplo n.º 1
0
  /**
   * Creates an User with roles.
   *
   * @param login The user login.
   * @return The User.
   */
  protected TestUser makeUser(String login) {
    TestUser user = new TestUser();
    user.setEmail(login);

    int adminID =
        ps.queryFirst(TestRole.class, "select tr from TestRole tr where tr.name = 'admin'").getId();
    int userID =
        ps.queryFirst(TestRole.class, "select tr from TestRole tr where tr.name = 'user'").getId();

    Map<String, int[]> associations = new HashMap<String, int[]>();
    associations.put("roles", new int[] {adminID, userID});

    assertTrue(userService.persist(user, associations, "password"));
    return user;
  }