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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations