use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestRangerValidator method test_getPolicies.
@Test
public void test_getPolicies() throws Exception {
// returns null when store returns null
String policyName = "aPolicy";
String serviceName = "aService";
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, policyName);
filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
when(_store.getPolicies(filter)).thenReturn(null);
List<RangerPolicy> result = _validator.getPolicies(serviceName, policyName);
// validate store is queried with both parameters
verify(_store).getPolicies(filter);
Assert.assertNull(result);
// returns null if store throws an exception
when(_store.getPolicies(filter)).thenThrow(new Exception());
result = _validator.getPolicies(serviceName, policyName);
Assert.assertNull(result);
// does not shove policy into search filter if policy name passed in is "blank"
filter = new SearchFilter();
filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
List<RangerPolicy> policies = new ArrayList<>();
RangerPolicy policy = mock(RangerPolicy.class);
policies.add(policy);
when(_store.getPolicies(filter)).thenReturn(policies);
for (String aName : new String[] { null, "", " " }) {
result = _validator.getPolicies(serviceName, aName);
Assert.assertTrue(result.iterator().next() == policy);
}
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class RangerValidator method getPolicies.
List<RangerPolicy> getPolicies(final String serviceName, final String policyName) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerValidator.getPolicies(" + serviceName + ", " + policyName + ")");
}
List<RangerPolicy> policies = null;
try {
SearchFilter filter = new SearchFilter();
if (StringUtils.isNotBlank(policyName)) {
filter.setParam(SearchFilter.POLICY_NAME, policyName);
}
filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
policies = _store.getPolicies(filter);
} catch (Exception e) {
LOG.debug("Encountred exception while retrieving service from service store!", e);
}
if (LOG.isDebugEnabled()) {
int count = policies == null ? 0 : policies.size();
LOG.debug("<== RangerValidator.getPolicies(" + serviceName + ", " + policyName + "): count[" + count + "], " + policies);
}
return policies;
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestServiceREST method test23getServicePoliciesByName.
@Test
public void test23getServicePoliciesByName() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerPolicy rangerPolicy = rangerPolicy();
List<RangerPolicy> ret = Mockito.mock(List.class);
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(svcStore.getServicePolicies(rangerPolicy.getName(), filter)).thenReturn(ret);
RangerPolicyList dbRangerPolicy = serviceREST.getServicePoliciesByName(rangerPolicy.getName(), request);
Assert.assertNotNull(dbRangerPolicy);
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestServiceREST method test44getPolicyLabels.
@Test
public void test44getPolicyLabels() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchFilter filter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilter(request, policyLabelsService.sortFields)).thenReturn(filter);
List<String> ret = new ArrayList<String>();
Mockito.when(svcStore.getPolicyLabels(filter)).thenReturn(ret);
ret = serviceREST.getPolicyLabels(request);
Assert.assertNotNull(ret);
Mockito.verify(searchUtil).getSearchFilter(request, policyLabelsService.sortFields);
}
use of org.apache.ranger.plugin.util.SearchFilter 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);
}
Aggregations