Examples of Poll


Examples of org.jtalks.jcommune.model.entity.Poll

    @Test
    public void testAddSingleVoteInInactivePoll() {
        List<Long> pollOptionIds = Arrays.asList(1L);
        DateTime endingDate = new DateTime(1999, 1, 1, 1, 1, 1, 1);
        Poll poll = createPollWithOptions(POLL_ID, pollOptionIds, VOTES_COUNT, endingDate);

        Mockito.when(pollDao.get(POLL_ID)).thenReturn(poll);

        Poll resultPoll = pollService.vote(POLL_ID, pollOptionIds);
        PollItem resultPollOption = resultPoll.getPollItems().get(0);

        Assert.assertEquals(resultPollOption.getVotesCount(), VOTES_COUNT,
                "Count of votes should be the same.");
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

    }

    @Test
    public void testAddMultipleVotes() {
        List<Long> pollOptionIds = Arrays.asList(1L, 5L, 9L);
        Poll poll = createPollWithOptions(POLL_ID, pollOptionIds, VOTES_COUNT, null);

        Mockito.when(pollDao.get(Mockito.anyLong())).thenReturn(poll);

        Poll resultPoll = pollService.vote(POLL_ID, pollOptionIds);

        for (PollItem option : resultPoll.getPollItems()) {
            Assert.assertEquals(option.getVotesCount(), VOTES_COUNT + 1,
                    "Count of votes should be increased.");
        }
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

    @Test
    public void testAddMultipleVotesInInactivePoll() {
        List<Long> pollOptionIds = Arrays.asList(1L, 5L, 9L);
        DateTime endingDate = new DateTime(1999, 1, 1, 1, 1, 1, 1);
        Poll poll = createPollWithOptions(POLL_ID, pollOptionIds, VOTES_COUNT, endingDate);

        Mockito.when(pollDao.get(Mockito.anyLong())).thenReturn(poll);

        Poll resultPoll = pollService.vote(POLL_ID, pollOptionIds);

        for (PollItem option : resultPoll.getPollItems()) {
            Assert.assertEquals(option.getVotesCount(), VOTES_COUNT,
                    "Count of votes should be the same.");
        }
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

    @Test
    public void testAddIncorrectVotes() {
        List<Long> pollOptionIds = Arrays.asList(1L, 5L, 9L);
        List<Long> incorrectPollOptionIds = Arrays.asList(11L, 13L);
        DateTime endingDate = new DateTime(1999, 1, 1, 1, 1, 1, 1);
        Poll poll = createPollWithOptions(POLL_ID, pollOptionIds, VOTES_COUNT, endingDate);

        Mockito.when(pollDao.get(Mockito.anyLong())).thenReturn(poll);

        Poll resultPoll = pollService.vote(POLL_ID, incorrectPollOptionIds);

        for (PollItem option : resultPoll.getPollItems()) {
            Assert.assertEquals(option.getVotesCount(), VOTES_COUNT,
                    "Count of votes should be the same.");
        }
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

        }
    }

    private Poll createPollWithOptions(Long pollId, List<Long> pollOptionIds,
                                       int initialVoteCount, DateTime endingDate) {
        Poll poll = new Poll("Poll");
        poll.setEndingDate(endingDate);
        poll.setId(pollId);
        for (Long id : pollOptionIds) {
            PollItem option = new PollItem("Option:" + String.valueOf(id));
            option.setId(id);
            option.setVotesCount(initialVoteCount);
            poll.addPollOptions(option);
        }
        return poll;
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

     * {@inheritDoc}
     */
    @Override
    @PreAuthorize("hasPermission(#pollId, 'POLL', 'GeneralPermission.WRITE')")
    public Poll vote(Long pollId, List<Long> selectedOptionsIds) {
        Poll poll = getDao().get(pollId);
        if (poll.isActive()) {
            prohibitRevote(poll);
            for (PollItem option : poll.getPollItems()) {
                if (selectedOptionsIds.contains(option.getId())) {
                    option.increaseVotesCount();
                    pollOptionDao.saveOrUpdate(option);
                }
            }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

    /*===== Common methods =====*/

    @Test
    public void testGet() {
        Poll expectedPoll = PersistedObjectsFactory.createDefaultVoting();
        session.save(expectedPoll);

        Poll resultPoll = pollDao.get(expectedPoll.getId());

        Assert.assertNotNull(resultPoll);
        Assert.assertEquals(resultPoll.getId(), expectedPoll.getId());
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

        Assert.assertEquals(resultPoll.getId(), expectedPoll.getId());
    }

    @Test
    public void testGetInvalidId() {
        Poll poll = pollDao.get(-111111L);

        Assert.assertNull(poll);
    }
View Full Code Here

Examples of org.jtalks.jcommune.model.entity.Poll

    }

    @Test
    public void testUpdate() {
        String newTitle = "Changed title";
        Poll poll = PersistedObjectsFactory.createDefaultVoting();
        session.save(poll);

        poll.setTitle(newTitle);
        pollDao.saveOrUpdate(poll);
        session.flush();
        session.evict(poll);

        Poll changedPoll = (Poll) session.get(Poll.class, poll.getId());

        Assert.assertNotNull(changedPoll);
        Assert.assertEquals(newTitle, changedPoll.getTitle());
    }
View Full Code Here

Examples of ru.org.linux.poll.Poll

    if (!preparedTopic.getTags().isEmpty()) {
      form.setTags(TagRef.names(preparedTopic.getTags()));
    }

    if (preparedTopic.getSection().isPollPostAllowed()) {
      Poll poll = pollDao.getPollByTopicId(message.getId());

      form.setPoll(PollVariant.toMap(poll.getVariants()));

      form.setMultiselect(poll.isMultiSelect());
    }

    return new ModelAndView("edit", params);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.