Ejemplo n.º 1
0
  public void testAddUserRole() throws Exception {
    User user = dao.get(2L);
    assertEquals(6, user.getRoles().size());

    Role role = rdao.getRoleByName("ROLE_EXTERNAL");
    assertEquals((Long) 4L, (Long) role.getId());
    user.addRole(role);
    user = dao.saveUser(user);
    // flush();

    user = dao.get(2L);
    assertEquals(7, user.getRoles().size());

    // add the same role twice - should result in no additional role
    user.addRole(role);
    dao.saveUser(user);
    // flush();

    user = dao.get(2L);
    assertEquals("more than 7 roles", 7, user.getRoles().size());

    user.getRoles().remove(role);
    dao.saveUser(user);
    // flush();

    user = dao.get(2L);
    assertEquals(6, user.getRoles().size());
  }
Ejemplo n.º 2
0
  public void testAddAndRemoveUser() throws Exception {
    User user = new User("testuser");
    user.setPassword("testpass");
    user.setFirstName("Test");
    user.setLastName("Last");
    Address address = new Address();
    address.setCity("Denver");
    address.setProvince("CO");
    address.setCountry("USA");
    address.setPostalCode("80210");
    user.setAddress(address);
    user.setEmail("*****@*****.**");
    user.setWebsite("http://tek42.com");
    user.setTimeZone("US/Central");

    // Here we are creating an org that should already be in the database...
    // Ideally, we somehow have an org object... from the other dao or whatever...
    /*
     * Account org = new Account(); org.setName("Tek42"); org.setId(1L);
     */
    Account org = adao.get(2L);
    System.out.println("Have org: " + org);
    user.setAccount(org);

    Role role = rdao.getRoleByName(Constants.USER_ROLE);
    assertNotNull(role.getId());
    user.addRole(role);

    user = dao.saveUser(user);

    assertNotNull(user.getId());

    user = dao.get(user.getId());

    assertEquals("Vigilant", user.getAccount().getName());
    assertEquals("testpass", user.getPassword());
    assertEquals("US/Central", user.getTimeZone());

    dao.remove(user.getId());

    try {
      dao.get(user.getId());
      fail("getUser didn't throw DataAccessException");
    } catch (DataAccessException d) {
      assertNotNull(d);
    }
  }