public void testFetchByPrimaryKeyExisting() throws Exception {
    User newUser = addUser();

    User existingUser = _persistence.fetchByPrimaryKey(newUser.getPrimaryKey());

    assertEquals(existingUser, newUser);
  }
  public void testRemove() throws Exception {
    User newUser = addUser();

    _persistence.remove(newUser);

    User existingUser = _persistence.fetchByPrimaryKey(newUser.getPrimaryKey());

    assertNull(existingUser);
  }
  public void testCreate() throws Exception {
    long pk = nextLong();

    User user = _persistence.create(pk);

    assertNotNull(user);

    assertEquals(user.getPrimaryKey(), pk);
  }
  public int compareTo(User user) {
    long primaryKey = user.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
Exemple #5
0
  public static com.liferay.portal.model.User model(UserHBM userHBM) {
    com.liferay.portal.model.User user = UserPool.get(userHBM.getPrimaryKey());

    if (user == null) {
      user =
          new com.liferay.portal.model.User(
              userHBM.getUserId(),
              userHBM.getCompanyId(),
              userHBM.getPassword(),
              userHBM.getPasswordEncrypted(),
              userHBM.getPasswordExpirationDate(),
              userHBM.getPasswordReset(),
              userHBM.getFirstName(),
              userHBM.getMiddleName(),
              userHBM.getLastName(),
              userHBM.getNickName(),
              userHBM.getMale(),
              userHBM.getBirthday(),
              userHBM.getEmailAddress(),
              userHBM.getSmsId(),
              userHBM.getAimId(),
              userHBM.getIcqId(),
              userHBM.getMsnId(),
              userHBM.getYmId(),
              userHBM.getFavoriteActivity(),
              userHBM.getFavoriteBibleVerse(),
              userHBM.getFavoriteFood(),
              userHBM.getFavoriteMovie(),
              userHBM.getFavoriteMusic(),
              userHBM.getLanguageId(),
              userHBM.getTimeZoneId(),
              userHBM.getSkinId(),
              userHBM.getDottedSkins(),
              userHBM.getRoundedSkins(),
              userHBM.getGreeting(),
              userHBM.getResolution(),
              userHBM.getRefreshRate(),
              userHBM.getLayoutIds(),
              userHBM.getComments(),
              userHBM.getCreateDate(),
              userHBM.getLoginDate(),
              userHBM.getLoginIP(),
              userHBM.getLastLoginDate(),
              userHBM.getLastLoginIP(),
              userHBM.getFailedLoginAttempts(),
              userHBM.getAgreedToTermsOfUse(),
              userHBM.getActive());
      UserPool.put(user.getPrimaryKey(), user);
    }

    return user;
  }
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    User newUser = addUser();

    _persistence.clearCache();

    UserModelImpl existingUserModelImpl =
        (UserModelImpl) _persistence.findByPrimaryKey(newUser.getPrimaryKey());

    assertEquals(
        existingUserModelImpl.getContactId(), existingUserModelImpl.getOriginalContactId());

    assertEquals(
        existingUserModelImpl.getPortraitId(), existingUserModelImpl.getOriginalPortraitId());

    assertEquals(
        existingUserModelImpl.getCompanyId(), existingUserModelImpl.getOriginalCompanyId());
    assertEquals(existingUserModelImpl.getUserId(), existingUserModelImpl.getOriginalUserId());

    assertEquals(
        existingUserModelImpl.getCompanyId(), existingUserModelImpl.getOriginalCompanyId());
    assertEquals(
        existingUserModelImpl.getDefaultUser(), existingUserModelImpl.getOriginalDefaultUser());

    assertEquals(
        existingUserModelImpl.getCompanyId(), existingUserModelImpl.getOriginalCompanyId());
    assertTrue(
        Validator.equals(
            existingUserModelImpl.getScreenName(), existingUserModelImpl.getOriginalScreenName()));

    assertEquals(
        existingUserModelImpl.getCompanyId(), existingUserModelImpl.getOriginalCompanyId());
    assertTrue(
        Validator.equals(
            existingUserModelImpl.getEmailAddress(),
            existingUserModelImpl.getOriginalEmailAddress()));

    assertEquals(
        existingUserModelImpl.getCompanyId(), existingUserModelImpl.getOriginalCompanyId());
    assertEquals(
        existingUserModelImpl.getFacebookId(), existingUserModelImpl.getOriginalFacebookId());

    assertEquals(
        existingUserModelImpl.getCompanyId(), existingUserModelImpl.getOriginalCompanyId());
    assertTrue(
        Validator.equals(
            existingUserModelImpl.getOpenId(), existingUserModelImpl.getOriginalOpenId()));
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    User user = null;

    try {
      user = (User) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = user.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  public void testUpdateExisting() throws Exception {
    long pk = nextLong();

    User newUser = _persistence.create(pk);

    newUser.setUuid(randomString());
    newUser.setCompanyId(nextLong());
    newUser.setCreateDate(nextDate());
    newUser.setModifiedDate(nextDate());
    newUser.setDefaultUser(randomBoolean());
    newUser.setContactId(nextLong());
    newUser.setPassword(randomString());
    newUser.setPasswordEncrypted(randomBoolean());
    newUser.setPasswordReset(randomBoolean());
    newUser.setPasswordModifiedDate(nextDate());
    newUser.setDigest(randomString());
    newUser.setReminderQueryQuestion(randomString());
    newUser.setReminderQueryAnswer(randomString());
    newUser.setGraceLoginCount(nextInt());
    newUser.setScreenName(randomString());
    newUser.setEmailAddress(randomString());
    newUser.setFacebookId(nextLong());
    newUser.setOpenId(randomString());
    newUser.setPortraitId(nextLong());
    newUser.setLanguageId(randomString());
    newUser.setTimeZoneId(randomString());
    newUser.setGreeting(randomString());
    newUser.setComments(randomString());
    newUser.setFirstName(randomString());
    newUser.setMiddleName(randomString());
    newUser.setLastName(randomString());
    newUser.setJobTitle(randomString());
    newUser.setLoginDate(nextDate());
    newUser.setLoginIP(randomString());
    newUser.setLastLoginDate(nextDate());
    newUser.setLastLoginIP(randomString());
    newUser.setLastFailedLoginDate(nextDate());
    newUser.setFailedLoginAttempts(nextInt());
    newUser.setLockout(randomBoolean());
    newUser.setLockoutDate(nextDate());
    newUser.setAgreedToTermsOfUse(randomBoolean());
    newUser.setStatus(nextInt());

    _persistence.update(newUser, false);

    User existingUser = _persistence.findByPrimaryKey(newUser.getPrimaryKey());

    assertEquals(existingUser.getUuid(), newUser.getUuid());
    assertEquals(existingUser.getUserId(), newUser.getUserId());
    assertEquals(existingUser.getCompanyId(), newUser.getCompanyId());
    assertEquals(
        Time.getShortTimestamp(existingUser.getCreateDate()),
        Time.getShortTimestamp(newUser.getCreateDate()));
    assertEquals(
        Time.getShortTimestamp(existingUser.getModifiedDate()),
        Time.getShortTimestamp(newUser.getModifiedDate()));
    assertEquals(existingUser.getDefaultUser(), newUser.getDefaultUser());
    assertEquals(existingUser.getContactId(), newUser.getContactId());
    assertEquals(existingUser.getPassword(), newUser.getPassword());
    assertEquals(existingUser.getPasswordEncrypted(), newUser.getPasswordEncrypted());
    assertEquals(existingUser.getPasswordReset(), newUser.getPasswordReset());
    assertEquals(
        Time.getShortTimestamp(existingUser.getPasswordModifiedDate()),
        Time.getShortTimestamp(newUser.getPasswordModifiedDate()));
    assertEquals(existingUser.getDigest(), newUser.getDigest());
    assertEquals(existingUser.getReminderQueryQuestion(), newUser.getReminderQueryQuestion());
    assertEquals(existingUser.getReminderQueryAnswer(), newUser.getReminderQueryAnswer());
    assertEquals(existingUser.getGraceLoginCount(), newUser.getGraceLoginCount());
    assertEquals(existingUser.getScreenName(), newUser.getScreenName());
    assertEquals(existingUser.getEmailAddress(), newUser.getEmailAddress());
    assertEquals(existingUser.getFacebookId(), newUser.getFacebookId());
    assertEquals(existingUser.getOpenId(), newUser.getOpenId());
    assertEquals(existingUser.getPortraitId(), newUser.getPortraitId());
    assertEquals(existingUser.getLanguageId(), newUser.getLanguageId());
    assertEquals(existingUser.getTimeZoneId(), newUser.getTimeZoneId());
    assertEquals(existingUser.getGreeting(), newUser.getGreeting());
    assertEquals(existingUser.getComments(), newUser.getComments());
    assertEquals(existingUser.getFirstName(), newUser.getFirstName());
    assertEquals(existingUser.getMiddleName(), newUser.getMiddleName());
    assertEquals(existingUser.getLastName(), newUser.getLastName());
    assertEquals(existingUser.getJobTitle(), newUser.getJobTitle());
    assertEquals(
        Time.getShortTimestamp(existingUser.getLoginDate()),
        Time.getShortTimestamp(newUser.getLoginDate()));
    assertEquals(existingUser.getLoginIP(), newUser.getLoginIP());
    assertEquals(
        Time.getShortTimestamp(existingUser.getLastLoginDate()),
        Time.getShortTimestamp(newUser.getLastLoginDate()));
    assertEquals(existingUser.getLastLoginIP(), newUser.getLastLoginIP());
    assertEquals(
        Time.getShortTimestamp(existingUser.getLastFailedLoginDate()),
        Time.getShortTimestamp(newUser.getLastFailedLoginDate()));
    assertEquals(existingUser.getFailedLoginAttempts(), newUser.getFailedLoginAttempts());
    assertEquals(existingUser.getLockout(), newUser.getLockout());
    assertEquals(
        Time.getShortTimestamp(existingUser.getLockoutDate()),
        Time.getShortTimestamp(newUser.getLockoutDate()));
    assertEquals(existingUser.getAgreedToTermsOfUse(), newUser.getAgreedToTermsOfUse());
    assertEquals(existingUser.getStatus(), newUser.getStatus());
  }