Search in sources :

Example 86 with RangerServiceDef

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

the class TestRangerServiceDefService method test5getPopulatedViewObject.

@Test
public void test5getPopulatedViewObject() {
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
    XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
    XXAccessTypeDefDao xAccessTypeDefDao = Mockito.mock(XXAccessTypeDefDao.class);
    XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
    XXContextEnricherDefDao xContextEnricherDefDao = Mockito.mock(XXContextEnricherDefDao.class);
    XXEnumDefDao xEnumDefDao = Mockito.mock(XXEnumDefDao.class);
    XXEnumElementDefDao xEnumElementDefDao = Mockito.mock(XXEnumElementDefDao.class);
    XXServiceDef serviceDef = serviceDef();
    String name = "fdfdfds";
    XXPortalUser tUser = new XXPortalUser();
    tUser.setAddedByUserId(Id);
    tUser.setCreateTime(new Date());
    tUser.setEmailAddress("test@gmail.com");
    tUser.setFirstName(name);
    tUser.setId(Id);
    tUser.setLastName(name);
    List<XXServiceConfigDef> serviceConfigDefList = new ArrayList<XXServiceConfigDef>();
    XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
    serviceConfigDefObj.setAddedByUserId(Id);
    serviceConfigDefObj.setCreateTime(new Date());
    serviceConfigDefObj.setDefaultvalue("simple");
    serviceConfigDefObj.setDescription("service config");
    serviceConfigDefObj.setId(Id);
    serviceConfigDefObj.setIsMandatory(true);
    serviceConfigDefObj.setName(name);
    serviceConfigDefObj.setLabel("username");
    serviceConfigDefObj.setRbkeydescription(null);
    serviceConfigDefObj.setRbkeylabel(null);
    serviceConfigDefObj.setRbKeyValidationMessage(null);
    serviceConfigDefObj.setType("password");
    serviceConfigDefList.add(serviceConfigDefObj);
    List<XXResourceDef> resDefList = new ArrayList<XXResourceDef>();
    XXResourceDef resourceDef = new XXResourceDef();
    resourceDef.setAddedByUserId(Id);
    resourceDef.setCreateTime(new Date());
    resourceDef.setDefid(Id);
    resourceDef.setDescription("test");
    resourceDef.setId(Id);
    resDefList.add(resourceDef);
    List<XXPolicyItem> xPolicyItemList = new ArrayList<XXPolicyItem>();
    XXPolicyItem xPolicyItem = new XXPolicyItem();
    xPolicyItem.setDelegateAdmin(false);
    xPolicyItem.setAddedByUserId(null);
    xPolicyItem.setCreateTime(new Date());
    xPolicyItem.setGUID(null);
    xPolicyItem.setId(Id);
    xPolicyItem.setOrder(null);
    xPolicyItem.setPolicyId(Id);
    xPolicyItem.setUpdatedByUserId(null);
    xPolicyItem.setUpdateTime(new Date());
    xPolicyItemList.add(xPolicyItem);
    List<XXPolicyItemAccess> policyItemAccessList = new ArrayList<XXPolicyItemAccess>();
    XXPolicyItemAccess policyItemAccess = new XXPolicyItemAccess();
    policyItemAccess.setAddedByUserId(Id);
    policyItemAccess.setCreateTime(new Date());
    policyItemAccess.setPolicyitemid(Id);
    policyItemAccess.setId(Id);
    policyItemAccess.setOrder(1);
    policyItemAccess.setUpdatedByUserId(Id);
    policyItemAccess.setUpdateTime(new Date());
    policyItemAccessList.add(policyItemAccess);
    List<XXPolicyConditionDef> xConditionDefList = new ArrayList<XXPolicyConditionDef>();
    XXPolicyConditionDef policyConditionDefObj = new XXPolicyConditionDef();
    policyConditionDefObj.setAddedByUserId(Id);
    policyConditionDefObj.setCreateTime(new Date());
    policyConditionDefObj.setDefid(Id);
    policyConditionDefObj.setDescription("policy conditio");
    policyConditionDefObj.setId(Id);
    policyConditionDefObj.setName(name);
    policyConditionDefObj.setOrder(1);
    policyConditionDefObj.setLabel("label");
    xConditionDefList.add(policyConditionDefObj);
    List<XXPolicyItemCondition> policyItemConditionList = new ArrayList<XXPolicyItemCondition>();
    XXPolicyItemCondition policyItemCondition = new XXPolicyItemCondition();
    policyItemCondition.setAddedByUserId(Id);
    policyItemCondition.setCreateTime(new Date());
    policyItemCondition.setType(1L);
    policyItemCondition.setId(Id);
    policyItemCondition.setOrder(1);
    policyItemCondition.setPolicyItemId(Id);
    policyItemCondition.setUpdatedByUserId(Id);
    policyItemCondition.setUpdateTime(new Date());
    policyItemConditionList.add(policyItemCondition);
    List<XXContextEnricherDef> contextEnrichersList = new ArrayList<XXContextEnricherDef>();
    XXContextEnricherDef contextEnricherDefObj = new XXContextEnricherDef();
    contextEnricherDefObj.setAddedByUserId(Id);
    contextEnricherDefObj.setCreateTime(new Date());
    contextEnricherDefObj.setDefid(Id);
    contextEnricherDefObj.setEnricher("RangerCountryProvider");
    contextEnricherDefObj.setName("country-provider");
    contextEnricherDefObj.setId(Id);
    contextEnricherDefObj.setOrder(0);
    contextEnricherDefObj.setUpdatedByUserId(Id);
    contextEnricherDefObj.setUpdateTime(new Date());
    contextEnrichersList.add(contextEnricherDefObj);
    List<XXEnumDef> xEnumList = new ArrayList<XXEnumDef>();
    XXEnumDef enumDefObj = new XXEnumDef();
    enumDefObj.setAddedByUserId(Id);
    enumDefObj.setCreateTime(new Date());
    enumDefObj.setDefaultindex(null);
    enumDefObj.setDefid(Id);
    enumDefObj.setId(Id);
    enumDefObj.setName(name);
    enumDefObj.setUpdatedByUserId(Id);
    enumDefObj.setUpdateTime(new Date());
    xEnumList.add(enumDefObj);
    List<XXEnumElementDef> xElementsList = new ArrayList<XXEnumElementDef>();
    XXEnumElementDef enumElementDefObj = new XXEnumElementDef();
    enumElementDefObj.setAddedByUserId(Id);
    enumElementDefObj.setCreateTime(new Date());
    enumElementDefObj.setEnumdefid(Id);
    enumElementDefObj.setId(Id);
    enumElementDefObj.setLabel("Authentication");
    enumElementDefObj.setName("authentication");
    enumElementDefObj.setUpdateTime(new Date());
    enumElementDefObj.setUpdatedByUserId(Id);
    enumElementDefObj.setRbkeylabel(null);
    enumElementDefObj.setOrder(0);
    xElementsList.add(enumElementDefObj);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    Mockito.when(xPortalUserDao.getById(Id)).thenReturn(tUser);
    Mockito.when(daoManager.getXXServiceConfigDef()).thenReturn(xServiceConfigDefDao);
    Mockito.when(xServiceConfigDefDao.findByServiceDefId(serviceDef.getId())).thenReturn(serviceConfigDefList);
    Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
    Mockito.when(daoManager.getXXAccessTypeDef()).thenReturn(xAccessTypeDefDao);
    Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
    Mockito.when(daoManager.getXXContextEnricherDef()).thenReturn(xContextEnricherDefDao);
    Mockito.when(xContextEnricherDefDao.findByServiceDefId(serviceDef.getId())).thenReturn(contextEnrichersList);
    Mockito.when(daoManager.getXXEnumDef()).thenReturn(xEnumDefDao);
    Mockito.when(xEnumDefDao.findByServiceDefId(serviceDef.getId())).thenReturn(xEnumList);
    Mockito.when(daoManager.getXXEnumElementDef()).thenReturn(xEnumElementDefDao);
    Mockito.when(xEnumElementDefDao.findByEnumDefId(enumElementDefObj.getId())).thenReturn(xElementsList);
    XXDataMaskTypeDefDao xDataMaskTypeDao = Mockito.mock(XXDataMaskTypeDefDao.class);
    List<XXDataMaskTypeDef> xDataMaskTypeDefs = new ArrayList<XXDataMaskTypeDef>();
    Mockito.when(daoManager.getXXDataMaskTypeDef()).thenReturn(xDataMaskTypeDao);
    Mockito.when(xDataMaskTypeDao.findByServiceDefId(serviceDef.getId())).thenReturn(xDataMaskTypeDefs);
    RangerServiceDef dbRangerServiceDef = serviceDefService.getPopulatedViewObject(serviceDef);
    Assert.assertNotNull(dbRangerServiceDef);
    Mockito.verify(daoManager).getXXServiceConfigDef();
    Mockito.verify(daoManager).getXXResourceDef();
    Mockito.verify(daoManager).getXXAccessTypeDef();
    Mockito.verify(daoManager).getXXPolicyConditionDef();
    Mockito.verify(daoManager).getXXContextEnricherDef();
    Mockito.verify(daoManager).getXXEnumDef();
    Mockito.verify(daoManager).getXXEnumElementDef();
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 87 with RangerServiceDef

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

the class TestRangerServiceDefService method test1ValidateForCreate.

@Test
public void test1ValidateForCreate() {
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    serviceDefService.validateForCreate(rangerServiceDef);
    Assert.assertNotNull(rangerServiceDef);
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 88 with RangerServiceDef

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

the class TestRangerServiceDefServiceBase method rangerServiceDef.

private RangerServiceDef rangerServiceDef() {
    List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
    List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
    List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
    List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
    List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
    List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
    RangerServiceDef rangerServiceDef = new RangerServiceDef();
    rangerServiceDef.setId(Id);
    rangerServiceDef.setImplClass("RangerServiceHdfs");
    rangerServiceDef.setLabel("HDFS Repository");
    rangerServiceDef.setDescription("HDFS Repository");
    rangerServiceDef.setRbKeyDescription(null);
    rangerServiceDef.setUpdatedBy("Admin");
    rangerServiceDef.setUpdateTime(new Date());
    rangerServiceDef.setConfigs(configs);
    rangerServiceDef.setResources(resources);
    rangerServiceDef.setAccessTypes(accessTypes);
    rangerServiceDef.setPolicyConditions(policyConditions);
    rangerServiceDef.setContextEnrichers(contextEnrichers);
    rangerServiceDef.setEnums(enums);
    return rangerServiceDef;
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) ArrayList(java.util.ArrayList) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 89 with RangerServiceDef

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

the class TestServiceREST method test7getServiceDefs.

@Test
public void test7getServiceDefs() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilter(request, serviceDefService.sortFields)).thenReturn(filter);
    List<RangerServiceDef> serviceDefsList = new ArrayList<RangerServiceDef>();
    RangerServiceDef serviceDef = rangerServiceDef();
    serviceDefsList.add(serviceDef);
    PList<RangerServiceDef> serviceDefList = new PList<RangerServiceDef>();
    serviceDefList.setPageSize(0);
    serviceDefList.setResultSize(1);
    serviceDefList.setSortBy("asc");
    serviceDefList.setSortType("1");
    serviceDefList.setStartIndex(0);
    serviceDefList.setTotalCount(10);
    serviceDefList.setList(serviceDefsList);
    Mockito.when(svcStore.getPaginatedServiceDefs(filter)).thenReturn(serviceDefList);
    RangerServiceDefList dbRangerServiceDef = serviceREST.getServiceDefs(request);
    Assert.assertNotNull(dbRangerServiceDef);
    Mockito.verify(searchUtil).getSearchFilter(request, serviceDefService.sortFields);
    Mockito.verify(svcStore).getPaginatedServiceDefs(filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PList(org.apache.ranger.plugin.store.PList) 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 90 with RangerServiceDef

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

the class TestServiceDBStore method test18getPaginatedServiceDefs.

@Test
public void test18getPaginatedServiceDefs() 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);
    PList<RangerServiceDef> dbServiceDefList = serviceDBStore.getPaginatedServiceDefs(filter);
    Assert.assertNotNull(dbServiceDefList);
    Assert.assertEquals(dbServiceDefList.getList(), serviceDefList.getServiceDefs());
    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)

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