Beispiel #1
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());
  }
Beispiel #2
0
  @Test
  @ExpectedException(DataIntegrityViolationException.class)
  public void testUpdateUser() throws Exception {
    User user = dao.get(-1L);

    Address address = user.getAddress();
    address.setAddress("new address");

    dao.saveUser(user);
    flush();

    user = dao.get(-1L);
    assertEquals(address, user.getAddress());
    assertEquals("new address", user.getAddress().getAddress());

    // verify that violation occurs when adding new user with same username
    User user2 = new User();
    user2.setAddress(user.getAddress());
    user2.setConfirmPassword(user.getConfirmPassword());
    user2.setEmail(user.getEmail());
    user2.setFirstName(user.getFirstName());
    user2.setLastName(user.getLastName());
    user2.setPassword(user.getPassword());
    user2.setPasswordHint(user.getPasswordHint());
    user2.setRoles(user.getRoles());
    user2.setUsername(user.getUsername());
    user2.setWebsite(user.getWebsite());

    // should throw DataIntegrityViolationException
    dao.saveUser(user2);
  }
Beispiel #3
0
  /**
   * Overridden equals method for object comparison. Compares based on hashCode.
   *
   * @param o Object to compare
   * @return true/false based on hashCode
   */
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof Address)) {
      return false;
    }

    final Address address1 = (Address) o;

    return this.hashCode() == address1.hashCode();
  }