Search in sources :

Example 1 with VXUserGroupInfo

use of org.apache.ranger.view.VXUserGroupInfo in project ranger by apache.

the class TestXUserMgr method test23CreateVXUserGroupInfo.

@Test
public void test23CreateVXUserGroupInfo() {
    setup();
    VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
    VXUser vXUser = vxUser();
    List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
    List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
    final VXGroup vXGroup1 = vxGroup();
    vXGroup1.setName("users");
    vXGroup1.setDescription("users -added for unit testing");
    vXGroupList.add(vXGroup1);
    VXGroupUser vXGroupUser1 = vxGroupUser();
    vXGroupUser1.setName("users");
    vXGroupUserList.add(vXGroupUser1);
    final VXGroup vXGroup2 = vxGroup();
    vXGroup2.setName("user1");
    vXGroup2.setDescription("user1 -added for unit testing");
    vXGroupList.add(vXGroup2);
    VXGroupUser vXGroupUser2 = vxGroupUser();
    vXGroupUser2.setName("user1");
    vXGroupUserList.add(vXGroupUser2);
    vXUserGroupInfo.setXuserInfo(vXUser);
    vXUserGroupInfo.setXgroupInfo(vXGroupList);
    Mockito.when(xUserService.createXUserWithOutLogin(vXUser)).thenReturn(vXUser);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup1)).thenReturn(vXGroup1);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup2)).thenReturn(vXGroup2);
    XXPortalUserDao portalUser = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(portalUser);
    XXPortalUser user = new XXPortalUser();
    user.setId(1L);
    user.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    Mockito.when(portalUser.findByLoginId(vXUser.getName())).thenReturn(user);
    XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao);
    List<String> existingRole = new ArrayList<String>();
    existingRole.add(RangerConstants.ROLE_USER);
    List<String> reqRoleList = new ArrayList<String>();
    reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    Mockito.when(userDao.findXPortalUserRolebyXPortalUserId(Mockito.anyLong())).thenReturn(reqRoleList);
    VXPortalUser vXPortalUser = userProfile();
    Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(vXPortalUser);
    Mockito.when(userMgr.updateRoleForExternalUsers(Mockito.any(), Mockito.any(), (VXPortalUser) Mockito.any())).thenReturn(vXPortalUser);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_USER");
    vXPortalUser.setUserRoleList(userRoleList);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    VXUserGroupInfo vxUserGroupTest = xUserMgr.createXUserGroupFromMap(vXUserGroupInfo);
    Assert.assertEquals(userLoginID, vxUserGroupTest.getXuserInfo().getName());
    List<VXGroup> result = vxUserGroupTest.getXgroupInfo();
    List<VXGroup> expected = new ArrayList<VXGroup>();
    expected.add(vXGroup1);
    expected.add(vXGroup2);
    Assert.assertTrue(result.containsAll(expected));
    Mockito.verify(portalUser).findByLoginId(vXUser.getName());
    Mockito.verify(userDao).findXPortalUserRolebyXPortalUserId(Mockito.anyLong());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXUserGroupInfo(org.apache.ranger.view.VXUserGroupInfo) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 2 with VXUserGroupInfo

use of org.apache.ranger.view.VXUserGroupInfo in project ranger by apache.

the class TestXUserREST method test16createXUserGroupFromMap.

@Test
public void test16createXUserGroupFromMap() {
    VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
    vXUserGroupInfo.setXuserInfo(vxUser);
    Mockito.when(xUserMgr.createXUserGroupFromMap(vXUserGroupInfo)).thenReturn(vXUserGroupInfo);
    VXUserGroupInfo gotVXUserGroupInfo = xUserRest.createXUserGroupFromMap(vXUserGroupInfo);
    Mockito.verify(xUserMgr).createXUserGroupFromMap(vXUserGroupInfo);
    assertNotNull(gotVXUserGroupInfo);
    assertEquals(vXUserGroupInfo.getId(), gotVXUserGroupInfo.getId());
    assertEquals(vXUserGroupInfo.getOwner(), gotVXUserGroupInfo.getOwner());
}
Also used : VXUserGroupInfo(org.apache.ranger.view.VXUserGroupInfo) Test(org.junit.Test)

