use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test05UpdateXUser.
@Test
public void test05UpdateXUser() {
setup();
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
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("user12");
vxUser.setLastName("test12");
Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setUserRoleList(existingRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(vXPortalUser);
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);
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.getAll()).thenReturn(xXModuleDefs);
XXUser xXUser = xxUser(vxUser);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
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);
VXUserPermission vXUserPermission = vxUserPermission();
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vXUserPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
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);
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);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestRoleBasedUserSearchUtil method TestValidateUserAndFetchUserList.
@Test
public void TestValidateUserAndFetchUserList() {
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
String currentEncryptedPassword = "testpassword";
XXPortalUser xxPortalUser = new XXPortalUser();
xxPortalUser.setId(1L);
xxPortalUser.setLoginId("testUser");
xxPortalUser.setPassword("testpassword");
xxPortalUser.setFirstName("testUser");
VXUser vxUser = new VXUser();
vxUser.setId(1L);
VXUserList vXUserList = new VXUserList();
List<VXUser> vXUsers = new ArrayList<VXUser>();
vXUsers.add(vxUser);
vXUserList.setVXUsers(vXUsers);
List<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_SYS_ADMIN");
List<XXPortalUser> listXXPortalUser = new ArrayList<XXPortalUser>();
listXXPortalUser.add(xxPortalUser);
vxUser.setUserRoleList(userRoleList);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoMgr.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(Mockito.anyString())).thenReturn(xxPortalUser);
Mockito.when(xUserService.getXUserByUserName(xxPortalUser.getLoginId())).thenReturn(vxUser);
Mockito.when(daoMgr.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(xXModuleDefDao.findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(permissionList);
Mockito.when(userMgr.encrypt(Mockito.anyString(), Mockito.anyString())).thenReturn(currentEncryptedPassword);
Mockito.when(xXPortalUserDao.findByRole(Mockito.anyString())).thenReturn(listXXPortalUser);
roleBasedUserSearchUtil.validateUserAndFetchUserList();
Mockito.verify(xXPortalUserDao).findByLoginId(Mockito.anyString());
Mockito.verify(xUserService).getXUserByUserName(xxPortalUser.getLoginId());
Mockito.verify(xXModuleDefDao).findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong());
Mockito.verify(userMgr).encrypt(Mockito.anyString(), Mockito.anyString());
Mockito.verify(xXPortalUserDao, Mockito.atLeast(2)).findByRole(Mockito.anyString());
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestUserMgr method test06ChangeEmailAddressAsAdmin.
@Test
public void test06ChangeEmailAddressAsAdmin() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptedPwd);
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
VXPasswordChange changeEmail = new VXPasswordChange();
changeEmail.setEmailAddress("testuser@test.com");
changeEmail.setId(user.getId());
changeEmail.setLoginId(user.getLoginId());
changeEmail.setOldPassword(userProfile.getPassword());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
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);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(userDao.update(user)).thenReturn(user);
Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(userId, dbVXPortalUser.getId());
Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(changeEmail.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(changeEmail.getEmailAddress(), dbVXPortalUser.getEmailAddress());
user.setUserSource(RangerCommonEnums.USER_APP);
dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
user.setUserSource(RangerCommonEnums.USER_EXTERNAL);
changeEmail.setEmailAddress("");
dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(false);
changeEmail.setEmailAddress("test@123.com");
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrInvalidEmail", MessageEnums.INVALID_INPUT_DATA, changeEmail.getId(), "emailAddress", changeEmail.toString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.changeEmailAddress(user, changeEmail);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestUserMgr method test07ChangeEmailAddressAsKeyAdmin.
@Test
public void test07ChangeEmailAddressAsKeyAdmin() {
setupKeyAdmin();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
VXPortalUser userProfile = userProfile();
XXPortalUser userKeyAdmin = new XXPortalUser();
userKeyAdmin.setEmailAddress(userProfile.getEmailAddress());
userKeyAdmin.setFirstName(userProfile.getFirstName());
userKeyAdmin.setLastName(userProfile.getLastName());
userKeyAdmin.setLoginId(userProfile.getLoginId());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
userKeyAdmin.setPassword(encryptedPwd);
userKeyAdmin.setUserSource(userProfile.getUserSource());
userKeyAdmin.setPublicScreenName(userProfile.getPublicScreenName());
userKeyAdmin.setId(userProfile.getId());
VXPasswordChange changeEmail = new VXPasswordChange();
changeEmail.setEmailAddress("testuser@test.com");
changeEmail.setId(userKeyAdmin.getId());
changeEmail.setLoginId(userKeyAdmin.getLoginId());
changeEmail.setOldPassword(userProfile.getPassword());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
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);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(userKeyAdmin, changeEmail);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(userId, dbVXPortalUser.getId());
Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(changeEmail.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(changeEmail.getEmailAddress(), dbVXPortalUser.getEmailAddress());
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestUserMgr method test08ChangeEmailAddressAsUser.
@Test
public void test08ChangeEmailAddressAsUser() {
setupUser();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptedPwd);
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
VXPasswordChange changeEmail = new VXPasswordChange();
changeEmail.setEmailAddress("testuser@test.com");
changeEmail.setId(user.getId());
changeEmail.setLoginId(user.getLoginId());
changeEmail.setOldPassword(userProfile.getPassword());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
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);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(userId, dbVXPortalUser.getId());
Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(changeEmail.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(changeEmail.getEmailAddress(), dbVXPortalUser.getEmailAddress());
user.setId(userProfile.getId());
user.setLoginId("usertest123");
String encryptCred = userMgr.encrypt(user.getLoginId(), userProfile.getPassword());
user.setPassword(encryptCred);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrWrongPassword", MessageEnums.OPER_NO_PERMISSION, null, null, changeEmail.toString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.changeEmailAddress(user, changeEmail);
}
Aggregations