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());
}
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());
}
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());
}
Aggregations