Search in sources :

Example 56 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class TestAssetREST method testCountXAssets.

@Test
public void testCountXAssets() {
    RangerService rangerService1 = rangerService(Id);
    RangerService rangerService2 = rangerService(9L);
    VXAsset vXAsset1 = vXAsset(Id);
    VXAsset vXAsset2 = vXAsset(9L);
    VXAssetList expectedVXAsset = new VXAssetList();
    List<VXAsset> vXAsset = Arrays.asList(vXAsset1, vXAsset2);
    expectedVXAsset.setVXAssets(vXAsset);
    VXLong expectedAsset = new VXLong();
    expectedAsset.setValue(2l);
    List<RangerService> services = Arrays.asList(rangerService1, rangerService2);
    SearchFilter searchFilter = new SearchFilter();
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, null)).thenReturn(searchFilter);
    Mockito.when(serviceREST.getServices(searchFilter)).thenReturn(services);
    Mockito.when(serviceUtil.toVXAsset(rangerService1)).thenReturn(vXAsset1);
    Mockito.when(serviceUtil.toVXAsset(rangerService2)).thenReturn(vXAsset2);
    VXLong actualAsset = assetREST.countXAssets(request);
    Assert.assertEquals(expectedAsset.getValue(), actualAsset.getValue());
}
Also used : VXAsset(org.apache.ranger.view.VXAsset) VXLong(org.apache.ranger.view.VXLong) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) VXAssetList(org.apache.ranger.view.VXAssetList) Test(org.junit.Test)

Example 57 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter 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 58 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class TestServiceREST method test21countPolicies.

@Test
public void test21countPolicies() 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);
    Long data = serviceREST.countPolicies(request);
    Assert.assertNotNull(data);
    Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) Test(org.junit.Test)

Example 59 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class TestServiceREST method test31getServices.

@Test
public void test31getServices() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    RangerServiceList dbRangerService = serviceREST.getServices(request);
    Assert.assertNull(dbRangerService);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceList(org.apache.ranger.view.RangerServiceList) Test(org.junit.Test)

Example 60 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class TestServiceREST method test25getPolicies.

@Test
public void test25getPolicies() throws Exception {
    List<RangerPolicy> ret = new ArrayList<RangerPolicy>();
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(svcStore.getPolicies(filter)).thenReturn(ret);
    List<RangerPolicy> dbRangerPolicyList = serviceREST.getPolicies(filter);
    Assert.assertNotNull(dbRangerPolicyList);
    Mockito.verify(svcStore).getPolicies(filter);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) Test(org.junit.Test)

Aggregations

SearchFilter (org.apache.ranger.plugin.util.SearchFilter)61 Test (org.junit.Test)32 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)30 ArrayList (java.util.ArrayList)27 RangerService (org.apache.ranger.plugin.model.RangerService)24 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 GET (javax.ws.rs.GET)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 RangerPolicyList (org.apache.ranger.view.RangerPolicyList)11 VXString (org.apache.ranger.view.VXString)10 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)9 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)7 RangerServiceDefList (org.apache.ranger.view.RangerServiceDefList)6 RangerServiceList (org.apache.ranger.view.RangerServiceList)6 HashMap (java.util.HashMap)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 XXTrxLog (org.apache.ranger.entity.XXTrxLog)4 RangerExportPolicyList (org.apache.ranger.view.RangerExportPolicyList)4