use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testGetAllSecurityZone.
@Test(expected = WebApplicationException.class)
public void testGetAllSecurityZone() throws Exception {
RangerSecurityZone securityZone = createRangerSecurityZone();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchFilter filter = new SearchFilter();
when(searchUtil.getSearchFilter(request, securityZoneService.sortFields)).thenReturn(filter);
Long securityZoneId = 2L;
securityZone.setId(securityZoneId);
List<RangerSecurityZone> zonesList = new ArrayList<>();
zonesList.add(securityZone);
RangerSecurityZoneList rangerZoneList = new RangerSecurityZoneList();
rangerZoneList.setSecurityZoneList(zonesList);
when(securityZoneStore.getSecurityZones(filter)).thenReturn(zonesList);
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
RangerSecurityZoneList returnedZonesList = securityZoneREST.getAllZones(request);
assertEquals(returnedZonesList.getResultSize(), rangerZoneList.getList().size());
verify(securityZoneStore, times(1)).getSecurityZones(filter);
// No access
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
securityZoneREST.getAllZones(request);
verify(securityZoneStore, times(0)).getSecurityZones(filter);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testGetSecurityZoneById.
@Test(expected = WebApplicationException.class)
public void testGetSecurityZoneById() throws Exception {
RangerSecurityZone securityZone = createRangerSecurityZone();
Long securityZoneId = 2L;
securityZone.setId(securityZoneId);
when(securityZoneStore.getSecurityZone(securityZoneId)).thenReturn(securityZone);
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
RangerSecurityZone rangerSecurityZone = securityZoneREST.getSecurityZone(securityZoneId);
assertEquals(securityZoneId, rangerSecurityZone.getId());
verify(securityZoneStore, times(1)).getSecurityZone(securityZoneId);
// No access
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
securityZoneREST.getSecurityZone(securityZoneId);
verify(securityZoneStore, times(0)).getSecurityZone(securityZoneId);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testDeleteSecurityZoneById.
@Test
public void testDeleteSecurityZoneById() throws Exception {
RangerSecurityZone securityZone = createRangerSecurityZone();
Long securityZoneId = 2L;
securityZone.setId(securityZoneId);
when(rangerBizUtil.isAdmin()).thenReturn(true);
when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
doNothing().when(validator).validate(securityZoneId, RangerValidator.Action.DELETE);
securityZoneREST.deleteSecurityZone(securityZoneId);
verify(securityZoneStore, times(1)).deleteSecurityZoneById(securityZoneId);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testUpdateSecurityZone.
@Test
public void testUpdateSecurityZone() throws Exception {
RangerSecurityZone rangerSecurityZoneToUpdate = createRangerSecurityZone();
Long securityZoneId = 2L;
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXService xService = Mockito.mock(XXService.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
rangerSecurityZoneToUpdate.setId(securityZoneId);
when(rangerBizUtil.isAdmin()).thenReturn(true);
when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
when(daoManager.getXXService()).thenReturn(xServiceDao);
when(xServiceDao.findByName("test_service_1")).thenReturn(xService);
when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
doNothing().when(validator).validate(rangerSecurityZoneToUpdate, RangerValidator.Action.UPDATE);
when(securityZoneStore.updateSecurityZoneById(rangerSecurityZoneToUpdate)).thenReturn(rangerSecurityZoneToUpdate);
RangerSecurityZone updatedRangerSecurityZone = securityZoneREST.updateSecurityZone(securityZoneId, rangerSecurityZoneToUpdate);
assertEquals(rangerSecurityZoneToUpdate.getId(), updatedRangerSecurityZone.getId());
verify(validator, times(1)).validate(rangerSecurityZoneToUpdate, RangerValidator.Action.UPDATE);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestSecurityZoneREST method testGetSecurityZoneByName.
@Test(expected = WebApplicationException.class)
public void testGetSecurityZoneByName() throws Exception {
RangerSecurityZone securityZone = createRangerSecurityZone();
Long securityZoneId = 2L;
String securityZoneName = securityZone.getName();
securityZone.setId(securityZoneId);
when(securityZoneStore.getSecurityZoneByName(securityZoneName)).thenReturn(securityZone);
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
RangerSecurityZone rangerSecurityZone = securityZoneREST.getSecurityZone(securityZoneName);
assertEquals(securityZoneName, rangerSecurityZone.getName());
verify(securityZoneStore, times(1)).getSecurityZoneByName(securityZoneName);
// No access
when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
securityZoneREST.getSecurityZone(securityZoneName);
verify(securityZoneStore, times(0)).getSecurityZoneByName(securityZoneName);
}
Aggregations