Exemple #1
0
  public void testUpdateUser() throws Exception {
    User user = dao.get(1L);

    Address address = user.getAddress();
    address.setAddress1("new address");
    user.setTimeZone("US/Central");

    dao.saveUser(user);

    user = dao.get(1L);
    assertEquals(address, user.getAddress());
    assertEquals("new address", user.getAddress().getAddress1());
    assertEquals("US/Central", user.getTimeZone());

    // verify that violation occurs when adding new user with same username
    user.setId(null);

    endTransaction();

    try {
      dao.saveUser(user);
      // flush();
      fail("saveUser didn't throw DataIntegrityViolationException");
    } catch (DataIntegrityViolationException e) {
      assertNotNull(e);
      log.debug("expected exception: " + e.getMessage());
    }
  }
Exemple #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);
    }
  }
Exemple #3
0
  public void testGetUser() throws Exception {
    User user = dao.get(1L);

    assertNotNull(user);
    assertEquals(1, user.getRoles().size());
    assertTrue(user.isEnabled());
    assertNotNull(user.getAccount());
    assertEquals(1L, (long) user.getAccount().getId());
    assertEquals("Tek42", user.getAccount().getName());
    assertEquals("US/Eastern", user.getTimeZone());
    assertTrue(!user.isHasProfile());
    user.setAccount(adao.get(1L));

    endTransaction();

    dao.save(user);
  }