Search in sources :

Example 16 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao in project ranger by apache.

the class TestPublicAPIs method test3updateRepository.

@Test
public void test3updateRepository() throws Exception {
    VXAsset vXAsset = new VXAsset();
    RangerService rangerService = rangerService();
    HttpServletRequest request = null;
    VXRepository vXRepository = vXRepository(rangerService);
    XXService xService = xService();
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    Mockito.when(daoMgr.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
    Mockito.when(serviceUtil.publicObjecttoVXAsset(vXRepository)).thenReturn(vXAsset);
    Mockito.when(serviceUtil.toRangerService(vXAsset)).thenReturn(rangerService);
    Mockito.when(serviceREST.updateService(rangerService, request)).thenReturn(rangerService);
    Mockito.when(serviceUtil.toVXAsset(rangerService)).thenReturn(vXAsset);
    Mockito.when(serviceUtil.vXAssetToPublicObject(vXAsset)).thenReturn(vXRepository);
    VXRepository dbVXRepository = publicAPIs.updateRepository(vXRepository, Id);
    Assert.assertNotNull(dbVXRepository);
    Assert.assertEquals(dbVXRepository, vXRepository);
    Assert.assertEquals(dbVXRepository.getId(), vXRepository.getId());
    Assert.assertEquals(dbVXRepository.getName(), vXRepository.getName());
    Mockito.verify(serviceREST).updateService(rangerService, request);
    Mockito.verify(serviceUtil).publicObjecttoVXAsset(vXRepository);
    Mockito.verify(serviceUtil).toRangerService(vXAsset);
    Mockito.verify(serviceUtil).toVXAsset(rangerService);
    Mockito.verify(serviceUtil).vXAssetToPublicObject(vXAsset);
    Mockito.verify(daoMgr).getXXService();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXAsset(org.apache.ranger.view.VXAsset) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) VXRepository(org.apache.ranger.view.VXRepository) Test(org.junit.Test)

Example 17 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao in project ranger by apache.

the class TestServiceREST method test19getPolicyFalse.

@Test
public void test19getPolicyFalse() throws Exception {
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(svcStore.getPolicy(rangerPolicy.getId())).thenReturn(rangerPolicy);
    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(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);
    RangerPolicy dbRangerPolicy = serviceREST.getPolicy(rangerPolicy.getId());
    Assert.assertNotNull(dbRangerPolicy);
    Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
    Mockito.verify(svcStore).getPolicy(rangerPolicy.getId());
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao 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();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXServiceDao(org.apache.ranger.db.XXServiceDao) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) XXService(org.apache.ranger.entity.XXService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao 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);
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao 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();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) Test(org.junit.Test)

Aggregations

XXServiceDao (org.apache.ranger.db.XXServiceDao)20 XXService (org.apache.ranger.entity.XXService)19 Test (org.junit.Test)17 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)13 XXServiceDef (org.apache.ranger.entity.XXServiceDef)13 RangerService (org.apache.ranger.plugin.model.RangerService)9 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)6 ExpectedException (org.junit.rules.ExpectedException)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)4 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)4 VXString (org.apache.ranger.view.VXString)4 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)3 XXPolicy (org.apache.ranger.entity.XXPolicy)3 XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1