use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestAssetREST method testSearchXResource.
@Test
public void testSearchXResource() {
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
List<VXResource> vXResourcesList = new ArrayList<VXResource>();
RangerService rangerService = rangerService(Id);
long i;
for (i = 1; i <= 2; i++) {
RangerPolicy rangerPolicy = rangerPolicy(i);
VXResource vXresource = vxResource(i);
rangerPolicyList.add(rangerPolicy);
vXResourcesList.add(vXresource);
Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource);
}
Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService);
VXResourceList expectedVXResourceList = new VXResourceList();
expectedVXResourceList.setVXResources(vXResourcesList);
SearchFilter searchFilter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter);
Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList);
VXResourceList actualVXResourceList = assetREST.searchXResources(request);
Assert.assertNotNull(actualVXResourceList);
Assert.assertEquals(expectedVXResourceList.getVXResources(), actualVXResourceList.getVXResources());
Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, null);
Mockito.verify(serviceREST).getPolicies(searchFilter);
for (i = 0; i < 2; i++) {
Mockito.verify(serviceUtil, Mockito.times(1)).toVXResource(rangerPolicyList.get((int) i), rangerService);
}
Mockito.verify(serviceREST, Mockito.times(2)).getServiceByName(rangerPolicyList.get(0).getService());
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestPublicAPIs method test6countRepositories.
@Test
public void test6countRepositories() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
VXLong vXLong = new VXLong();
List<RangerService> ret = new ArrayList<RangerService>();
RangerService rangerService = rangerService();
VXRepository vXRepository = vXRepository(rangerService);
List<VXRepository> repoList = new ArrayList<VXRepository>();
repoList.add(vXRepository);
VXRepositoryList vXRepositoryList = new VXRepositoryList(repoList);
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields)).thenReturn(filter);
Mockito.when(serviceREST.getServices(filter)).thenReturn(ret);
Mockito.when(serviceUtil.rangerServiceListToPublicObjectList(ret)).thenReturn(vXRepositoryList);
VXRepositoryList dbVXRepositoryList = publicAPIs.searchRepositories(request);
vXLong.setValue(dbVXRepositoryList.getResultSize());
Assert.assertNotNull(vXLong);
Assert.assertEquals(vXLong.getValue(), 1);
Mockito.verify(searchUtil).getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields);
Mockito.verify(serviceREST).getServices(filter);
Mockito.verify(serviceUtil).rangerServiceListToPublicObjectList(ret);
}
use of org.apache.ranger.plugin.util.SearchFilter 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.util.SearchFilter in project ranger by apache.
the class TestPublicAPIs method test5searchRepositories.
@Test
public void test5searchRepositories() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
List<RangerService> ret = new ArrayList<RangerService>();
RangerService rangerService = rangerService();
VXRepository vXRepository = vXRepository(rangerService);
List<VXRepository> repoList = new ArrayList<VXRepository>();
repoList.add(vXRepository);
VXRepositoryList vXRepositoryList = new VXRepositoryList(repoList);
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields)).thenReturn(filter);
Mockito.when(serviceREST.getServices(filter)).thenReturn(ret);
Mockito.when(serviceUtil.rangerServiceListToPublicObjectList(ret)).thenReturn(vXRepositoryList);
VXRepositoryList dbVXRepositoryList = publicAPIs.searchRepositories(request);
Assert.assertNotNull(dbVXRepositoryList);
Assert.assertEquals(dbVXRepositoryList.getResultSize(), vXRepositoryList.getResultSize());
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestServiceREST method test20getPolicies.
@Test
public void test20getPolicies() 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, policyService.sortFields)).thenReturn(filter);
RangerPolicyList dbRangerPolicy = serviceREST.getPolicies(request);
Assert.assertNotNull(dbRangerPolicy);
Assert.assertEquals(dbRangerPolicy.getListSize(), 0);
Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
}
Aggregations