Search in sources :

Example 6 with RangerServiceDef

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

the class TestRangerServiceDefService method test4getAllServiceDefs.

@Test
public void test4getAllServiceDefs() {
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
    XXAccessTypeDefDao xAccessTypeDefDao = Mockito.mock(XXAccessTypeDefDao.class);
    XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
    XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
    XXContextEnricherDefDao xContextEnricherDefDao = Mockito.mock(XXContextEnricherDefDao.class);
    XXEnumDefDao xEnumDefDao = Mockito.mock(XXEnumDefDao.class);
    XXEnumElementDefDao xEnumElementDefDao = Mockito.mock(XXEnumElementDefDao.class);
    List<XXServiceDef> xServiceDefList = new ArrayList<XXServiceDef>();
    XXServiceDef serviceDef = new XXServiceDef();
    serviceDef.setAddedByUserId(Id);
    serviceDef.setCreateTime(new Date());
    serviceDef.setDescription("HDFS Repository");
    serviceDef.setGuid("1427365526516_835_0");
    serviceDef.setId(Id);
    serviceDef.setUpdateTime(new Date());
    serviceDef.setUpdatedByUserId(Id);
    serviceDef.setImplclassname("RangerServiceHdfs");
    serviceDef.setLabel("HDFS Repository");
    serviceDef.setRbkeylabel(null);
    serviceDef.setRbkeydescription(null);
    serviceDef.setIsEnabled(true);
    xServiceDefList.add(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<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<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<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.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getAll()).thenReturn(xServiceDefList);
    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);
    List<RangerServiceDef> dbRangerServiceDef = serviceDefService.getAllServiceDefs();
    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 7 with RangerServiceDef

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

the class TestRangerServiceDefServiceBase method test1MapViewToEntityBean.

@Test
public void test1MapViewToEntityBean() {
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    XXServiceDef serviceDef = serviceDef();
    int operationContext = 1;
    XXServiceDef dbServiceDef = rangerServiceDefService.mapViewToEntityBean(rangerServiceDef, serviceDef, operationContext);
    Assert.assertNotNull(dbServiceDef);
    Assert.assertEquals(dbServiceDef, serviceDef);
    Assert.assertEquals(dbServiceDef.getDescription(), serviceDef.getDescription());
    Assert.assertEquals(dbServiceDef.getGuid(), serviceDef.getGuid());
    Assert.assertEquals(dbServiceDef.getName(), serviceDef.getName());
    Assert.assertEquals(dbServiceDef.getAddedByUserId(), serviceDef.getAddedByUserId());
    Assert.assertEquals(dbServiceDef.getId(), serviceDef.getId());
    Assert.assertEquals(dbServiceDef.getVersion(), serviceDef.getVersion());
    Assert.assertEquals(dbServiceDef.getImplclassname(), serviceDef.getImplclassname());
    Assert.assertEquals(dbServiceDef.getUpdatedByUserId(), serviceDef.getUpdatedByUserId());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 8 with RangerServiceDef

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

the class TestRangerServiceDefServiceBase method test2MapEntityToViewBean.

@Test
public void test2MapEntityToViewBean() {
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    XXServiceDef serviceDef = serviceDef();
    RangerServiceDef dbRangerServiceDef = rangerServiceDefService.mapEntityToViewBean(rangerServiceDef, serviceDef);
    Assert.assertNotNull(dbRangerServiceDef);
    Assert.assertEquals(dbRangerServiceDef, rangerServiceDef);
    Assert.assertEquals(dbRangerServiceDef.getDescription(), rangerServiceDef.getDescription());
    Assert.assertEquals(dbRangerServiceDef.getGuid(), rangerServiceDef.getGuid());
    Assert.assertEquals(dbRangerServiceDef.getName(), rangerServiceDef.getName());
    Assert.assertEquals(dbRangerServiceDef.getId(), rangerServiceDef.getId());
    Assert.assertEquals(dbRangerServiceDef.getVersion(), rangerServiceDef.getVersion());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 9 with RangerServiceDef

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

the class TestAssetREST method servicePolicies.

private ServicePolicies servicePolicies() {
    RangerPolicy rangerPolicy = rangerPolicy(Id);
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    ServicePolicies servicePolicies = new ServicePolicies();
    List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
    policies.add(rangerPolicy);
    servicePolicies.setServiceId(Id);
    servicePolicies.setServiceName("Hdfs_1");
    servicePolicies.setPolicyVersion(1L);
    servicePolicies.setPolicyUpdateTime(new Date());
    servicePolicies.setServiceDef(rangerServiceDef);
    servicePolicies.setPolicies(policies);
    return servicePolicies;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 10 with RangerServiceDef

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

the class TestAssetREST 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)

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