Examples of Poll


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

        assertTrue(mav.getView() instanceof MappingJacksonJsonView);
        assertEquals(mav.getModel().get("errorMessage"), exception.getMessage());
    }

    private Poll createPoll(long pollId, List<Long> pollOptionIds) {
        Poll poll = new Poll("New poll");
        poll.setId(pollId);
        int voteCount = 10;
        for (Long optionId : pollOptionIds) {
            PollItem option = createPollOption("First option", optionId, voteCount);
            poll.addPollOptions(option);
        }
        return poll;
    }
View Full Code Here

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

     * @return data transfer object, that contains data about poll
     */
    @RequestMapping(value = "/poll/{pollId}/single", method = RequestMethod.POST)
    @ResponseBody
    public PollDto addSingleVote(@PathVariable Long pollId, @RequestParam Long pollOptionId) {
        Poll poll = pollService.vote(pollId, Collections.singletonList(pollOptionId));
        return new PollDto(poll);
    }
View Full Code Here

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

     * @return data transfer object, that contains data about poll
     */
    @RequestMapping(value = "/poll/{pollId}/multiple", method = RequestMethod.POST)
    @ResponseBody
    public PollDto addMultipleVote(@PathVariable Long pollId, @RequestBody PollDto pollDto) {
        Poll poll = pollService.vote(pollId, pollDto.getPollOptionIds());
        return new PollDto(poll);
    }
View Full Code Here

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

   
    @Test
    public void testEmptyTitleAndEmptyItemsValid() {
        String title = StringUtils.EMPTY;
        List<PollItem> items = Collections.emptyList();
        Poll poll = new Poll(title);
        poll.setPollItems(items);
       
        boolean isValid = validator.isValid(poll, validatorContext);
       
        Assert.assertTrue(isValid, "Poll with empty title and empty items must be valid");
    }
View Full Code Here

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

   
    @Test
    public void testFilledTitleAndFilledItemsValid() {
        String title = "larks! Stands and deliver.";
        List<PollItem> items = Arrays.asList(new PollItem("larks"));
        Poll poll = new Poll(title);
        poll.setPollItems(items);
       
        boolean isValid = validator.isValid(poll, validatorContext);
       
        Assert.assertTrue(isValid, "Poll with filled title and filled items must be valid");
    }
View Full Code Here

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

   
    @Test
    public void testFilledTitleAndEmptyItemsInvalid() {
        String title = "title";
        List<PollItem> items = Collections.emptyList();
        Poll poll = new Poll(title);
        poll.setPollItems(items);
        String defaultErrorMessage = "message";
        Mockito.when(validatorContext.getDefaultConstraintMessageTemplate()).thenReturn(defaultErrorMessage);
        Mockito.when(validatorContext.buildConstraintViolationWithTemplate(defaultErrorMessage))
            .thenReturn(constraintViolationBuilder);
        Mockito.when(constraintViolationBuilder.addNode(Mockito.anyString()))
View Full Code Here

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

   
    @Test
    public void testEmptyTitleAndEmptyItemsValid() {
        String title = StringUtils.EMPTY;
        List<PollItem> items = Collections.emptyList();
        Poll poll = new Poll(title);
        poll.setPollItems(items);
       
        boolean isValid = validator.isValid(poll, validatorContext);
       
        Assert.assertTrue(isValid, "Poll with empty title and empty items must be valid");
    }
View Full Code Here

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

   
    @Test
    public void testFilledTitleAndFilledItemsValid() {
        String title = "larks! Stands and deliver.";
        List<PollItem> items = Arrays.asList(new PollItem("larks"));
        Poll poll = new Poll(title);
        poll.setPollItems(items);
       
        boolean isValid = validator.isValid(poll, validatorContext);
       
        Assert.assertTrue(isValid, "Poll with filled title and filled items must be valid");
    }
View Full Code Here

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

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

    }

    @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
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.