use of org.apache.ranger.db.XXRoleDao in project ranger by apache.
the class TestXUserMgr method test127DeleteXUser.
@Test
public void test127DeleteXUser() {
destroySession();
setup();
boolean force = true;
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);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
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");
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
XXAuthSession xXAuthSession = new XXAuthSession();
xXAuthSession.setId(userId);
xXAuthSession.setLoginId(vXPortalUser.getLoginId());
xXAuthSessions.add(xXAuthSession);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
xXUserPermissions.add(xxUserPermission());
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
xXPortalUserRoles.add(XXPortalUserRole);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
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>();
XXRoleRefUser xRoleRefUser = new XXRoleRefUser();
xRoleRefUser.setRoleId(userId);
xRoleRefUser.setUserId(userId);
xRoleRefUser.setUserName(vXUser.getName().trim());
xRoleRefUser.setUserType(0);
roleRefUser.add(xRoleRefUser);
XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
XXRoleDao roleDao = Mockito.mock(XXRoleDao.class);
Mockito.when(daoManager.getXXRole()).thenReturn(roleDao);
Mockito.when(roleDao.getById(xRoleRefUser.getRoleId())).thenReturn(xRole);
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete User '" + vXUser.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
force = false;
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.db.XXRoleDao in project ranger by apache.
the class TestXUserMgr method test128DeleteXGroup.
@Test
public void test128DeleteXGroup() {
destroySession();
setup();
boolean force = true;
VXGroup vXGroup = vxGroup();
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
XXGroupGroup xXGroupGroup = xxGroupGroup();
xXGroupGroups.add(xXGroupGroup);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
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);
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>();
XXRoleRefGroup xRoleRefGroup = new XXRoleRefGroup();
xRoleRefGroup.setRoleId(userId);
xRoleRefGroup.setGroupId(userId);
xRoleRefGroup.setGroupName(groupName);
xRoleRefGroup.setGroupType(0);
roleRefGroup.add(xRoleRefGroup);
XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
XXRoleDao roleDao = Mockito.mock(XXRoleDao.class);
Mockito.when(daoManager.getXXRole()).thenReturn(roleDao);
Mockito.when(roleDao.getById(xRoleRefGroup.getRoleId())).thenReturn(xRole);
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete Group '" + vXGroup.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Aggregations