Package org.jtalks.jcommune.web.dto.json

Examples of org.jtalks.jcommune.web.dto.json.JsonResponse


    @Test
    public void testAjaxLoginFailure() throws Exception {
        when(userService.loginUser(any(LoginUserDto.class),any(HttpServletRequest.class),
                any(HttpServletResponse.class))).thenReturn(false);
        JsonResponse response = userController.loginAjax(null, null, "on", request, null);
        assertEquals(response.getStatus(), JsonResponseStatus.FAIL);
        verify(userService).loginUser(any(LoginUserDto.class), any(HttpServletRequest.class), any(HttpServletResponse.class));
    }
View Full Code Here


    @Test
    public void testLoginAjaxUserShouldFailIfConnectionErrorOccurred() throws Exception {
        when(userService.loginUser(any(LoginUserDto.class), any(HttpServletRequest.class), any(HttpServletResponse.class)))
                .thenThrow(new NoConnectionException());
       
        JsonResponse response = userController.loginAjax(null, null, "on", request, null);
        assertEquals(response.getStatus(), JsonResponseStatus.FAIL);
        verify(userService).loginUser(any(LoginUserDto.class), any(HttpServletRequest.class), any(HttpServletResponse.class));
    }
View Full Code Here

    @Test
    public void testLoginAjaxUserShouldFailIfUnexpectedErrorOccurred() throws Exception {
        when(userService.loginUser(any(LoginUserDto.class), any(HttpServletRequest.class), any(HttpServletResponse.class)))
                .thenThrow(new UnexpectedErrorException());
       
        JsonResponse response = userController.loginAjax(null, null, "on", request, null);
        assertEquals(response.getStatus(), JsonResponseStatus.FAIL);
        verify(userService).loginUser(any(LoginUserDto.class), any(HttpServletRequest.class), any(HttpServletResponse.class));
    }
View Full Code Here

    public void testGetUsernameListSuccess() {
        String pattern = "us";
        List<String> usernames = Lists.newArrayList("User1", "User2", "User3");
        when(userService.getUsernames(pattern)).thenReturn(usernames);

        JsonResponse response = userController.usernameList(pattern);
        assertEquals(response.getStatus(), JsonResponseStatus.SUCCESS);
    }
View Full Code Here

        Component component = new Component();
        component.setId(componentId);
        when(componentService.getComponentOfForum()).thenReturn(component);
        PluginActivatingDto pluginActivatingDto = new PluginActivatingDto("Dummy plugin", true);
       
        String expectedStatus = new JsonResponse(JsonResponseStatus.SUCCESS).getStatus().name();
       
        String actualStatus = pluginController.activatePlugin(pluginActivatingDto).getStatus().name();
       
        assertEquals(actualStatus, expectedStatus);
    }
View Full Code Here

    @RequestMapping(value = "/activate", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse activatePlugin(@RequestBody PluginActivatingDto pluginActivatingDto) throws NotFoundException {
        long componentId = getForumComponentId();
        pluginService.updatePluginActivating(pluginActivatingDto, componentId);
        return new JsonResponse(JsonResponseStatus.SUCCESS);
    }
View Full Code Here

    public JsonResponse hasPermission(
            @RequestParam("targetId") long targetId,
            @RequestParam("targetType") String targetType,
            @RequestParam("permission") String permission) {
        if (permissionService.hasPermission(targetId, targetType, permission)) {
            return new JsonResponse(JsonResponseStatus.SUCCESS);
        } else {
            return new JsonResponse(JsonResponseStatus.FAIL);
        }
    }
View Full Code Here

    @RequestMapping(value = "/admin/edit", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse setForumInformation(@Valid @RequestBody ComponentInformation componentInformation,
                                            BindingResult result, Locale locale) {
        if (result.hasErrors()) {
            return new JsonResponse(JsonResponseStatus.FAIL, result.getAllErrors());
        }

        componentInformation.setId(componentService.getComponentOfForum().getId());

        try {
            componentService.setComponentInformation(componentInformation);
        } catch (AccessDeniedException e) {
            String errorMessage = messageSource.getMessage(ACCESS_DENIED_MESSAGE, null, locale);
            return new JsonResponse(JsonResponseStatus.FAIL, errorMessage);
        }

        return new JsonResponse(JsonResponseStatus.SUCCESS, null);
    }
View Full Code Here

    @RequestMapping(value = "/branch/edit", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse setBranchInformation(@Valid @RequestBody BranchDto branchDto,
                                            BindingResult result, Locale locale) throws NotFoundException {
        if (result.hasErrors()) {
            return new JsonResponse(JsonResponseStatus.FAIL, result.getAllErrors());
        }

        long forumId = componentService.getComponentOfForum().getId();

        try {
            branchService.changeBranchInfo(forumId, branchDto.getId(), branchDto.getName(), branchDto.getDescription());
        } catch (AccessDeniedException e) {
            String errorMessage = messageSource.getMessage(ACCESS_DENIED_MESSAGE, null, locale);
            return new JsonResponse(JsonResponseStatus.FAIL, errorMessage);
        }

        return new JsonResponse(JsonResponseStatus.SUCCESS, null);
    }
View Full Code Here

    @RequestMapping(value = "/branch/new", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse createNewBranch(@Valid @RequestBody BranchDto branchDto,
                                            BindingResult result, Locale locale) throws NotFoundException {
        if (result.hasErrors()) {
            return new JsonResponse(JsonResponseStatus.FAIL, result.getAllErrors());
        }

        long forumId = componentService.getComponentOfForum().getId();

        try {
            branchService.createNewBranch(forumId, branchDto.getSectionId(), branchDto.getName(), branchDto.getDescription());
        } catch (AccessDeniedException e) {
            String errorMessage = messageSource.getMessage(ACCESS_DENIED_MESSAGE, null, locale);
            return new JsonResponse(JsonResponseStatus.FAIL, errorMessage);
        }

        return new JsonResponse(JsonResponseStatus.SUCCESS, null);
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.web.dto.json.JsonResponse

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.