Search in sources :

Example 1 with VXUserList

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

the class TestXUserREST method test24searchXUsers.

@SuppressWarnings("unchecked")
@Test
public void test24searchXUsers() {
    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", "User name", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "emailAddress", "Email Address", null)).thenReturn("");
    Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "userSource", "User Source")).thenReturn(1);
    Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "isVisible", "User Visibility")).thenReturn(1);
    Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "status", "User Status")).thenReturn(1);
    Mockito.when(searchUtil.extractStringList(request, testSearchCriteria, "userRoleList", "User Role List", "userRoleList", null, null)).thenReturn(new ArrayList<String>());
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "userRole", "UserRole", null)).thenReturn("");
    List<VXUser> vXUsersList = new ArrayList<VXUser>();
    vXUsersList.add(vxUser);
    VXUserList testVXUserList = new VXUserList();
    testVXUserList.setVXUsers(vXUsersList);
    Mockito.when(xUserMgr.searchXUsers(testSearchCriteria)).thenReturn(testVXUserList);
    VXUserList gotVXUserList = xUserRest.searchXUsers(request);
    Mockito.verify(xUserMgr).searchXUsers(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "name", "User name", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "emailAddress", "Email Address", null);
    Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "userSource", "User Source");
    Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "isVisible", "User Visibility");
    Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "status", "User Status");
    Mockito.verify(searchUtil).extractStringList(request, testSearchCriteria, "userRoleList", "User Role List", "userRoleList", null, null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "userRole", "UserRole", null);
    assertNotNull(gotVXUserList);
    assertEquals(testVXUserList.getTotalCount(), gotVXUserList.getTotalCount());
    assertEquals(testVXUserList.getClass(), gotVXUserList.getClass());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXUserList(org.apache.ranger.view.VXUserList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 2 with VXUserList

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

the class MetricUtil method getUserCountBasedOnUserRole.

private Long getUserCountBasedOnUserRole(@SuppressWarnings("rawtypes") List userRoleList) {
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.setStartIndex(0);
    searchCriteria.setMaxRows(100);
    searchCriteria.setGetCount(true);
    searchCriteria.setSortType("asc");
    searchCriteria.addParam("userRoleList", userRoleList);
    VXUserList VXUserListKeyAdmin = xUserMgr.searchXUsers(searchCriteria);
    long userCount = VXUserListKeyAdmin.getTotalCount();
    return userCount;
}
Also used : VXUserList(org.apache.ranger.view.VXUserList) SearchCriteria(org.apache.ranger.common.SearchCriteria)

Example 3 with VXUserList

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

the class XUserServiceBase method searchXUsers.

/**
 * @param searchCriteria
 * @return
 */
public VXUserList searchXUsers(SearchCriteria searchCriteria) {
    VXUserList returnList = new VXUserList();
    List<VXUser> xUserList = new ArrayList<VXUser>();
    @SuppressWarnings("unchecked") List<XXUser> resultList = (List<XXUser>) searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (XXUser gjXUser : resultList) {
        @SuppressWarnings("unchecked") VXUser vXUser = populateViewBean((T) gjXUser);
        xUserList.add(vXUser);
    }
    returnList.setVXUsers(xUserList);
    return returnList;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) ArrayList(java.util.ArrayList) List(java.util.List) VXUserList(org.apache.ranger.view.VXUserList) ArrayList(java.util.ArrayList) VXUser(org.apache.ranger.view.VXUser) VXUserList(org.apache.ranger.view.VXUserList)

Example 4 with VXUserList

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

the class TestXUserREST method test73getXGroupUsers.

@SuppressWarnings("unchecked")
@Test
public void test73getXGroupUsers() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    testSearchCriteria.addParam("xGroupId", id);
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    VXUser testVXUser = createVXUser();
    VXUserList testVXUserList = new VXUserList();
    List<VXUser> testVXUsers = new ArrayList<VXUser>();
    testVXUsers.add(testVXUser);
    testVXUserList.setVXUsers(testVXUsers);
    testVXUserList.setStartIndex(1);
    testVXUserList.setTotalCount(1);
    Mockito.when(xUserMgr.getXGroupUsers(testSearchCriteria)).thenReturn(testVXUserList);
    VXUserList retVxGroupList = xUserRest.getXGroupUsers(request, id);
    assertNotNull(retVxGroupList);
    assertEquals(testVXUserList.getTotalCount(), retVxGroupList.getTotalCount());
    assertEquals(testVXUserList.getStartIndex(), retVxGroupList.getStartIndex());
    Mockito.verify(xUserMgr).getXGroupUsers(testSearchCriteria);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXUser(org.apache.ranger.view.VXUser) VXUserList(org.apache.ranger.view.VXUserList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 5 with VXUserList

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

the class TestXUserMgr method test23GetXGroupUsers.

@Test
public void test23GetXGroupUsers() {
    SearchCriteria testSearchCriteria = createsearchCriteria();
    testSearchCriteria.addParam("xGroupId", userId);
    VXUserList dbVXUserList = xUserMgr.getXGroupUsers(testSearchCriteria);
    VXGroup vXGroup = new VXGroup();
    vXGroup.setId(userId);
    vXGroup.setDescription("group test");
    vXGroup.setName("grouptest");
    Assert.assertNotNull(dbVXUserList);
}
Also used : VXUserList(org.apache.ranger.view.VXUserList) VXGroup(org.apache.ranger.view.VXGroup) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Aggregations

VXUserList (org.apache.ranger.view.VXUserList)6 ArrayList (java.util.ArrayList)4 SearchCriteria (org.apache.ranger.common.SearchCriteria)4 VXUser (org.apache.ranger.view.VXUser)4 Test (org.junit.Test)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SortField (org.apache.ranger.common.SortField)2 List (java.util.List)1 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)1 XXPortalUser (org.apache.ranger.entity.XXPortalUser)1 XXUser (org.apache.ranger.entity.XXUser)1 VXGroup (org.apache.ranger.view.VXGroup)1 VXString (org.apache.ranger.view.VXString)1