use of org.apache.ranger.db.XXSecurityZoneDao 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);
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestSecurityZoneDBStore method test5getSecurityZoneByName.
@Test
public void test5getSecurityZoneByName() throws Exception {
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
RangerSecurityZone createdSecurityZone = new RangerSecurityZone();
createdSecurityZone.setId(2L);
createdSecurityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(xxSecurityZone);
Mockito.when(securityZoneService.read(securityZone.getId())).thenReturn(createdSecurityZone);
RangerSecurityZone expectedSecurityZone = securityZoneDBStore.getSecurityZoneByName(securityZone.getName());
Assert.assertNotNull(xxSecurityZone);
Assert.assertEquals(createdSecurityZone.getName(), expectedSecurityZone.getName());
Mockito.verify(securityZoneService).read(securityZone.getId());
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestSecurityZoneDBStore method test11getSecurityZoneByWrongName.
@Test
public void test11getSecurityZoneByWrongName() throws Exception {
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
securityZoneDBStore.getSecurityZoneByName(securityZone.getName());
Mockito.verify(xXSecurityZoneDao, times(1)).findByZoneName(securityZone.getName());
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestSecurityZoneDBStore method test2updateSecurityZoneById.
@Test
public void test2updateSecurityZoneById() throws Exception {
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
RangerSecurityZone updateSecurityZone = new RangerSecurityZone();
updateSecurityZone.setId(2L);
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.findByZoneId(securityZone.getId())).thenReturn(xxSecurityZone);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
Mockito.when(securityZoneService.update(securityZone)).thenReturn(updateSecurityZone);
Mockito.doNothing().when(securityZoneRefUpdater).createNewZoneMappingForRefTable(updateSecurityZone);
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
RangerSecurityZone expectedSecurityZone = securityZoneDBStore.updateSecurityZoneById(securityZone);
Assert.assertNotNull(xxSecurityZone);
Assert.assertEquals(updateSecurityZone.getId(), expectedSecurityZone.getId());
Mockito.verify(daoManager).getXXSecurityZoneDao();
Mockito.verify(daoManager).getXXGlobalState();
Mockito.verify(securityZoneService).update(securityZone);
}
Aggregations