Search in sources :

Example 26 with XXModuleDef

use of org.apache.ranger.entity.XXModuleDef in project ranger by apache.

the class TestXUserMgr method test33updateXModuleDefPermission.

@Test
public void test33updateXModuleDefPermission() {
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    VXUserPermission vXUserPermission = vXUserPermission();
    VXGroupPermission vXGroupPermission = vXGroupPermission();
    VXModuleDef vXModuleDef = vXModuleDef();
    Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
    Mockito.when(xModuleDefService.populateViewBean(xModuleDef)).thenReturn(vXModuleDef);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(xGroupPermissionService.createResource((VXGroupPermission) Mockito.any())).thenReturn(vXGroupPermission);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vXUserPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertNotNull(dbMuduleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
    Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
    Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
    Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
    Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
    Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
    Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
    Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
    Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
    Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
    Mockito.verify(daoManager).getXXModuleDef();
    Mockito.verify(xModuleDefService).populateViewBean(xModuleDef);
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXGroupPermission();
}
Also used : XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXModuleDef(org.apache.ranger.view.VXModuleDef) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with XXModuleDef

use of org.apache.ranger.entity.XXModuleDef in project ranger by apache.

the class TestXUserMgr method test109AssignPermissionToUser.

@Test
public void test109AssignPermissionToUser() {
    destroySession();
    setup();
    VXPortalUser vXPortalUser = userProfile();
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXModuleDef().getAll()).thenReturn(xXModuleDefs);
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermission = xxUserPermission();
    xUserPermission.setModuleId(userPermission.getModuleId());
    xUserPermission.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermission);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(xXUserPermissionDao.findByModuleIdAndPortalUserId(vXPortalUser.getId(), xXModuleDefs.get(0).getId())).thenReturn(xUserPermission);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermission)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    Collection<String> existingRoleList = new ArrayList<String>();
    existingRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    existingRoleList.clear();
    existingRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    existingRoleList.clear();
    existingRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    existingRoleList.clear();
    existingRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUser(org.apache.ranger.view.VXUser) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with XXModuleDef

use of org.apache.ranger.entity.XXModuleDef in project ranger by apache.

the class TestXUserMgr method test20DeleteXGroup.

@Test
public void test20DeleteXGroup() {
    setup();
    boolean force = true;
    VXGroup vXGroup = vxGroup();
    XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(xXUser.getId())).thenReturn(xXUser);
    XXGroup xXGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
    Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.getById(Mockito.anyLong())).thenReturn(xXResource);
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    XXModuleDef xModuleDef = xxModuleDef();
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
    Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
    Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroupDao(org.apache.ranger.db.XXRoleRefGroupDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXModuleDef(org.apache.ranger.entity.XXModuleDef) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Example 29 with XXModuleDef

use of org.apache.ranger.entity.XXModuleDef 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);
}
Also used : HashMap(java.util.HashMap) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) UsersGroupRoleAssignments(org.apache.ranger.ugsyncutil.model.UsersGroupRoleAssignments) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with XXModuleDef

use of org.apache.ranger.entity.XXModuleDef in project ranger by apache.

the class TestXUserMgr method test112CreateOrUpdateXUsers.

@Test
public void test112CreateOrUpdateXUsers() {
    destroySession();
    setup();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    VXUser vXUser = vxUser();
    vXUser.setFirstName("testuser");
    vXUser.setLastName("testuser");
    vXUser.setPassword("TestPassword@123");
    vXUser.setEmailAddress("");
    vXUser.setUserSource(RangerCommonEnums.USER_APP);
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add(RangerConstants.ROLE_USER);
    userRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
    userRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
    vXUser.setUserRoleList(userRoleList);
    vXUserList.add(vXUser);
    VXUserList users = new VXUserList(vXUserList);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setFirstName("testuser");
    vXPortalUser.setLastName("testuser");
    vXPortalUser.setPassword("TestPassword@123");
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(vXUser);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    xUserMgr.createOrUpdateXUsers(users);
    vXUser.setPassword("*****");
    xUserMgr.createOrUpdateXUsers(users);
}
Also used : XXUserDao(org.apache.ranger.db.XXUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserList(org.apache.ranger.view.VXUserList) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

XXModuleDef (org.apache.ranger.entity.XXModuleDef)41 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)31 XXUserPermission (org.apache.ranger.entity.XXUserPermission)29 VXPortalUser (org.apache.ranger.view.VXPortalUser)28 VXUserPermission (org.apache.ranger.view.VXUserPermission)28 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)26 VXString (org.apache.ranger.view.VXString)26 XXPortalUser (org.apache.ranger.entity.XXPortalUser)25 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)23 Date (java.util.Date)19 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)18 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)18 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)16 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)16 VXUser (org.apache.ranger.view.VXUser)15 XXUserDao (org.apache.ranger.db.XXUserDao)14 HashSet (java.util.HashSet)13 UserSessionBase (org.apache.ranger.common.UserSessionBase)13