use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.
the class TestSecurityZoneDBStore method test4deleteSecurityZoneById.
@Test
public void test4deleteSecurityZoneById() throws Exception {
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(securityZoneService.read(securityZone.getId())).thenReturn(securityZone);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
Mockito.when(securityZoneRefUpdater.cleanupRefTables(securityZone)).thenReturn(true);
Mockito.when(securityZoneService.delete(securityZone)).thenReturn(true);
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
securityZoneDBStore.deleteSecurityZoneById(securityZone.getId());
}
use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.
the class TestXUserMgr method test120GetUserStoreVersion.
@Test
public void test120GetUserStoreVersion() throws Exception {
destroySession();
setup();
Long lastKnownUserStoreVersion = Long.valueOf(1);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
Mockito.when(xxGlobalStateDao.getAppDataVersion(RANGER_USER_GROUP_GLOBAL_STATE_NAME)).thenReturn(lastKnownUserStoreVersion);
Long userStoreVersion = xUserMgr.getUserStoreVersion();
Assert.assertNotNull(userStoreVersion);
Assert.assertEquals(lastKnownUserStoreVersion, userStoreVersion);
}
use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.
the class TestXUserMgr method test112CreateOrUpdateXUsers.
@Test
public void test112CreateOrUpdateXUsers() {
destroySession();
setup();
List<VXUser> vXUserList = new ArrayList<VXUser>();
VXUser vXUser = vxUser();
vXUser.setFirstName("testuser");
vXUser.setLastName("testuser");
vXUser.setPassword("TestPassword@123");
vXUser.setEmailAddress("");
vXUser.setUserSource(RangerCommonEnums.USER_APP);
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add(RangerConstants.ROLE_USER);
userRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
userRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
userRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
userRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
vXUser.setUserRoleList(userRoleList);
vXUserList.add(vXUser);
VXUserList users = new VXUserList(vXUserList);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setFirstName("testuser");
vXPortalUser.setLastName("testuser");
vXPortalUser.setPassword("TestPassword@123");
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
VXUserPermission userPermission = vxUserPermission();
List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
userPermList.add(userPermission);
xUserPermissionObj.setModuleId(userPermission.getModuleId());
xUserPermissionObj.setUserId(userPermission.getUserId());
xUserPermissionsList.add(xUserPermissionObj);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(vXUser);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
xUserMgr.createOrUpdateXUsers(users);
vXUser.setPassword("*****");
xUserMgr.createOrUpdateXUsers(users);
}
use of org.apache.ranger.db.XXGlobalStateDao 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);
}
use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.
the class TestSecurityZoneDBStore method test3deleteSecurityZoneByName.
@Test
public void test3deleteSecurityZoneByName() throws Exception {
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(xxSecurityZone);
Mockito.when(securityZoneService.read(securityZone.getId())).thenReturn(securityZone);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
Mockito.when(securityZoneRefUpdater.cleanupRefTables(securityZone)).thenReturn(true);
Mockito.when(securityZoneService.delete(securityZone)).thenReturn(true);
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
securityZoneDBStore.deleteSecurityZoneByName(securityZone.getName());
Assert.assertNotNull(xxSecurityZone);
}
Aggregations