use of org.apache.ranger.view.VXGroupList in project ranger by apache.
the class TestXUserREST method test11searchXGroups.
@SuppressWarnings("unchecked")
@Test
public void test11searchXGroups() {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchCriteria testSearchCriteria = createsearchCriteria();
Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
Mockito.when(searchUtil.extractString(request, testSearchCriteria, "name", "group name", null)).thenReturn("");
Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "isVisible", "Group Visibility")).thenReturn(1);
Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "groupSource", "group source")).thenReturn(1);
VXGroupList testvXGroupList = createxGroupList();
Mockito.when(xUserMgr.searchXGroups(testSearchCriteria)).thenReturn(testvXGroupList);
VXGroupList outputvXGroupList = xUserRest.searchXGroups(request);
Mockito.verify(xUserMgr).searchXGroups(testSearchCriteria);
Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "name", "group name", null);
Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "isVisible", "Group Visibility");
Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "groupSource", "group source");
assertNotNull(outputvXGroupList);
assertEquals(outputvXGroupList.getTotalCount(), testvXGroupList.getTotalCount());
assertEquals(outputvXGroupList.getClass(), testvXGroupList.getClass());
}
use of org.apache.ranger.view.VXGroupList in project ranger by apache.
the class TestXUserMgr method test108RoleUserWillSearchOnlyHisOwnGroupDetails.
@Test
public void test108RoleUserWillSearchOnlyHisOwnGroupDetails() {
destroySession();
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(false);
XXPortalUser xXPortalUser = new XXPortalUser();
xXPortalUser.setLoginId(userLoginID);
xXPortalUser.setId(userId);
currentUserSession.setXXPortalUser(xXPortalUser);
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
SearchCriteria testSearchCriteria = createsearchCriteria();
List<Long> groupIdList = new ArrayList<Long>();
groupIdList.add(5L);
VXGroup expectedVXGroup = new VXGroup();
expectedVXGroup.setId(5L);
expectedVXGroup.setName("testGroup");
List<VXGroup> grpList = new ArrayList<VXGroup>();
grpList.add(expectedVXGroup);
VXGroupList expectedVXGroupList = new VXGroupList();
expectedVXGroupList.setVXGroups(grpList);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_USER);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
loggedInUser.setGroupIdList(groupIdList);
VXUser vxUser = vxUser();
List<String> userRole = new ArrayList<String>();
userRole.add(RangerConstants.ROLE_USER);
vxUser.setId(8L);
vxUser.setName("test3");
vxUser.setUserRoleList(userRole);
vxUser.setUserSource(RangerCommonEnums.USER_UNIX);
Mockito.when(xUserService.getXUserByUserName("testuser")).thenReturn(loggedInUser);
Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(expectedVXGroupList);
XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
VXGroupList rcvVXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
Assert.assertNotNull(rcvVXGroupList);
Assert.assertEquals(rcvVXGroupList.getList().get(0).getId(), expectedVXGroup.getId());
Assert.assertEquals(rcvVXGroupList.getList().get(0).getName(), expectedVXGroup.getName());
}
use of org.apache.ranger.view.VXGroupList in project ranger by apache.
the class TestXUserMgr method test123LookupXGroups.
@Test
public void test123LookupXGroups() {
destroySession();
setup();
VXGroup vXGroup = vxGroup();
VXGroupList vXGroupListSort = new VXGroupList();
List<VXGroup> vXGroups = new ArrayList<VXGroup>();
vXGroups.add(vXGroup);
vXGroupListSort.setVXGroups(vXGroups);
String groupName = vXGroup.getName();
SearchCriteria testSearchCriteria = createsearchCriteria();
testSearchCriteria.addParam("name", groupName);
Mockito.when(xGroupService.getGroupByGroupName(groupName)).thenReturn(vXGroup);
Mockito.when(xGroupService.searchXGroups((SearchCriteria) Mockito.any())).thenReturn(vXGroupListSort);
VXGroupList vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
testSearchCriteria.addParam("isvisible", "true");
vXGroupList = xUserMgr.lookupXGroups(testSearchCriteria);
Assert.assertNotNull(vXGroupList);
testSearchCriteria = createsearchCriteria();
testSearchCriteria.addParam("name", groupName);
testSearchCriteria.addParam("groupsource", 1L);
vXGroupList = xUserMgr.lookupXGroups(testSearchCriteria);
Assert.assertNotNull(vXGroupList);
testSearchCriteria = createsearchCriteria();
testSearchCriteria.setSortBy("");
testSearchCriteria.addParam("name", groupName);
Mockito.when(xGroupService.getGroupByGroupName(Mockito.anyString())).thenReturn(vXGroup);
vXGroupList = xUserMgr.lookupXGroups(testSearchCriteria);
Assert.assertNotNull(vXGroupList);
SearchCriteria emptyCriteria = new SearchCriteria();
Mockito.when(xGroupService.searchXGroups((SearchCriteria) Mockito.any())).thenReturn(null);
vXGroupList = xUserMgr.lookupXGroups(emptyCriteria);
Assert.assertNull(vXGroupList);
}
use of org.apache.ranger.view.VXGroupList in project ranger by apache.
the class TestXUserMgr method test114CreateOrUpdateXGroups.
@Test
public void test114CreateOrUpdateXGroups() {
destroySession();
setup();
VXGroup vXGroup = vxGroup();
VXGroupList vXGroupListSort = new VXGroupList();
List<VXGroup> vXGroups = new ArrayList<VXGroup>();
vXGroups.add(vXGroup);
VXGroup vXGroup1 = vxGroup();
vXGroup1.setName("null");
vXGroups.add(vXGroup1);
vXGroupListSort.setVXGroups(vXGroups);
VXUser vXUser = vxUser();
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vXUser);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
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(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
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);
xUserMgr.createOrUpdateXGroups(vXGroupListSort);
}
Aggregations