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