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

    PollsVote newPollsVote = addPollsVote();

    _persistence.clearCache();

    PollsVoteModelImpl existingPollsVoteModelImpl =
        (PollsVoteModelImpl) _persistence.findByPrimaryKey(newPollsVote.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingPollsVoteModelImpl.getUuid(), existingPollsVoteModelImpl.getOriginalUuid()));
    Assert.assertEquals(
        existingPollsVoteModelImpl.getGroupId(), existingPollsVoteModelImpl.getOriginalGroupId());

    Assert.assertEquals(
        existingPollsVoteModelImpl.getQuestionId(),
        existingPollsVoteModelImpl.getOriginalQuestionId());
    Assert.assertEquals(
        existingPollsVoteModelImpl.getUserId(), existingPollsVoteModelImpl.getOriginalUserId());
  }
Exemple #2
0
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    PollsVote newPollsVote = addPollsVote();

    PollsVote existingPollsVote = _persistence.fetchByPrimaryKey(newPollsVote.getPrimaryKey());

    Assert.assertEquals(existingPollsVote, newPollsVote);
  }
Exemple #3
0
  @Test
  public void testRemove() throws Exception {
    PollsVote newPollsVote = addPollsVote();

    _persistence.remove(newPollsVote);

    PollsVote existingPollsVote = _persistence.fetchByPrimaryKey(newPollsVote.getPrimaryKey());

    Assert.assertNull(existingPollsVote);
  }
Exemple #4
0
  @Test
  public void testCreate() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    PollsVote pollsVote = _persistence.create(pk);

    Assert.assertNotNull(pollsVote);

    Assert.assertEquals(pollsVote.getPrimaryKey(), pk);
  }
  public PollsVote addVote(
      long userId, long questionId, long choiceId, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Choice

    Date now = new Date();

    PollsChoice choice = pollsChoicePersistence.findByPrimaryKey(choiceId);

    if (choice.getQuestionId() != questionId) {
      throw new NoSuchQuestionException();
    }

    // Question

    PollsQuestion question = pollsQuestionPersistence.findByPrimaryKey(questionId);

    if (question.isExpired(serviceContext, now)) {
      throw new QuestionExpiredException();
    }

    question.setLastVoteDate(serviceContext.getCreateDate(now));

    pollsQuestionPersistence.update(question, false);

    // Vote

    PollsVote vote = pollsVotePersistence.fetchByQ_U(questionId, userId);

    if (vote != null) {
      throw new DuplicateVoteException();
    } else {
      User user = userPersistence.findByPrimaryKey(userId);

      long voteId = counterLocalService.increment();

      vote = pollsVotePersistence.create(voteId);

      vote.setCompanyId(user.getCompanyId());
      vote.setUserId(user.getUserId());
      vote.setUserName(user.getFullName());
      vote.setCreateDate(serviceContext.getCreateDate(now));
      vote.setModifiedDate(serviceContext.getModifiedDate(now));
      vote.setQuestionId(questionId);
      vote.setChoiceId(choiceId);
      vote.setVoteDate(serviceContext.getCreateDate(now));

      pollsVotePersistence.update(vote, false);
    }

    return vote;
  }
Exemple #6
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    PollsVote newPollsVote = addPollsVote();

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

    dynamicQuery.add(RestrictionsFactoryUtil.eq("voteId", newPollsVote.getVoteId()));

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

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

    PollsVote existingPollsVote = result.get(0);

    Assert.assertEquals(existingPollsVote, newPollsVote);
  }
Exemple #7
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    PollsVote newPollsVote = addPollsVote();

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

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

    Object newVoteId = newPollsVote.getVoteId();

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

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

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

    Object existingVoteId = result.get(0);

    Assert.assertEquals(existingVoteId, newVoteId);
  }
Exemple #8
0
  protected PollsVote addPollsVote() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    PollsVote pollsVote = _persistence.create(pk);

    pollsVote.setUuid(ServiceTestUtil.randomString());

    pollsVote.setGroupId(ServiceTestUtil.nextLong());

    pollsVote.setCompanyId(ServiceTestUtil.nextLong());

    pollsVote.setUserId(ServiceTestUtil.nextLong());

    pollsVote.setUserName(ServiceTestUtil.randomString());

    pollsVote.setCreateDate(ServiceTestUtil.nextDate());

    pollsVote.setModifiedDate(ServiceTestUtil.nextDate());

    pollsVote.setQuestionId(ServiceTestUtil.nextLong());

    pollsVote.setChoiceId(ServiceTestUtil.nextLong());

    pollsVote.setVoteDate(ServiceTestUtil.nextDate());

    _persistence.update(pollsVote);

    return pollsVote;
  }
Exemple #9
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    PollsVote newPollsVote = _persistence.create(pk);

    newPollsVote.setUuid(ServiceTestUtil.randomString());

    newPollsVote.setGroupId(ServiceTestUtil.nextLong());

    newPollsVote.setCompanyId(ServiceTestUtil.nextLong());

    newPollsVote.setUserId(ServiceTestUtil.nextLong());

    newPollsVote.setUserName(ServiceTestUtil.randomString());

    newPollsVote.setCreateDate(ServiceTestUtil.nextDate());

    newPollsVote.setModifiedDate(ServiceTestUtil.nextDate());

    newPollsVote.setQuestionId(ServiceTestUtil.nextLong());

    newPollsVote.setChoiceId(ServiceTestUtil.nextLong());

    newPollsVote.setVoteDate(ServiceTestUtil.nextDate());

    _persistence.update(newPollsVote);

    PollsVote existingPollsVote = _persistence.findByPrimaryKey(newPollsVote.getPrimaryKey());

    Assert.assertEquals(existingPollsVote.getUuid(), newPollsVote.getUuid());
    Assert.assertEquals(existingPollsVote.getVoteId(), newPollsVote.getVoteId());
    Assert.assertEquals(existingPollsVote.getGroupId(), newPollsVote.getGroupId());
    Assert.assertEquals(existingPollsVote.getCompanyId(), newPollsVote.getCompanyId());
    Assert.assertEquals(existingPollsVote.getUserId(), newPollsVote.getUserId());
    Assert.assertEquals(existingPollsVote.getUserName(), newPollsVote.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingPollsVote.getCreateDate()),
        Time.getShortTimestamp(newPollsVote.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingPollsVote.getModifiedDate()),
        Time.getShortTimestamp(newPollsVote.getModifiedDate()));
    Assert.assertEquals(existingPollsVote.getQuestionId(), newPollsVote.getQuestionId());
    Assert.assertEquals(existingPollsVote.getChoiceId(), newPollsVote.getChoiceId());
    Assert.assertEquals(
        Time.getShortTimestamp(existingPollsVote.getVoteDate()),
        Time.getShortTimestamp(newPollsVote.getVoteDate()));
  }