use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test45getUserRolesByName.
@Test
public void test45getUserRolesByName() {
destroySession();
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
userProfile.setUserRoleList(userRoleList);
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = vxGroupPermission();
groupPermList.add(groupPermission);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(userProfile.getLoginId())).thenReturn(userProfile);
VXStringList vXStringList = xUserMgr.getUserRolesByName(userProfile.getLoginId());
Assert.assertNotNull(vXStringList);
Mockito.when(restErrorUtil.createRESTException("Please provide a valid userName", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.getUserRolesByName("");
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test37setUserRolesByExternalID.
@Test
public void test37setUserRolesByExternalID() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXUser vXUser = vxUser();
VXPortalUser userProfile = userProfile();
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = vxGroupPermission();
groupPermList.add(groupPermission);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
VXStringList vXStringList = xUserMgr.setUserRolesByExternalID(userId, vStringRolesList);
Assert.assertNotNull(vXStringList);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test43getUserRolesByExternalID.
@Test
public void test43getUserRolesByExternalID() {
destroySession();
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXUser vXUser = vxUser();
VXPortalUser userProfile = userProfile();
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = vxGroupPermission();
groupPermList.add(groupPermission);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
VXStringList vXStringList = xUserMgr.getUserRolesByExternalID(userId);
Assert.assertNotNull(vXStringList);
Mockito.when(restErrorUtil.createRESTException("User ID doesn't exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
Mockito.when(userMgr.getUserProfileByLoginId((String) Mockito.anyString())).thenReturn(null);
xUserMgr.getUserRolesByExternalID(userId);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test54modifyUserActiveStatus.
@Test
public void test54modifyUserActiveStatus() {
setup();
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
VXPortalUser userProfile = userProfile();
VXUser vxUser = vxUser();
XXUser xXUser = xxUser(vxUser);
XXPortalUser xXPortalUser = xxPortalUser(userProfile);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.getById(xXUser.getId())).thenReturn(xXUser);
Mockito.when(userMgr.updateUser(userProfile)).thenReturn(xXPortalUser);
HashMap<Long, Integer> statusMap = new HashMap<Long, Integer>();
statusMap.put(xXUser.getId(), 1);
Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(userProfile);
xUserMgr.modifyUserActiveStatus(statusMap);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserREST method test13GetUserProfile.
@Test
public void test13GetUserProfile() {
HttpSession hs = Mockito.mock(HttpSession.class);
VXPortalUser vxPUserExp = CreateVXPortalUser();
Mockito.when(userManager.getUserProfileByLoginId()).thenReturn(vxPUserExp);
Mockito.when(request.getSession()).thenReturn(hs);
Mockito.when(hs.getId()).thenReturn("id");
VXPortalUser vxPUserAct = userREST.getUserProfile(request);
Assert.assertNotNull(vxPUserAct);
Assert.assertEquals(vxPUserExp, vxPUserAct);
Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
Mockito.verify(userManager).getUserProfileByLoginId();
}
Aggregations