use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestServiceREST method test4getServiceDefById.
@Test
public void test4getServiceDefById() throws Exception {
RangerServiceDef rangerServiceDef = rangerServiceDef();
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(Id)).thenReturn(xServiceDef);
Mockito.when(!bizUtil.hasAccess(xServiceDef, null)).thenReturn(true);
Mockito.when(svcStore.getServiceDef(rangerServiceDef.getId())).thenReturn(rangerServiceDef);
RangerServiceDef dbRangerServiceDef = serviceREST.getServiceDef(rangerServiceDef.getId());
Assert.assertNotNull(dbRangerServiceDef);
Assert.assertEquals(dbRangerServiceDef.getId(), rangerServiceDef.getId());
Mockito.verify(svcStore).getServiceDef(rangerServiceDef.getId());
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(bizUtil).hasAccess(xServiceDef, null);
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestServiceREST method test16createPolicyFalse.
@Test
public void test16createPolicyFalse() throws Exception {
RangerPolicy rangerPolicy = rangerPolicy();
RangerServiceDef rangerServiceDef = rangerServiceDef();
List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
RangerPolicy rangPolicy = new RangerPolicy();
policies.add(rangPolicy);
String userName = "admin";
Set<String> userGroupsList = new HashSet<String>();
userGroupsList.add("group1");
userGroupsList.add("group2");
ServicePolicies servicePolicies = new ServicePolicies();
servicePolicies.setServiceId(Id);
servicePolicies.setServiceName("Hdfs_1");
servicePolicies.setPolicyVersion(1L);
servicePolicies.setPolicyUpdateTime(new Date());
servicePolicies.setServiceDef(rangerServiceDef);
servicePolicies.setPolicies(policies);
List<RangerAccessTypeDef> rangerAccessTypeDefList = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
rangerAccessTypeDefObj.setLabel("Read");
rangerAccessTypeDefObj.setName("read");
rangerAccessTypeDefObj.setRbKeyLabel(null);
rangerAccessTypeDefList.add(rangerAccessTypeDefObj);
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(Mockito.anyString())).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(svcStore.createPolicy((RangerPolicy) Mockito.any())).thenReturn(rangPolicy);
RangerPolicy dbRangerPolicy = serviceREST.createPolicy(rangerPolicy, null);
Assert.assertNotNull(dbRangerPolicy);
Mockito.verify(bizUtil, Mockito.times(2)).isAdmin();
Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
Mockito.verify(daoManager).getXXService();
Mockito.verify(daoManager).getXXServiceDef();
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestServiceREST method test18deletePolicyFalse.
@Test
public void test18deletePolicyFalse() throws Exception {
RangerPolicy rangerPolicy = rangerPolicy();
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
String userName = "admin";
Set<String> userGroupsList = new HashSet<String>();
userGroupsList.add("group1");
userGroupsList.add("group2");
List<RangerAccessTypeDef> rangerAccessTypeDefList = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
rangerAccessTypeDefObj.setLabel("Read");
rangerAccessTypeDefObj.setName("read");
rangerAccessTypeDefObj.setRbKeyLabel(null);
rangerAccessTypeDefList.add(rangerAccessTypeDefObj);
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);
Mockito.when(svcStore.getPolicy(Id)).thenReturn(rangerPolicy);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(Mockito.anyString())).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
serviceREST.deletePolicy(rangerPolicy.getId());
Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestServiceREST method test9deleteService.
@Test
public void test9deleteService() throws Exception {
RangerService rangerService = rangerService();
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getServiceValidator(svcStore)).thenReturn(serviceValidator);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
serviceREST.deleteService(rangerService.getId());
Mockito.verify(validatorFactory).getServiceValidator(svcStore);
Mockito.verify(daoManager).getXXService();
Mockito.verify(daoManager).getXXServiceDef();
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestServiceREST method test3deleteServiceDef.
@Test
public void test3deleteServiceDef() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerServiceDef rangerServiceDef = rangerServiceDef();
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(validatorFactory.getServiceDefValidator(svcStore)).thenReturn(serviceDefValidator);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(Id)).thenReturn(xServiceDef);
serviceREST.deleteServiceDef(rangerServiceDef.getId(), request);
Mockito.verify(validatorFactory).getServiceDefValidator(svcStore);
Mockito.verify(daoManager).getXXServiceDef();
}
Aggregations