use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestPublicAPIs method rangerPolicy.
private RangerPolicy rangerPolicy() {
List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
List<String> users = new ArrayList<String>();
List<String> groups = new ArrayList<String>();
List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
rangerPolicyItem.setAccesses(accesses);
rangerPolicyItem.setConditions(conditions);
rangerPolicyItem.setGroups(groups);
rangerPolicyItem.setUsers(users);
rangerPolicyItem.setDelegateAdmin(false);
policyItems.add(rangerPolicyItem);
Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
rangerPolicyResource.setIsExcludes(true);
rangerPolicyResource.setIsRecursive(true);
rangerPolicyResource.setValue("1");
rangerPolicyResource.setValues(users);
policyResource.put("resource", rangerPolicyResource);
RangerPolicy policy = new RangerPolicy();
policy.setId(Id);
policy.setCreateTime(new Date());
policy.setDescription("policy");
policy.setGuid("policyguid");
policy.setIsEnabled(true);
policy.setName("HDFS_1-1-20150316062453");
policy.setUpdatedBy("Admin");
policy.setUpdateTime(new Date());
policy.setService("HDFS_1-1-20150316062453");
policy.setIsAuditEnabled(true);
policy.setPolicyItems(policyItems);
policy.setResources(policyResource);
policy.setService("HDFS_1");
return policy;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestPublicAPIs method test12countPolicies.
@Test
public void test12countPolicies() throws Exception {
VXLong vXLong = new VXLong();
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);
vXLong.setValue(dbVXPolicyList.getResultSize());
Assert.assertNotNull(vXLong);
Assert.assertEquals(vXLong.getValue(), 1);
Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
Mockito.verify(serviceREST).getPolicies(filter);
Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestPublicAPIsv2 method test26getPolicies.
@Test
public void test26getPolicies() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerPolicyList policyList = Mockito.mock(RangerPolicyList.class);
List<RangerPolicy> rangerPolicies = new ArrayList<RangerPolicy>();
RangerPolicy rangerpolicy1 = rangerPolicy();
RangerPolicy rangerpolicy2 = rangerPolicy1();
rangerPolicies.add(rangerpolicy1);
rangerPolicies.add(rangerpolicy2);
Mockito.when(serviceREST.getPolicies(request)).thenReturn(policyList);
Mockito.when(policyList.getPolicies()).thenReturn(rangerPolicies);
List<RangerPolicy> dbRangerPolicies = publicAPIsv2.getPolicies(request);
Assert.assertNotNull(dbRangerPolicies);
Assert.assertEquals(dbRangerPolicies.size(), rangerPolicies.size());
Mockito.verify(serviceREST).getPolicies(request);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestPublicAPIsv2 method test21applyPolicy.
@Test
public void test21applyPolicy() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerPolicy rangerPolicy = rangerPolicy();
Mockito.when(serviceREST.applyPolicy(rangerPolicy, request)).thenReturn(rangerPolicy);
RangerPolicy dbRangerPolicy = publicAPIsv2.applyPolicy(rangerPolicy, request);
Assert.assertNotNull(dbRangerPolicy);
Assert.assertEquals(dbRangerPolicy, rangerPolicy);
Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName());
Mockito.verify(serviceREST).applyPolicy(rangerPolicy, request);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestPublicAPIsv2 method test19searchPolicies.
@Test
public void test19searchPolicies() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
List<RangerPolicy> policiesList = new ArrayList<RangerPolicy>();
RangerService service = rangerService();
String serviceName = service.getName();
RangerPolicy rangerPolicy = rangerPolicy();
policiesList.add(rangerPolicy);
RangerPolicyList policyList = new RangerPolicyList(policiesList);
Mockito.when(serviceREST.getServicePoliciesByName(serviceName, request)).thenReturn(policyList);
List<RangerPolicy> dbRangerPolicyList = publicAPIsv2.searchPolicies(serviceName, request);
Assert.assertNotNull(dbRangerPolicyList);
Assert.assertEquals(dbRangerPolicyList.size(), policiesList.size());
Mockito.verify(serviceREST).getServicePoliciesByName(serviceName, request);
}
Aggregations