Search in sources :

Example 6 with VXModuleDef

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

the class XModuleDefServiceBase method searchModuleDef.

/**
 * @param searchCriteria
 * @return
 */
public VXModuleDefList searchModuleDef(SearchCriteria searchCriteria) {
    VXModuleDefList returnList = new VXModuleDefList();
    List<VXModuleDef> vXModuleDefList = new ArrayList<VXModuleDef>();
    searchCriteria.setMaxRows(Integer.MAX_VALUE);
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    Map<Long, T> matchModule = new HashMap<Long, T>();
    for (T moduleDef : resultList) {
        matchModule.put(moduleDef.getId(), moduleDef);
    }
    List<T> moduleDefList = new ArrayList<T>(matchModule.values());
    // Iterate over the result list and create the return list
    for (T gjXModuleDef : moduleDefList) {
        VXModuleDef vXModuleDef = populateViewBean(gjXModuleDef);
        vXModuleDefList.add(vXModuleDef);
    }
    returnList.setTotalCount(vXModuleDefList.size());
    returnList.setvXModuleDef(vXModuleDefList);
    return returnList;
}
Also used : VXModuleDefList(org.apache.ranger.view.VXModuleDefList) HashMap(java.util.HashMap) VXModuleDef(org.apache.ranger.view.VXModuleDef) ArrayList(java.util.ArrayList)

Example 7 with VXModuleDef

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

the class TestXUserREST method test80searchXModuleDef.

@SuppressWarnings("unchecked")
@Test
public void test80searchXModuleDef() {
    VXModuleDefList testVXModuleDefList = new VXModuleDefList();
    VXModuleDef vXModuleDef = createVXModuleDef();
    List<VXModuleDef> VXModuleDefs = new ArrayList<VXModuleDef>();
    VXModuleDefs.add(vXModuleDef);
    testVXModuleDefList.setvXModuleDef(VXModuleDefs);
    testVXModuleDefList.setTotalCount(1);
    testVXModuleDefList.setStartIndex(1);
    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, "module", "modulename", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "moduleDefList", "id", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "userName", "userName", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "groupName", "groupName", null)).thenReturn("");
    Mockito.when(xUserMgr.searchXModuleDef(testSearchCriteria)).thenReturn(testVXModuleDefList);
    VXModuleDefList outputVXModuleDefList = xUserRest.searchXModuleDef(request);
    assertNotNull(outputVXModuleDefList);
    assertEquals(outputVXModuleDefList.getTotalCount(), testVXModuleDefList.getTotalCount());
    assertEquals(outputVXModuleDefList.getStartIndex(), testVXModuleDefList.getStartIndex());
    Mockito.verify(xUserMgr).searchXModuleDef(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "module", "modulename", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "moduleDefList", "id", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "userName", "userName", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "groupName", "groupName", null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXModuleDefList(org.apache.ranger.view.VXModuleDefList) VXModuleDef(org.apache.ranger.view.VXModuleDef) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 8 with VXModuleDef

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

the class TestXUserREST method test78updateXModuleDefPermission.

@Test
public void test78updateXModuleDefPermission() {
    VXModuleDef testVXModuleDef = createVXModuleDef();
    Mockito.doNothing().when(xUserMgr).checkAdminAccess();
    Mockito.when(xUserMgr.updateXModuleDefPermission(testVXModuleDef)).thenReturn(testVXModuleDef);
    VXModuleDef retVxModuleDef = xUserRest.updateXModuleDefPermission(testVXModuleDef);
    assertNotNull(retVxModuleDef);
    assertEquals(testVXModuleDef.getId(), retVxModuleDef.getId());
    assertEquals(testVXModuleDef.getOwner(), retVxModuleDef.getOwner());
    Mockito.verify(xUserMgr).updateXModuleDefPermission(testVXModuleDef);
    Mockito.verify(xUserMgr).checkAdminAccess();
}
Also used : VXModuleDef(org.apache.ranger.view.VXModuleDef) Test(org.junit.Test)

Example 9 with VXModuleDef

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

the class TestXUserREST method test76createXModuleDefPermission.

@Test
public void test76createXModuleDefPermission() {
    VXModuleDef testVXModuleDef = createVXModuleDef();
    Mockito.doNothing().when(xUserMgr).checkAdminAccess();
    Mockito.when(xUserMgr.createXModuleDefPermission(testVXModuleDef)).thenReturn(testVXModuleDef);
    VXModuleDef retVxModuleDef = xUserRest.createXModuleDefPermission(testVXModuleDef);
    assertNotNull(retVxModuleDef);
    assertEquals(testVXModuleDef.getId(), retVxModuleDef.getId());
    assertEquals(testVXModuleDef.getOwner(), retVxModuleDef.getOwner());
    Mockito.verify(xUserMgr).createXModuleDefPermission(testVXModuleDef);
    Mockito.verify(xUserMgr).checkAdminAccess();
}
Also used : VXModuleDef(org.apache.ranger.view.VXModuleDef) Test(org.junit.Test)

Example 10 with VXModuleDef

use of org.apache.ranger.view.VXModuleDef 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)

Aggregations

VXModuleDef (org.apache.ranger.view.VXModuleDef)11 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)4 VXUserPermission (org.apache.ranger.view.VXUserPermission)4 Date (java.util.Date)2 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)2 VXModuleDefList (org.apache.ranger.view.VXModuleDefList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 SortField (org.apache.ranger.common.SortField)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)1 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)1 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)1 XXGroup (org.apache.ranger.entity.XXGroup)1 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)1 XXModuleDef (org.apache.ranger.entity.XXModuleDef)1