Search in sources :

Example 11 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestAssetREST method vXPolicy.

private VXPolicy vXPolicy(RangerPolicy policy, RangerService service) {
    VXPolicy ret = new VXPolicy();
    ret.setPolicyName(StringUtils.trim(policy.getName()));
    ret.setDescription(policy.getDescription());
    ret.setRepositoryName(policy.getService());
    ret.setIsEnabled(policy.getIsEnabled() ? true : false);
    ret.setRepositoryType(service.getType());
    ret.setIsAuditEnabled(policy.getIsAuditEnabled());
    return ret;
}
Also used : VXPolicy(org.apache.ranger.view.VXPolicy)

Example 12 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestPublicAPIs method test8createPolicy.

@Test
public void test8createPolicy() throws Exception {
    RangerPolicy policy = rangerPolicy();
    RangerService service = rangerService();
    VXPolicy vXPolicy = vXPolicy(policy, service);
    Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service);
    Mockito.when(serviceUtil.toRangerPolicy(vXPolicy, service)).thenReturn(policy);
    Mockito.when(serviceREST.createPolicy(policy, null)).thenReturn(policy);
    Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy);
    VXPolicy dbVXPolicy = publicAPIs.createPolicy(vXPolicy);
    Assert.assertNotNull(dbVXPolicy);
    Assert.assertEquals(dbVXPolicy, vXPolicy);
    Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId());
    Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName());
    Mockito.verify(serviceREST).createPolicy(policy, null);
    Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName());
    Mockito.verify(serviceUtil).toVXPolicy(policy, service);
    Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy, service);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 13 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestPublicAPIs method test9updatePolicy.

@Test
public void test9updatePolicy() throws Exception {
    RangerPolicy policy = rangerPolicy();
    RangerService service = rangerService();
    VXPolicy vXPolicy = vXPolicy(policy, service);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    XXPolicy xXPolicy = policy();
    Mockito.when(daoMgr.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.getById(Id)).thenReturn(xXPolicy);
    Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service);
    Mockito.when(serviceUtil.toRangerPolicy(vXPolicy, service)).thenReturn(policy);
    Mockito.when(serviceREST.updatePolicy(policy)).thenReturn(policy);
    Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy);
    VXPolicy dbVXPolicy = publicAPIs.updatePolicy(vXPolicy, Id);
    Assert.assertNotNull(dbVXPolicy);
    Assert.assertEquals(dbVXPolicy, vXPolicy);
    Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId());
    Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName());
    Mockito.verify(serviceREST).updatePolicy(policy);
    Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName());
    Mockito.verify(serviceUtil).toVXPolicy(policy, service);
    Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy, service);
    Mockito.verify(daoMgr).getXXPolicy();
    Mockito.verify(xXPolicyDao).getById(Id);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicy(org.apache.ranger.view.VXPolicy) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Example 14 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestPublicAPIs method test11searchPolicies.

@Test
public void test11searchPolicies() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerService service = rangerService();
    RangerPolicy policy = rangerPolicy();
    List<RangerPolicy> policyList = new ArrayList<RangerPolicy>();
    policyList.add(policy);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>();
    vXPolicies.add(vXPolicy);
    VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    filter.setStartIndex(0);
    filter.setMaxRows(10);
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList);
    Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList, filter)).thenReturn(vXPolicyList);
    VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request);
    Assert.assertNotNull(dbVXPolicyList);
    Assert.assertEquals(dbVXPolicyList.getResultSize(), vXPolicyList.getResultSize());
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    Mockito.verify(serviceREST).getPolicies(filter);
    Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicyList(org.apache.ranger.view.VXPolicyList) ArrayList(java.util.ArrayList) VXPolicy(org.apache.ranger.view.VXPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 15 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestPublicAPIs method test7getPolicy.

@Test
public void test7getPolicy() throws Exception {
    RangerPolicy policy = rangerPolicy();
    RangerService service = rangerService();
    VXPolicy vXPolicy = vXPolicy(policy, service);
    Mockito.when(serviceREST.getPolicy(policy.getId())).thenReturn(policy);
    Mockito.when(serviceREST.getServiceByName(policy.getService())).thenReturn(service);
    Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy);
    VXPolicy dbVXPolicy = publicAPIs.getPolicy(Id);
    Assert.assertNotNull(dbVXPolicy);
    Assert.assertEquals(dbVXPolicy, vXPolicy);
    Assert.assertEquals(dbVXPolicy.getPolicyName(), vXPolicy.getPolicyName());
    Assert.assertEquals(dbVXPolicy.getRepositoryType(), vXPolicy.getRepositoryType());
    Mockito.verify(serviceREST).getPolicy(Id);
    Mockito.verify(serviceREST).getServiceByName(policy.getService());
    Mockito.verify(serviceUtil).toVXPolicy(policy, service);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Aggregations

VXPolicy (org.apache.ranger.view.VXPolicy)16 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)11 RangerService (org.apache.ranger.plugin.model.RangerService)10 Test (org.junit.Test)9 WebApplicationException (javax.ws.rs.WebApplicationException)5 ArrayList (java.util.ArrayList)4 GrantRevokeRequest (org.apache.ranger.plugin.util.GrantRevokeRequest)4 VXPolicyList (org.apache.ranger.view.VXPolicyList)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 VXPermObj (org.apache.ranger.view.VXPermObj)2 VXResource (org.apache.ranger.view.VXResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InvalidNameException (javax.naming.InvalidNameException)1 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1 RangerServiceNotFoundException (org.apache.ranger.plugin.util.RangerServiceNotFoundException)1 VXAuditMap (org.apache.ranger.view.VXAuditMap)1