Search in sources :

Example 6 with XXPolicyDao

use of org.apache.ranger.db.XXPolicyDao in project ranger by apache.

the class TestXUserMgr method test94DeleteXUser.

@Test
public void test94DeleteXUser() {
    setup();
    boolean force = false;
    VXUser vXUser = vxUser();
    XXUser xXUser = new XXUser();
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
    Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
    XXAuthSession xXAuthSession = new XXAuthSession();
    xXAuthSession.setId(userId);
    xXAuthSession.setLoginId(vXPortalUser.getLoginId());
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
    List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
    XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
    Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
    List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
    XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
    Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
    Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(new VXGroupUserList());
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(xXPolicyList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(new ArrayList<XXPolicy>());
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(new VXPermMapList());
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(new VXAuditMapList());
    xXAuthSessions.add(xXAuthSession);
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXAuthSession>());
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xXUserPermissions.add(xUserPermissionObj);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(new ArrayList<XXUserPermission>());
    xXPortalUserRoles.add(XXPortalUserRole);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXPortalUserRole>());
    xUserMgr.deleteXUser(vXUser.getId(), force);
    vXUser.setName("");
    Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
    thrown.expect(NullPointerException.class);
    xUserMgr.deleteXUser(vXUser.getId(), force);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXAuditMap(org.apache.ranger.view.VXAuditMap) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Example 7 with XXPolicyDao

use of org.apache.ranger.db.XXPolicyDao in project ranger by apache.

the class TestXUserMgr method test95DeleteXGroup.

@Test
public void test95DeleteXGroup() {
    setup();
    boolean force = false;
    VXGroup vXGroup = vxGroup();
    XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroup xXGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
    Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
    Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(new VXGroupUserList());
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(new ArrayList<XXPolicy>());
    vXPermMapList.setVXPermMaps(vXPermMaps);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(new VXPermMapList());
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(new VXAuditMapList());
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(new ArrayList<XXGroupGroup>());
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(new ArrayList<XXGroupPermission>());
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(null);
    Mockito.when(restErrorUtil.createRESTException("Group ID doesn't exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroupDao(org.apache.ranger.db.XXRoleRefGroupDao) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Example 8 with XXPolicyDao

use of org.apache.ranger.db.XXPolicyDao in project ranger by apache.

the class TestXUserMgr method test28DeleteXUser.

@Test
public void test28DeleteXUser() {
    setup();
    boolean force = true;
    VXUser vXUser = vxUser();
    // XXUser
    XXUser xXUser = new XXUser();
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
    // VXGroupUser
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    VXGroupUser vxGroupUser = new VXGroupUser();
    vxGroupUser.setId(userId);
    vxGroupUser.setName("group user test");
    vxGroupUser.setOwner("Admin");
    vxGroupUser.setUserId(vXUser.getId());
    vxGroupUser.setUpdatedBy("User");
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    // VXPermMap
    VXPermMapList vXPermMapList = new VXPermMapList();
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    // VXAuditMap
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    // XXPortalUser
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = new XXPortalUser();
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
    Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
    XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    // update XXPolicyItemUserPerm
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Example 9 with XXPolicyDao

use of org.apache.ranger.db.XXPolicyDao in project ranger by apache.

the class TestXUserMgr method test20DeleteXGroup.

@Test
public void test20DeleteXGroup() {
    setup();
    boolean force = true;
    VXGroup vXGroup = vxGroup();
    XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(xXUser.getId())).thenReturn(xXUser);
    XXGroup xXGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
    Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.getById(Mockito.anyLong())).thenReturn(xXResource);
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    XXModuleDef xModuleDef = xxModuleDef();
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
    Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
    Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroupDao(org.apache.ranger.db.XXRoleRefGroupDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXModuleDef(org.apache.ranger.entity.XXModuleDef) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Example 10 with XXPolicyDao

use of org.apache.ranger.db.XXPolicyDao in project ranger by apache.

the class TestPublicAPIs method test9updatePolicy.

@Test
public void test9updatePolicy() throws Exception {
    RangerPolicy policy = rangerPolicy();
    RangerService service = rangerService();
    VXPolicy vXPolicy = vXPolicy(policy, service);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    XXPolicy xXPolicy = policy();
    Mockito.when(daoMgr.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.getById(Id)).thenReturn(xXPolicy);
    Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service);
    Mockito.when(serviceUtil.toRangerPolicy(vXPolicy, service)).thenReturn(policy);
    Mockito.when(serviceREST.updatePolicy(policy)).thenReturn(policy);
    Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy);
    VXPolicy dbVXPolicy = publicAPIs.updatePolicy(vXPolicy, Id);
    Assert.assertNotNull(dbVXPolicy);
    Assert.assertEquals(dbVXPolicy, vXPolicy);
    Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId());
    Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName());
    Mockito.verify(serviceREST).updatePolicy(policy);
    Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName());
    Mockito.verify(serviceUtil).toVXPolicy(policy, service);
    Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy, service);
    Mockito.verify(daoMgr).getXXPolicy();
    Mockito.verify(xXPolicyDao).getById(Id);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicy(org.apache.ranger.view.VXPolicy) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Aggregations

XXPolicyDao (org.apache.ranger.db.XXPolicyDao)13 XXPolicy (org.apache.ranger.entity.XXPolicy)11 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)6 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)6 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)6 XXUserDao (org.apache.ranger.db.XXUserDao)6 XXUser (org.apache.ranger.entity.XXUser)6 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)6 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)6 VXGroupUserList (org.apache.ranger.view.VXGroupUserList)6 VXPermMapList (org.apache.ranger.view.VXPermMapList)6 XXAuthSessionDao (org.apache.ranger.db.XXAuthSessionDao)4 XXGroupDao (org.apache.ranger.db.XXGroupDao)4 XXGroupGroupDao (org.apache.ranger.db.XXGroupGroupDao)4 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)4 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)4 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)4 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)4