Package org.jtalks.jcommune.web.dto

Examples of org.jtalks.jcommune.web.dto.PrivateMessageDto


        ModelAndView mav = controller.newPmPage(JC_USER.getId());

        //check result
        verify(pmService).checkPermissionsToSend(JC_USER.getId());
        assertViewName(mav, "pm/pmForm");
        PrivateMessageDto dto = assertAndReturnModelAttributeOfType(mav, "privateMessageDto", PrivateMessageDto.class);
        assertEquals(dto.getRecipient(), JC_USER.getUsername());
    }
View Full Code Here


    @Test
    public void sendMessage() throws NotFoundException {
        when(userService.getByUsername(USERNAME)).thenReturn(JC_USER);
        when(userService.getCurrentUser()).thenReturn(JC_USER);
        PrivateMessageDto dto = getPrivateMessageDto();
        dto.setRecipient(USERNAME);
        BindingResult bindingResult = new BeanPropertyBindingResult(dto, "privateMessageDto");

        ModelAndView mav = controller.sendMessage(dto, bindingResult);

        assertEquals(mav.getViewName(), "redirect:/outbox");
        verify(pmService).sendMessage(dto.getTitle(), dto.getBody(), JC_USER, JC_USER);
    }
View Full Code Here

    @Test
    public void sendDraftMessage() throws NotFoundException {
        when(userService.getByUsername(USERNAME)).thenReturn(JC_USER);
        when(userService.getCurrentUser()).thenReturn(JC_USER);
        PrivateMessageDto dto = getPrivateMessageDto();
        dto.setRecipient(USERNAME);
        dto.setId(4);
        BindingResult bindingResult = new BeanPropertyBindingResult(dto, "privateMessageDto");

        ModelAndView mav = controller.sendMessage(dto, bindingResult);

        assertEquals(mav.getViewName(), "redirect:/outbox");
        verify(pmService).sendDraft(dto.getId(), dto.getTitle(), dto.getBody(), JC_USER, JC_USER);
    }
View Full Code Here

        verify(pmService).sendDraft(dto.getId(), dto.getTitle(), dto.getBody(), JC_USER, JC_USER);
    }

    @Test
    public void sendMessageWithErrors() throws NotFoundException {
        PrivateMessageDto dto = getPrivateMessageDto();
        BeanPropertyBindingResult resultWithErrors = mock(BeanPropertyBindingResult.class);
        when(resultWithErrors.hasErrors()).thenReturn(true);

        ModelAndView mav = controller.sendMessage(dto, resultWithErrors);
View Full Code Here

        assertEquals(mav.getViewName(), "pm/pmForm");
    }

    @Test(expectedExceptions = NotFoundException.class)
    public void sendMessageWithWrongUser() throws NotFoundException {
        PrivateMessageDto dto = getPrivateMessageDto();
        doThrow(new NotFoundException()).when(pmService).
                sendMessage(anyString(), anyString(), any(JCUser.class), any(JCUser.class));
        BindingResult bindingResult = new BeanPropertyBindingResult(dto, "privateMessageDto");

        controller.sendMessage(dto, bindingResult);
View Full Code Here

        //check expectations
        verify(pmService).get(PM_ID);

        //check result
        assertViewName(mav, "pm/pmForm");
        PrivateMessageDto dto = assertAndReturnModelAttributeOfType(mav, "privateMessageDto", PrivateMessageDto.class);
        assertEquals(dto.getId(), PM_ID);
    }
View Full Code Here

    @Test
    public void saveDraft() throws NotFoundException {
        when(userService.getByUsername(USERNAME)).thenReturn(JC_USER);
        when(userService.getCurrentUser()).thenReturn(JC_USER);
        PrivateMessageDto dto = getPrivateMessageDto();
        dto.setRecipient(USERNAME);
        BindingResult bindingResult = new BeanPropertyBindingResult(dto, "privateMessageDto");

        String view = controller.saveDraft(dto, bindingResult);

        assertEquals(view, "redirect:/drafts");
        verify(pmService).saveDraft(dto.getId(), USERNAME, dto.getTitle(), dto.getBody(), JC_USER);
    }
View Full Code Here

        verify(pmService).saveDraft(dto.getId(), USERNAME, dto.getTitle(), dto.getBody(), JC_USER);
    }

    @Test
    public void saveDraftWithWrongUser() throws NotFoundException {
        PrivateMessageDto dto = getPrivateMessageDto();
        doThrow(new NotFoundException()).when(pmService)
                .saveDraft(anyLong(), anyString(), anyString(), anyString(), any(JCUser.class));
        BindingResult bindingResult = new BeanPropertyBindingResult(dto, "privateMessageDto");

        String view = controller.saveDraft(dto, bindingResult);
View Full Code Here

        assertEquals(result, "redirect:/aaa");
    }

    private PrivateMessageDto getPrivateMessageDto() {
        PrivateMessageDto dto = new PrivateMessageDto();
        dto.setBody("body");
        dto.setTitle("title");
        dto.setRecipient(USERNAME);
        return dto;
    }
View Full Code Here

    @RequestMapping(value = "/pm/new", method = RequestMethod.GET)
    public ModelAndView newPmPage(@RequestParam(value = "recipientId", required = false) Long recipientId)
            throws NotFoundException {
        Long senderId = userService.getCurrentUser().getId();
        pmService.checkPermissionsToSend(senderId);
        PrivateMessageDto pmDto = new PrivateMessageDto();
        if (recipientId != null) {
            String name = userService.get(recipientId).getUsername();
            pmDto.setRecipient(name);
        }
        return new ModelAndView(PM_FORM)
                .addObject(DTO, pmDto);
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.web.dto.PrivateMessageDto

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.