Search in sources :

Example 91 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestServiceDBStore method test16getServiceDefByNameNotNull.

@Test
public void test16getServiceDefByNameNotNull() throws Exception {
    String name = "fdfdfds";
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    RangerServiceDef serviceDef = new RangerServiceDef();
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.findByName(name)).thenReturn(xServiceDef);
    Mockito.when(serviceDefService.getPopulatedViewObject(xServiceDef)).thenReturn(serviceDef);
    RangerServiceDef dbServiceDef = serviceDBStore.getServiceDefByName(name);
    Assert.assertNotNull(dbServiceDef);
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 92 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestServiceDBStore method test15getServiceDefByName.

@Test
public void test15getServiceDefByName() throws Exception {
    String name = "fdfdfds";
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.findByName(name)).thenReturn(xServiceDef);
    RangerServiceDef dbServiceDef = serviceDBStore.getServiceDefByName(name);
    Assert.assertNull(dbServiceDef);
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 93 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestServiceDBStore method test14getServiceDef.

@Test
public void test14getServiceDef() throws Exception {
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    Mockito.when(serviceDefService.read(Id)).thenReturn(rangerServiceDef);
    RangerServiceDef dbRangerServiceDef = serviceDBStore.getServiceDef(Id);
    Assert.assertNotNull(dbRangerServiceDef);
    Assert.assertEquals(dbRangerServiceDef, rangerServiceDef);
    Assert.assertEquals(dbRangerServiceDef.getId(), rangerServiceDef.getId());
    Assert.assertEquals(dbRangerServiceDef.getCreatedBy(), rangerServiceDef.getCreatedBy());
    Assert.assertEquals(dbRangerServiceDef.getDescription(), rangerServiceDef.getDescription());
    Assert.assertEquals(dbRangerServiceDef.getGuid(), rangerServiceDef.getGuid());
    Assert.assertEquals(dbRangerServiceDef.getImplClass(), rangerServiceDef.getImplClass());
    Assert.assertEquals(dbRangerServiceDef.getLabel(), rangerServiceDef.getLabel());
    Assert.assertEquals(dbRangerServiceDef.getName(), rangerServiceDef.getName());
    Assert.assertEquals(dbRangerServiceDef.getRbKeyDescription(), rangerServiceDef.getRbKeyDescription());
    Assert.assertEquals(dbRangerServiceDef.getConfigs(), rangerServiceDef.getConfigs());
    Assert.assertEquals(dbRangerServiceDef.getVersion(), rangerServiceDef.getVersion());
    Assert.assertEquals(dbRangerServiceDef.getResources(), rangerServiceDef.getResources());
    Mockito.verify(serviceDefService).read(Id);
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 94 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestServiceDBStore method test17getServiceDefs.

@Test
public void test17getServiceDefs() throws Exception {
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    List<RangerServiceDef> serviceDefsList = new ArrayList<RangerServiceDef>();
    RangerServiceDef serviceDef = rangerServiceDef();
    serviceDefsList.add(serviceDef);
    RangerServiceDefList serviceDefList = new RangerServiceDefList();
    serviceDefList.setPageSize(0);
    serviceDefList.setResultSize(1);
    serviceDefList.setSortBy("asc");
    serviceDefList.setSortType("1");
    serviceDefList.setStartIndex(0);
    serviceDefList.setTotalCount(10);
    serviceDefList.setServiceDefs(serviceDefsList);
    Mockito.when(serviceDefService.searchRangerServiceDefs(filter)).thenReturn(serviceDefList);
    List<RangerServiceDef> dbServiceDef = serviceDBStore.getServiceDefs(filter);
    Assert.assertNotNull(dbServiceDef);
    Assert.assertEquals(dbServiceDef, serviceDefsList);
    Assert.assertEquals(dbServiceDef.get(0), serviceDefsList.get(0));
    Mockito.verify(serviceDefService).searchRangerServiceDefs(filter);
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Test(org.junit.Test)

Example 95 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestServiceDBStore method test19createService.

@Test
public void test19createService() throws Exception {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
    XXUserDao xUserDao = Mockito.mock(XXUserDao.class);
    XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
    XXService xService = Mockito.mock(XXService.class);
    RangerService rangerService = rangerService();
    List<XXServiceConfigDef> svcConfDefList = new ArrayList<XXServiceConfigDef>();
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    serviceConfigDefObj.setId(Id);
    serviceConfigDefObj.setType("1");
    svcConfDefList.add(serviceConfigDefObj);
    Mockito.when(daoManager.getXXServiceConfigDef()).thenReturn(xServiceConfigDefDao);
    Mockito.when(svcService.create(rangerService)).thenReturn(rangerService);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(rangerService.getId())).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
    Mockito.when(daoManager.getXXUser()).thenReturn(xUserDao);
    XXServiceConfigMap xConfMap = new XXServiceConfigMap();
    Mockito.when(svcService.getPopulatedViewObject(xService)).thenReturn(rangerService);
    Mockito.when(rangerAuditFields.populateAuditFields(Mockito.isA(XXServiceConfigMap.class), Mockito.isA(XXService.class))).thenReturn(xConfMap);
    RangerServiceDef ran = new RangerServiceDef();
    ran.setName("Test");
    ServiceDBStore spy = Mockito.spy(serviceDBStore);
    Mockito.doNothing().when(spy).createDefaultPolicies(rangerService);
    spy.createService(rangerService);
    Mockito.verify(daoManager, Mockito.atLeast(1)).getXXService();
    Mockito.verify(daoManager).getXXServiceConfigMap();
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Aggregations

RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)105 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)38 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 XXServiceDef (org.apache.ranger.entity.XXServiceDef)18 Date (java.util.Date)15 HashMap (java.util.HashMap)13 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)13 RangerService (org.apache.ranger.plugin.model.RangerService)12 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)12 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)12 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)11 VXString (org.apache.ranger.view.VXString)10 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)9 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)9 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)9 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)8 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)8 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)8 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)7