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

    SocialActivityAchievement newSocialActivityAchievement = addSocialActivityAchievement();

    _persistence.clearCache();

    SocialActivityAchievementModelImpl existingSocialActivityAchievementModelImpl =
        (SocialActivityAchievementModelImpl)
            _persistence.findByPrimaryKey(newSocialActivityAchievement.getPrimaryKey());

    Assert.assertEquals(
        existingSocialActivityAchievementModelImpl.getGroupId(),
        existingSocialActivityAchievementModelImpl.getOriginalGroupId());
    Assert.assertEquals(
        existingSocialActivityAchievementModelImpl.getUserId(),
        existingSocialActivityAchievementModelImpl.getOriginalUserId());
    Assert.assertTrue(
        Validator.equals(
            existingSocialActivityAchievementModelImpl.getName(),
            existingSocialActivityAchievementModelImpl.getOriginalName()));
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    SocialActivityAchievement newSocialActivityAchievement = addSocialActivityAchievement();

    SocialActivityAchievement existingSocialActivityAchievement =
        _persistence.fetchByPrimaryKey(newSocialActivityAchievement.getPrimaryKey());

    Assert.assertEquals(existingSocialActivityAchievement, newSocialActivityAchievement);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    SocialActivityAchievement socialActivityAchievement = _persistence.create(pk);

    Assert.assertNotNull(socialActivityAchievement);

    Assert.assertEquals(socialActivityAchievement.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    SocialActivityAchievement newSocialActivityAchievement = addSocialActivityAchievement();

    _persistence.remove(newSocialActivityAchievement);

    SocialActivityAchievement existingSocialActivityAchievement =
        _persistence.fetchByPrimaryKey(newSocialActivityAchievement.getPrimaryKey());

    Assert.assertNull(existingSocialActivityAchievement);
  }
  /**
   * Adds the social activity achievement to the database. Also notifies the appropriate model
   * listeners.
   *
   * @param socialActivityAchievement the social activity achievement
   * @return the social activity achievement that was added
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public SocialActivityAchievement addSocialActivityAchievement(
      SocialActivityAchievement socialActivityAchievement) {
    socialActivityAchievement.setNew(true);

    return socialActivityAchievementPersistence.update(socialActivityAchievement);
  }
  public void addActivityAchievement(long userId, long groupId, SocialAchievement achievement)
      throws PortalException, SystemException {

    SocialActivityAchievement activityAchievement =
        socialActivityAchievementPersistence.fetchByG_U_N(groupId, userId, achievement.getName());

    if (activityAchievement != null) {
      return;
    }

    User user = userPersistence.findByPrimaryKey(userId);

    long activityAchievementId = counterLocalService.increment();

    activityAchievement = socialActivityAchievementPersistence.create(activityAchievementId);

    activityAchievement.setGroupId(groupId);
    activityAchievement.setCompanyId(user.getCompanyId());
    activityAchievement.setUserId(userId);
    activityAchievement.setCreateDate(System.currentTimeMillis());

    int count = socialActivityAchievementPersistence.countByG_N(groupId, achievement.getName());

    if (count == 0) {
      activityAchievement.setFirstInGroup(true);
    }

    activityAchievement.setName(achievement.getName());

    socialActivityAchievementPersistence.update(activityAchievement, false);

    socialActivityCounterLocalService.incrementUserAchievementCounter(userId, groupId);
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    SocialActivityAchievement newSocialActivityAchievement = addSocialActivityAchievement();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialActivityAchievement.class, SocialActivityAchievement.class.getClassLoader());

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq(
            "activityAchievementId", newSocialActivityAchievement.getActivityAchievementId()));

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

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

    SocialActivityAchievement existingSocialActivityAchievement = result.get(0);

    Assert.assertEquals(existingSocialActivityAchievement, newSocialActivityAchievement);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    SocialActivityAchievement newSocialActivityAchievement = addSocialActivityAchievement();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            SocialActivityAchievement.class, SocialActivityAchievement.class.getClassLoader());

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

    Object newActivityAchievementId = newSocialActivityAchievement.getActivityAchievementId();

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

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

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

    Object existingActivityAchievementId = result.get(0);

    Assert.assertEquals(existingActivityAchievementId, newActivityAchievementId);
  }
  protected SocialActivityAchievement addSocialActivityAchievement() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    SocialActivityAchievement socialActivityAchievement = _persistence.create(pk);

    socialActivityAchievement.setGroupId(ServiceTestUtil.nextLong());

    socialActivityAchievement.setCompanyId(ServiceTestUtil.nextLong());

    socialActivityAchievement.setUserId(ServiceTestUtil.nextLong());

    socialActivityAchievement.setCreateDate(ServiceTestUtil.nextLong());

    socialActivityAchievement.setName(ServiceTestUtil.randomString());

    socialActivityAchievement.setFirstInGroup(ServiceTestUtil.randomBoolean());

    _persistence.update(socialActivityAchievement);

    return socialActivityAchievement;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    SocialActivityAchievement newSocialActivityAchievement = _persistence.create(pk);

    newSocialActivityAchievement.setGroupId(ServiceTestUtil.nextLong());

    newSocialActivityAchievement.setCompanyId(ServiceTestUtil.nextLong());

    newSocialActivityAchievement.setUserId(ServiceTestUtil.nextLong());

    newSocialActivityAchievement.setCreateDate(ServiceTestUtil.nextLong());

    newSocialActivityAchievement.setName(ServiceTestUtil.randomString());

    newSocialActivityAchievement.setFirstInGroup(ServiceTestUtil.randomBoolean());

    _persistence.update(newSocialActivityAchievement);

    SocialActivityAchievement existingSocialActivityAchievement =
        _persistence.findByPrimaryKey(newSocialActivityAchievement.getPrimaryKey());

    Assert.assertEquals(
        existingSocialActivityAchievement.getActivityAchievementId(),
        newSocialActivityAchievement.getActivityAchievementId());
    Assert.assertEquals(
        existingSocialActivityAchievement.getGroupId(), newSocialActivityAchievement.getGroupId());
    Assert.assertEquals(
        existingSocialActivityAchievement.getCompanyId(),
        newSocialActivityAchievement.getCompanyId());
    Assert.assertEquals(
        existingSocialActivityAchievement.getUserId(), newSocialActivityAchievement.getUserId());
    Assert.assertEquals(
        existingSocialActivityAchievement.getCreateDate(),
        newSocialActivityAchievement.getCreateDate());
    Assert.assertEquals(
        existingSocialActivityAchievement.getName(), newSocialActivityAchievement.getName());
    Assert.assertEquals(
        existingSocialActivityAchievement.getFirstInGroup(),
        newSocialActivityAchievement.getFirstInGroup());
  }