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

    RatingsEntry newRatingsEntry = _persistence.create(pk);

    newRatingsEntry.setUuid(RandomTestUtil.randomString());

    newRatingsEntry.setCompanyId(RandomTestUtil.nextLong());

    newRatingsEntry.setUserId(RandomTestUtil.nextLong());

    newRatingsEntry.setUserName(RandomTestUtil.randomString());

    newRatingsEntry.setCreateDate(RandomTestUtil.nextDate());

    newRatingsEntry.setModifiedDate(RandomTestUtil.nextDate());

    newRatingsEntry.setClassNameId(RandomTestUtil.nextLong());

    newRatingsEntry.setClassPK(RandomTestUtil.nextLong());

    newRatingsEntry.setScore(RandomTestUtil.nextDouble());

    newRatingsEntry.setLastPublishDate(RandomTestUtil.nextDate());

    _ratingsEntries.add(_persistence.update(newRatingsEntry));

    RatingsEntry existingRatingsEntry =
        _persistence.findByPrimaryKey(newRatingsEntry.getPrimaryKey());

    Assert.assertEquals(existingRatingsEntry.getUuid(), newRatingsEntry.getUuid());
    Assert.assertEquals(existingRatingsEntry.getEntryId(), newRatingsEntry.getEntryId());
    Assert.assertEquals(existingRatingsEntry.getCompanyId(), newRatingsEntry.getCompanyId());
    Assert.assertEquals(existingRatingsEntry.getUserId(), newRatingsEntry.getUserId());
    Assert.assertEquals(existingRatingsEntry.getUserName(), newRatingsEntry.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getCreateDate()),
        Time.getShortTimestamp(newRatingsEntry.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getModifiedDate()),
        Time.getShortTimestamp(newRatingsEntry.getModifiedDate()));
    Assert.assertEquals(existingRatingsEntry.getClassNameId(), newRatingsEntry.getClassNameId());
    Assert.assertEquals(existingRatingsEntry.getClassPK(), newRatingsEntry.getClassPK());
    AssertUtils.assertEquals(existingRatingsEntry.getScore(), newRatingsEntry.getScore());
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getLastPublishDate()),
        Time.getShortTimestamp(newRatingsEntry.getLastPublishDate()));
  }
  protected void importRatings(long oldClassNameId, long oldClassPK, long classNameId, long classPK)
      throws SystemException {

    List<RatingsEntry> ratingsEntries =
        ratingsEntryPersistence.findByC_C(oldClassNameId, oldClassPK);

    for (RatingsEntry ratingsEntry : ratingsEntries) {
      addRatingsEntry(
          counterLocalService.increment(),
          ratingsEntry.getCompanyId(),
          ratingsEntry.getUserId(),
          ratingsEntry.getUserName(),
          ratingsEntry.getCreateDate(),
          ratingsEntry.getModifiedDate(),
          classNameId,
          classPK,
          ratingsEntry.getScore());
    }

    RatingsStats ratingsStats = ratingsStatsPersistence.fetchByC_C(oldClassNameId, oldClassPK);

    if (ratingsStats == null) {
      return;
    }

    addRatingsStats(
        counterLocalService.increment(),
        classNameId,
        classPK,
        ratingsStats.getTotalEntries(),
        ratingsStats.getTotalScore(),
        ratingsStats.getAverageScore());
  }