Package org.jtalks.common.model.permissions

Examples of org.jtalks.common.model.permissions.BranchPermission


    @Test
    public void getGroupsForBranchPermissionShouldReturnFailIfBranchWasNotFound() throws Exception {
        Component component = setupComponentMock();

        BranchPermission targetPermission = BranchPermission.CREATE_POSTS;
        BranchPermissionDto dto = createBranchPermissionDto(targetPermission);
        when(permissionManager.findBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);
        when(branchService.getPermissionGroupsFor(component.getId(), dto.getBranchId(), dto.isAllowed(), targetPermission))
                .thenThrow(new NotFoundException());

        JsonResponse jsonResponse = administrationController.getGroupsForBranchPermission(dto);
View Full Code Here


    @Test
    public void getGroupsForBranchPermissionShouldReturnSuccessIfBranchExistsAndPermissionHasNoGroups()
            throws Exception {
        Component component = setupComponentMock();

        BranchPermission targetPermission = BranchPermission.CREATE_POSTS;
        BranchPermissionDto dto = createBranchPermissionDto(targetPermission);
        when(branchService.getPermissionGroupsFor(component.getId(), dto.getBranchId(), dto.isAllowed(), targetPermission))
                .thenReturn(Collections.EMPTY_LIST);
        when(permissionManager.findBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);
        when(permissionManager.getAllGroupsWithoutExcluded(anyList(), eq(targetPermission))).thenReturn(Collections.EMPTY_LIST);


        JsonResponse jsonResponse = administrationController.getGroupsForBranchPermission(dto);
View Full Code Here

    @Test
    public void getGroupsForBranchPermissionShouldReturnSuccessIfBranchExists() throws Exception {
        Component component = setupComponentMock();

        BranchPermission targetPermission = BranchPermission.CREATE_POSTS;
        BranchPermissionDto dto = createBranchPermissionDto(targetPermission);

        List<Group> selectedGroupList = Arrays.asList(new Group("1"), new Group("2"), new Group("3"));
        when(branchService.getPermissionGroupsFor(component.getId(), dto.getBranchId(), dto.isAllowed(), targetPermission))
                .thenReturn(selectedGroupList);

        List<Group> allGroupList = Arrays.asList(new Group("4"), new Group("5"), new Group("6"));
        when(permissionManager.getAllGroupsWithoutExcluded(selectedGroupList, targetPermission)).thenReturn(allGroupList);
        when(permissionManager.findBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);

        JsonResponse jsonResponse = administrationController.getGroupsForBranchPermission(dto);

        assertEquals(jsonResponse.getStatus(), JsonResponseStatus.SUCCESS);
        assertTrue(jsonResponse.getResult() instanceof PermissionGroupsDto);
View Full Code Here

    @Test
    public void editBranchPermissionsShouldReturnSuccessIfBranchExist() throws Exception {
        Component component = setupComponentMock();

        BranchPermission targetPermission = BranchPermission.CREATE_POSTS;
        BranchPermissionDto dto = createBranchPermissionDto(targetPermission);

        dto.setNewlyAddedGroupIds(Arrays.asList(1L, 2L));
        dto.setRemovedGroupIds(Arrays.asList(1L, 2L));
        when(permissionManager.findBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);

        JsonResponse response = administrationController.editBranchPermissions(dto);

        assertEquals(response.getStatus(), JsonResponseStatus.SUCCESS);
        verify(branchService).changeBranchPermissions(anyLong(),
View Full Code Here

    @Test
    public void editBranchPermissionsShouldReturnFailIfBranchNotFound() throws Exception {
        Component component = setupComponentMock();

        BranchPermission targetPermission = BranchPermission.CREATE_POSTS;
        BranchPermissionDto dto = createBranchPermissionDto(targetPermission);

        dto.setNewlyAddedGroupIds(Arrays.asList(1L, 2L));
        dto.setRemovedGroupIds(Arrays.asList(1L, 2L));

        when(permissionManager.findBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);
        doThrow(new NotFoundException()).when(branchService).changeBranchPermissions(anyLong(),
                eq(dto.getBranchId()), eq(dto.isAllowed()), any(PermissionChanges.class));

        JsonResponse response = administrationController.editBranchPermissions(dto);
View Full Code Here

    }

    @Test
    public void getPermissionGroupsShouldReturnAllowedPermissionGroupsWhenBranchExist() throws Exception {
        long branchId = 42;
        BranchPermission permission = BranchPermission.CLOSE_TOPICS;
        GroupsPermissions expectedPermissions = new GroupsPermissions();
        expectedPermissions.addAllowed(permission, new Group("1"));

        Branch expectedBranch = new Branch("name", "description");
        when(branchDao.isExist(branchId)).thenReturn(true);
View Full Code Here

    }

    @Test
    public void getPermissionGroupsShouldReturnRestrictedPermissionGroupsWhenBranchExist() throws Exception {
        long branchId = 42;
        BranchPermission permission = BranchPermission.CLOSE_TOPICS;
        GroupsPermissions expectedPermissions = new GroupsPermissions();
        expectedPermissions.addRestricted(permission, new Group("1"));

        Branch expectedBranch = new Branch("name", "description");
        when(branchDao.isExist(branchId)).thenReturn(true);
View Full Code Here

TOP

Related Classes of org.jtalks.common.model.permissions.BranchPermission

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.