Ejemplo n.º 1
0
  @Test
  public void testUpdateRole() throws Exception {
    Role role = dao.getRoleByName("ROLE_USER");
    log.debug(role);
    role.setDescription("test descr");

    dao.save(role);

    role = dao.getRoleByName("ROLE_USER");
    assertEquals(role.getDescription(), "test descr");
  }
Ejemplo n.º 2
0
  @Test
  public void testAddUserRole() throws Exception {
    User user = dao.get(-1L);
    assertEquals(1, user.getRoles().size());

    Role role = rdao.getRoleByName(Constants.ADMIN_ROLE);
    user.addRole(role);
    dao.saveUser(user);
    flush();

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

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

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

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

    user = dao.get(-1L);
    assertEquals(1, user.getRoles().size());
  }
Ejemplo n.º 3
0
  @Test
  @ExpectedException(DataAccessException.class)
  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://raibledesigns.com");

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

    user = dao.saveUser(user);
    flush();

    assertNotNull(user.getId());
    user = dao.get(user.getId());
    assertEquals("testpass", user.getPassword());

    dao.remove(user);
    flush();

    // should throw DataAccessException
    dao.get(user.getId());
  }
Ejemplo n.º 4
0
  @Test
  public void testAddAndRemoveRole() throws Exception {
    Role role = new Role("testrole");
    role.setDescription("new role descr");
    dao.save(role);
    // setComplete(); // change behavior from rollback to commit
    // endTransaction();

    // startNewTransaction();
    role = dao.getRoleByName("testrole");
    assertNotNull(role.getDescription());

    dao.removeRole("testrole");
    // setComplete();
    // endTransaction(); // deletes role from database

    role = dao.getRoleByName("testrole");
    assertNull(role);
  }
Ejemplo n.º 5
0
 @Test
 public void testGetRole() throws Exception {
   Role role = dao.getRoleByName(Constants.USER_ROLE);
   assertNotNull(role);
 }
Ejemplo n.º 6
0
 @Test
 public void testGetRoleInvalid() throws Exception {
   Role role = dao.getRoleByName("badrolename");
   assertNull(role);
 }