use of org.apache.ranger.ugsyncutil.model.UsersGroupRoleAssignments in project ranger by apache.
the class TestXUserMgr method test115UpdateUserRoleAssignments.
@Test
public void test115UpdateUserRoleAssignments() {
destroySession();
setup();
UsersGroupRoleAssignments ugRoleAssignments = new UsersGroupRoleAssignments();
Set<String> addUsers = new HashSet<String>();
Set<String> delUsers = new HashSet<String>();
addUsers.add("testuser");
addUsers.add("testuser2");
delUsers.add("testuser2");
Map<String, String> userMap = new HashMap<String, String>();
Map<String, String> groupMap = new HashMap<>();
List<String> allUsers = new ArrayList<>(addUsers);
userMap.put("testuser", "role1");
userMap.put("testuser2", "role2");
groupMap.put("testgroup1", "role1");
groupMap.put("testgroup2", "role2");
ugRoleAssignments.setUsers(allUsers);
ugRoleAssignments.setGroupRoleAssignments(groupMap);
ugRoleAssignments.setUserRoleAssignments(userMap);
ugRoleAssignments.setWhiteListUserRoleAssignments(new HashMap<>());
ugRoleAssignments.setWhiteListGroupRoleAssignments(new HashMap<>());
VXUser vXUser = vxUser();
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vXUser);
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
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);
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(daoManager.getXXModuleDef().getAll()).thenReturn(xXModuleDefs);
xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
allUsers.clear();
allUsers.add("UnMappedUser");
ugRoleAssignments.setUsers(allUsers);
ugRoleAssignments.setGroupRoleAssignments(groupMap);
ugRoleAssignments.setUserRoleAssignments(userMap);
VXUserPermission userPermission = vxUserPermission();
List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
userPermList.add(userPermission);
List<XXUserPermission> xUserPermissionsList1 = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj1 = xxUserPermission();
xUserPermissionObj1.setModuleId(userPermission.getModuleId());
xUserPermissionObj1.setUserId(userPermission.getUserId());
xUserPermissionsList1.add(xUserPermissionObj1);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(vXPortalUser);
xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
}
Aggregations