Package org.jtalks.jcommune.model.entity

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


   
    @Test
    public void testBlankTitleAndFilledItemsInvalid() {
        String title = " ";
        List<PollItem> items = Arrays.asList(new PollItem("name"));
        Poll poll = new Poll(title);
        poll.setPollItems(items);
        String defaultErrorMessage = "message";
        Mockito.when(validatorContext.getDefaultConstraintMessageTemplate())
            .thenReturn(defaultErrorMessage);
        Mockito.when(validatorContext.buildConstraintViolationWithTemplate(defaultErrorMessage))
            .thenReturn(constraintViolationBuilder);
View Full Code Here


    }

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

        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 + 1,
                "Count of votes should be increased.");
    }
View Full Code Here

    @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

    }

    @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

    @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

    @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

        }
    }

    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

     * {@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

    /*===== 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

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

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

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

TOP

Related Classes of org.jtalks.jcommune.model.entity.Poll

Copyright © 2018 www.massapicom. 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.