Search in sources :

Example 66 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone 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 67 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone 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 68 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone 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

RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)68 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)27 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)16 WebApplicationException (javax.ws.rs.WebApplicationException)14 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)12 RangerService (org.apache.ranger.plugin.model.RangerService)11 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)10 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)10 XXTrxLog (org.apache.ranger.entity.XXTrxLog)9 RangerSecurityZoneService (org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService)7 HashMap (java.util.HashMap)6 ValidationErrorCode (org.apache.ranger.plugin.errors.ValidationErrorCode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)3