Package org.jtalks.jcommune.model.entity

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


    }

    @Test
    public void testAddSingleVote() {
        long pollOptionId = 1;
        Poll poll = createPoll(POLL_ID, Arrays.asList(pollOptionId));

        Mockito.when(pollService.vote(POLL_ID, Arrays.asList(pollOptionId))).thenReturn(poll);

        PollDto pollDto = pollController.addSingleVote(POLL_ID, pollOptionId);
        PollOptionDto optionDto = pollDto.getPollOptions().get(0);

        Assert.assertEquals(pollDto.getId(), poll.getId(), "The id must be the same.");
        Assert.assertEquals(optionDto.getId(), pollOptionId, "The id must be the same");
    }
View Full Code Here


    @Test
    public void testAddMultipleVote() {
        long firstOptionId = 1;
        long secondOptionId = 2;
        List<Long> optionIds = Arrays.asList(firstOptionId, secondOptionId);
        Poll poll = createPoll(POLL_ID, optionIds);
        PollDto pollDto = new PollDto(poll);

        Mockito.when(pollService.vote(POLL_ID, optionIds)).thenReturn(poll);

        PollDto resultPollDto = pollController.addMultipleVote(POLL_ID, pollDto);

        Assert.assertEquals(resultPollDto.getId(), poll.getId(), "The id must be the same.");
        PollOptionDto firstOptionDto = resultPollDto.getPollOptions().get(0);
        Assert.assertEquals(firstOptionDto.getId(), firstOptionId,
                "The id must be the same");
        PollOptionDto secondOptionDto = resultPollDto.getPollOptions().get(1);
        Assert.assertEquals(secondOptionDto.getId(), secondOptionId,
View Full Code Here

        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

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

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

   
    @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

   
    @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

   
    @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

   
    @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

   
    @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

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.