001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kim.test.service;
017    
018    import org.junit.Test;
019    import org.kuali.rice.kim.api.common.assignee.Assignee;
020    import org.kuali.rice.kim.api.permission.PermissionService;
021    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
022    import org.kuali.rice.kim.impl.common.template.TemplateBo;
023    import org.kuali.rice.kim.impl.permission.PermissionBo;
024    import org.kuali.rice.kim.test.KIMTestCase;
025    import org.kuali.rice.test.BaselineTestCase;
026    
027    import java.util.Collections;
028    import java.util.HashMap;
029    import java.util.List;
030    
031    import static org.junit.Assert.*;
032    
033    /**
034     * Test the PermissionService
035     * 
036     * @author Kuali Rice Team (rice.collab@kuali.org)
037     *
038     */
039    @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
040    public class PermissionServiceTest extends KIMTestCase {
041    
042            private PermissionService permissionService;
043    
044            @Override
045            public void setUp() throws Exception {
046                    super.setUp();
047                    setPermissionService(KimApiServiceLocator.getPermissionService());
048            }
049    
050            @Test
051            public void testHasPermission() {
052                    assertTrue(getPermissionService().hasPermission("entity123pId", "KR-NS", "perm1", new HashMap<String, String>()));
053                    assertTrue(getPermissionService().hasPermission("entity123pId", "KR-NS", "perm2", new HashMap<String, String>()));
054                    assertFalse(getPermissionService().hasPermission("entity124pId", "KR-NS", "perm2", new HashMap<String, String>()));
055            }
056            
057            @Test
058            public void testIsAuthorized() {
059                    assertTrue(getPermissionService().isAuthorized("entity123pId", "KR-NS", "perm1", new HashMap<String, String>(), new HashMap<String, String>()));
060                    assertTrue(getPermissionService().isAuthorized("entity123pId", "KR-NS", "perm2", new HashMap<String, String>(), new HashMap<String, String>()));
061                    assertFalse(getPermissionService().isAuthorized("entity124pId", "KR-NS", "perm2", new HashMap<String, String>(), new HashMap<String, String>()));
062            }
063            
064            @Test
065            public void testHasPermissionByTemplateName() {
066                    assertTrue(getPermissionService().hasPermissionByTemplateName("entity123pId", "KUALI", "Default", new HashMap<String, String>()));
067                    // TODO - getting a SOAPFaultException on this call; fix and un-comment
068                    // assertFalse(getPermissionService().hasPermissionByTemplateName("entity124pId", "KUALI", "Default", new Map<String, String>()));
069            }
070            
071            @Test
072            public void testIsAuthorizedByTemplateName() {
073                    // assertTrue(getPermissionService().isAuthorizedByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification)("entity123pId", "KR-NS", "1", new Map<String, String>()));
074            }
075            
076            @Test
077            public void testGetPermissionAssignees() {
078                    
079                    List<Assignee> assignees = getPermissionService().getPermissionAssignees("KUALI", "Log In Kuali Portal", Collections
080                    .<String, String>emptyMap(), Collections.<String, String>emptyMap());
081                    assertNotNull(assignees);
082                    assertEquals(1, assignees.size());
083                    Assignee permInfo = assignees.get(0);
084                    assertEquals("entity123pId", permInfo.getPrincipalId());
085                    assignees = getPermissionService().getPermissionAssignees("KUALI", "Not A Valid Permission Name", Collections.<String, String>emptyMap(), Collections.<String, String>emptyMap());
086                    // TODO - jax-ws remoted service returns null; local return empty List. Fix webservice return
087                    assertTrue(null == assignees || assignees.size() == 0);
088            }
089            
090            @Test
091            public void testGetPermissionAssigneesForTemplateName() {
092                    /*
093                    List<PermissionAssigneeInfo> assignees = getPermissionService().getPermissionAssignees("KUALI", "Log In", null, null);
094                    assertNotNull(assignees);
095                    assertEquals(1, assignees.size());
096                    PermissionAssigneeInfo permInfo = assignees.get(0);
097                    assertEquals("entity123pId", permInfo.getPrincipalId());
098                    assignees = getPermissionService().getPermissionAssignees("KUALI", "Not A Valid Permission Name", null, null);
099                    assertNull(assignees);
100                    */
101            }
102            
103            @Test
104            public void testIsPermissionDefined() {
105            }
106            
107            @Test
108            public void testIsPermissionDefinedForTemplateName() {
109            }
110            
111            @Test
112            public void testGetAuthorizedPermissions() {
113            }
114            
115            @Test
116            public void testGetAuthorizedPermissionsByTemplateName() {
117            }
118            
119            @Test
120            public void testGetPermission() {
121                    PermissionBo permissionBo = PermissionBo.from(getPermissionService().getPermission("p1"));
122    
123                    assertNotNull(permissionBo);
124                    assertEquals("perm1", permissionBo.getName());
125                    assertEquals("KR-NS", permissionBo.getNamespaceCode());
126                    assertEquals(0, permissionBo.getDetails().size());
127                    assertTrue(permissionBo.isActive());
128                    
129                    TemplateBo templateBo = permissionBo.getTemplate();
130                    assertNotNull(templateBo);
131                    assertTrue(templateBo.isActive());
132                    assertEquals("1", templateBo.getKimTypeId());
133                    assertEquals("Default", templateBo.getName());
134                    assertEquals("KUALI", templateBo.getNamespaceCode());
135                    
136                    permissionBo = PermissionBo.from(getPermissionService().getPermission("p0"));
137                    assertNull(permissionBo);
138            }
139            
140            @Test
141            public void testGetPermissionsByTemplateName() {
142            }
143            
144            @Test
145            public void testGetPermissionsByName() {
146            }
147            
148            @Test
149            public void testLookupPermissions() {
150            }
151            
152            @Test
153            public void testGetRoleIdsForPermission() {
154            }
155            
156            @Test
157            public void testGetRoleIdsForPermissions() {
158            }
159            
160            @Test
161            public void testGetPermissionDetailLabel() {
162            }
163    
164            public PermissionService getPermissionService() {
165                    return this.permissionService;
166            }
167    
168            public void setPermissionService(PermissionService permissionService) {
169                    this.permissionService = permissionService;
170            }
171    
172    }