@Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    PasswordTracker newPasswordTracker = _persistence.create(pk);

    newPasswordTracker.setMvccVersion(RandomTestUtil.nextLong());

    newPasswordTracker.setCompanyId(RandomTestUtil.nextLong());

    newPasswordTracker.setUserId(RandomTestUtil.nextLong());

    newPasswordTracker.setCreateDate(RandomTestUtil.nextDate());

    newPasswordTracker.setPassword(RandomTestUtil.randomString());

    _passwordTrackers.add(_persistence.update(newPasswordTracker));

    PasswordTracker existingPasswordTracker =
        _persistence.findByPrimaryKey(newPasswordTracker.getPrimaryKey());

    Assert.assertEquals(
        existingPasswordTracker.getMvccVersion(), newPasswordTracker.getMvccVersion());
    Assert.assertEquals(
        existingPasswordTracker.getPasswordTrackerId(), newPasswordTracker.getPasswordTrackerId());
    Assert.assertEquals(existingPasswordTracker.getCompanyId(), newPasswordTracker.getCompanyId());
    Assert.assertEquals(existingPasswordTracker.getUserId(), newPasswordTracker.getUserId());
    Assert.assertEquals(
        Time.getShortTimestamp(existingPasswordTracker.getCreateDate()),
        Time.getShortTimestamp(newPasswordTracker.getCreateDate()));
    Assert.assertEquals(existingPasswordTracker.getPassword(), newPasswordTracker.getPassword());
  }
Пример #2
0
  protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) {
    if (passwordTracker instanceof PasswordTrackerImpl) {
      return passwordTracker;
    }

    PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl();

    passwordTrackerImpl.setNew(passwordTracker.isNew());
    passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey());

    passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId());
    passwordTrackerImpl.setUserId(passwordTracker.getUserId());
    passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate());
    passwordTrackerImpl.setPassword(passwordTracker.getPassword());

    return passwordTrackerImpl;
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    PasswordTracker newPasswordTracker = addPasswordTracker();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(PasswordTracker.class, _dynamicQueryClassLoader);

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("passwordTrackerId", newPasswordTracker.getPasswordTrackerId()));

    List<PasswordTracker> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    PasswordTracker existingPasswordTracker = result.get(0);

    Assert.assertEquals(existingPasswordTracker, newPasswordTracker);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    PasswordTracker newPasswordTracker = addPasswordTracker();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(PasswordTracker.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("passwordTrackerId"));

    Object newPasswordTrackerId = newPasswordTracker.getPasswordTrackerId();

    dynamicQuery.add(
        RestrictionsFactoryUtil.in("passwordTrackerId", new Object[] {newPasswordTrackerId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingPasswordTrackerId = result.get(0);

    Assert.assertEquals(existingPasswordTrackerId, newPasswordTrackerId);
  }