use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test72UpdateXUser.
@Test
public void test72UpdateXUser() {
destroySession();
setup();
Collection<String> existingRoleList = new ArrayList<String>();
existingRoleList.add(RangerConstants.ROLE_USER);
Collection<String> reqRoleList = new ArrayList<String>();
reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
Collection<Long> groupIdList = new ArrayList<Long>();
groupIdList.add(userId);
VXUser vxUser = vxUser();
vxUser.setUserRoleList(reqRoleList);
vxUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
vxUser.setGroupIdList(groupIdList);
vxUser.setFirstName("null");
vxUser.setLastName("null");
vxUser.setPassword("*****");
Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
VXPortalUser oldUserProfile = userProfile();
oldUserProfile.setUserSource(RangerCommonEnums.USER_APP);
oldUserProfile.setPassword(vxUser.getPassword());
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setUserRoleList(existingRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(oldUserProfile);
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
Mockito.when(userMgr.updateUserWithPass((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
VXGroupUserList vxGroupUserList = vxGroupUserList();
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
VXUser dbvxUser = xUserMgr.updateXUser(vxUser);
Assert.assertNotNull(dbvxUser);
Assert.assertEquals(dbvxUser.getId(), vxUser.getId());
Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
Mockito.verify(xUserService).updateResource(vxUser);
groupIdList.clear();
groupIdList.add(9L);
vxUser.setGroupIdList(groupIdList);
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Mockito.when(xGroupUserService.getTransactionLog((VXGroupUser) Mockito.any(), Mockito.anyString())).thenReturn(trxLogList);
vxUser.setPassword("TestUser@1234");
oldUserProfile.setPassword(vxUser.getPassword());
vxGroupUserList.setVXGroupUsers(null);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
VXGroup vXGroup = vxGroup();
Mockito.when(xGroupService.readResource(Mockito.anyLong())).thenReturn(vXGroup);
VXGroupUser vXGroupUser = vxGroupUser();
Mockito.when(xGroupUserService.createResource((VXGroupUser) Mockito.any())).thenReturn(vXGroupUser);
dbvxUser = xUserMgr.updateXUser(vxUser);
Assert.assertNotNull(dbvxUser);
Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException("user " + vxUser.getName() + " does not exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
vxUser = xUserMgr.updateXUser(vxUser);
Assert.assertNull(vxUser);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test79checkAccess.
@Test
public void test79checkAccess() {
destroySession();
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
VXPortalUser vXPortalUser = userProfile();
xUserMgr.checkAccess(vXPortalUser.getLoginId());
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test113CreateOrUpdateXUsers.
@Test
public void test113CreateOrUpdateXUsers() {
destroySession();
setup();
VXUser vXUser = vxUser();
vXUser.setFirstName("null");
vXUser.setLastName("null");
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vXUser);
VXUserList users = new VXUserList(vXUserList);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
XXUser xXUser = xxUser(vXUser);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setFirstName("null");
vXPortalUser.setLastName("null");
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
List<XXModuleDef> xXModuleDefs = new ArrayList<XXModuleDef>();
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
Mockito.when(xUserService.updateResource(vXUser)).thenReturn(vXUser);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
xUserMgr.createOrUpdateXUsers(users);
vXUserList.clear();
vXUser.setUserSource(RangerCommonEnums.USER_APP);
vXUser.setFirstName("testuser");
vXUser.setLastName("testuser");
vXUser.setPassword("TestPassword@123");
vXUserList.add(vXUser);
users = new VXUserList(vXUserList);
vXPortalUser = userProfile();
vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
vXPortalUser.setFirstName("testuser");
vXPortalUser.setLastName("testuser");
vXPortalUser.setPassword("TestPassword@123");
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
Mockito.when(userMgr.updateUserWithPass((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
xUserMgr.createOrUpdateXUsers(users);
vXUser.setPassword("*****");
xUserMgr.createOrUpdateXUsers(users);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test132CreateExternalUser.
@Test
public void test132CreateExternalUser() {
destroySession();
setup();
ArrayList<String> roleList = new ArrayList<String>();
roleList.add(RangerConstants.ROLE_USER);
VXPortalUser vXPortalUser = userProfile();
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
VXUser vXUser = vxUser();
VXUser createdXUser = vxUser();
XXUser xXUser = xxUser(vXUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(null, xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
vXPortalUser.setUserRoleList(roleList);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = new XXUserPermission();
xUserPermissionObj.setAddedByUserId(userId);
xUserPermissionObj.setCreateTime(new Date());
xUserPermissionObj.setId(userId);
xUserPermissionObj.setIsAllowed(1);
xUserPermissionObj.setModuleId(1L);
xUserPermissionObj.setUpdatedByUserId(userId);
xUserPermissionObj.setUpdateTime(new Date());
xUserPermissionObj.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj);
createdXUser = xUserMgr.createExternalUser(vXUser.getName());
Assert.assertNotNull(createdXUser);
Assert.assertEquals(createdXUser.getName(), vXUser.getName());
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test52createXGroupUserFromMap.
@Test
public void test52createXGroupUserFromMap() {
setup();
VXGroup vxGroup = vxGroup();
VXUser vxUser = vxUser();
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vxUser);
VXGroupUserInfo vxGUInfo = new VXGroupUserInfo();
vxGUInfo.setXgroupInfo(vxGroup);
vxGUInfo.setXuserInfo(vXUserList);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao userRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXUser xXUser = xxUser(vxUser);
VXPortalUser userProfile = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(userProfile);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
List<XXModuleDef> xXModuleDefs = new ArrayList<XXModuleDef>();
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(xXUser);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(xXPortalUser);
Mockito.when(xGroupService.createXGroupWithOutLogin(vxGroup)).thenReturn(vxGroup);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userRoleDao);
Mockito.when(userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount(xXPortalUser)).thenReturn(userProfile);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
VXGroupUserInfo vxGUInfoObj = xUserMgr.createXGroupUserFromMap(vxGUInfo);
Assert.assertNotNull(vxGUInfoObj);
}
Aggregations