use of org.apache.ranger.entity.XXRoleRefGroup 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