use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testGetRoles.
@Test
public void testGetRoles() throws Exception {
List<IPentahoRole> roleList = new ArrayList<>();
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getRoles()).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
IPentahoRole role = mock(IPentahoRole.class);
when(role.getName()).thenReturn("testRole");
roleList.add(role);
RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
assertEquals(wrapRoleList.getRoles(), userRoleService.getRoles().getRoles());
}
use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.
the class UserRoleListServiceTest method testDoGetRoles.
@Test
public void testDoGetRoles() {
List<String> roles = new ArrayList<String>();
roles.add("ROLE1");
roles.add("ROLE2");
IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
doReturn(roles).when(userRoleListService1).getAllRoles();
RoleListWrapper roleListWrapper = userRoleListService.getRoles();
verify(userRoleListService).getUserRoleListService();
verify(userRoleListService1).getAllRoles();
assertEquals(roles, roleListWrapper.getRoles());
}
use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.
the class UserRoleListServiceTest method testGetPermissionRoles.
@Test
public void testGetPermissionRoles() {
List<String> roles = new ArrayList<String>();
roles.add("ROLE1");
roles.add("ROLE2");
roles.add("ADMIN_ROLE");
IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
doReturn(roles).when(userRoleListService1).getAllRoles();
ArrayList<String> extraRoles = new ArrayList<String>();
extraRoles.add("EXTRA_ROLE1");
extraRoles.add("EXTRA_ROLE2");
userRoleListService.setExtraRoles(extraRoles);
RoleListWrapper roleWrapper = userRoleListService.getPermissionRoles("ADMIN_ROLE");
assertTrue(!roleWrapper.getRoles().contains("ADMIN_ROLE"));
assertTrue(roleWrapper.getRoles().size() == 4);
}
use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.
the class UserRoleListService method getPermissionRoles.
public RoleListWrapper getPermissionRoles(String adminRole) {
IUserRoleListService userRoleListService = getUserRoleListService();
List<String> allRoles = userRoleListService.getAllRoles();
// We will not allow user to update permission for Administrator
if (allRoles.contains(adminRole)) {
allRoles.remove(adminRole);
}
// Add extra roles to the list of roles
if (extraRoles != null) {
for (String extraRole : extraRoles) {
if (!allRoles.contains(extraRole)) {
allRoles.add(extraRole);
}
}
}
if (null != roleComparator) {
Collections.sort(allRoles, roleComparator);
}
return new RoleListWrapper(allRoles);
}
use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testGetRolesForUser.
@Test
public void testGetRolesForUser() throws Exception {
List<IPentahoRole> roleList = new ArrayList<>();
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
IPentahoSession session = mock(IPentahoSession.class);
String tenantPath = "testPath";
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
PentahoSessionHolder.setSession(session);
setupMockSessionUser(SESSION_USER_NAME, true);
assertEquals(wrapRoleList.getRoles(), userRoleService.getRolesForUser("admin").getRoles());
}
Aggregations