Example 3 with VXUserGroupInfo

use of org.apache.ranger.view.VXUserGroupInfo in project ranger by apache.

the class TestXUserMgr method test30CreateVXUserGroupInfo.

@Test
public void test30CreateVXUserGroupInfo() {
    setup();
    VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
    VXUser vXUser = new VXUser();
    vXUser.setName("user1");
    vXUser.setDescription("testuser1 -added for unit testing");
    vXUser.setPassword("usertest123");
    List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
    List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
    final VXGroup vXGroup1 = new VXGroup();
    vXGroup1.setName("users");
    vXGroup1.setDescription("users -added for unit testing");
    vXGroupList.add(vXGroup1);
    VXGroupUser vXGroupUser1 = new VXGroupUser();
    vXGroupUser1.setName("users");
    vXGroupUserList.add(vXGroupUser1);
    final VXGroup vXGroup2 = new VXGroup();
    vXGroup2.setName("user1");
    vXGroup2.setDescription("user1 -added for unit testing");
    vXGroupList.add(vXGroup2);
    VXGroupUser vXGroupUser2 = new VXGroupUser();
    vXGroupUser2.setName("user1");
    vXGroupUserList.add(vXGroupUser2);
    vXUserGroupInfo.setXuserInfo(vXUser);
    vXUserGroupInfo.setXgroupInfo(vXGroupList);
    Mockito.when(xUserService.createXUserWithOutLogin(vXUser)).thenReturn(vXUser);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup1)).thenReturn(vXGroup1);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup2)).thenReturn(vXGroup2);
    XXPortalUserDao portalUser = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(portalUser);
    XXPortalUser user = new XXPortalUser();
    user.setId(1L);
    user.setUserSource(RangerCommonEnums.USER_APP);
    Mockito.when(portalUser.findByLoginId(vXUser.getName())).thenReturn(user);
    XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    Mockito.when(userDao.findXPortalUserRolebyXPortalUserId(Mockito.anyLong())).thenReturn(lstRole);
    VXUserGroupInfo vxUserGroupTest = xUserMgr.createXUserGroupFromMap(vXUserGroupInfo);
    Assert.assertEquals("user1", vxUserGroupTest.getXuserInfo().getName());
    List<VXGroup> result = vxUserGroupTest.getXgroupInfo();
    List<VXGroup> expected = new ArrayList<VXGroup>();
    expected.add(vXGroup1);
    expected.add(vXGroup2);
    Assert.assertTrue(result.containsAll(expected));
    // Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(portalUser).findByLoginId(vXUser.getName());
    // Mockito.verify(daoManager).getXXPortalUserRole();
    Mockito.verify(userDao).findXPortalUserRolebyXPortalUserId(Mockito.anyLong());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXUserGroupInfo(org.apache.ranger.view.VXUserGroupInfo) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Aggregations

VXUserGroupInfo (org.apache.ranger.view.VXUserGroupInfo)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)2 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)2 XXPortalUser (org.apache.ranger.entity.XXPortalUser)2 VXGroup (org.apache.ranger.view.VXGroup)2 VXGroupUser (org.apache.ranger.view.VXGroupUser)2 VXString (org.apache.ranger.view.VXString)2 VXUser (org.apache.ranger.view.VXUser)2 HashSet (java.util.HashSet)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)1 XXUserDao (org.apache.ranger.db.XXUserDao)1 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)1 XXModuleDef (org.apache.ranger.entity.XXModuleDef)1 XXUser (org.apache.ranger.entity.XXUser)1 XXUserPermission (org.apache.ranger.entity.XXUserPermission)1 VXPortalUser (org.apache.ranger.view.VXPortalUser)1 VXUserPermission (org.apache.ranger.view.VXUserPermission)1