Search in sources :

Example 11 with XXSecurityZoneDao

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);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 12 with XXSecurityZoneDao

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());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 13 with XXSecurityZoneDao

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());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 14 with XXSecurityZoneDao

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);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Aggregations

XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)14 Test (org.junit.Test)14 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)12 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)12 ArrayList (java.util.ArrayList)9 WebApplicationException (javax.ws.rs.WebApplicationException)6 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)3 XXTrxLog (org.apache.ranger.entity.XXTrxLog)3 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 XXSecurityZoneRefServiceDao (org.apache.ranger.db.XXSecurityZoneRefServiceDao)2 XXSecurityZoneRefTagServiceDao (org.apache.ranger.db.XXSecurityZoneRefTagServiceDao)2