Search in sources :

Example 6 with SearchFilter

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());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 7 with SearchFilter

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXLong(org.apache.ranger.view.VXLong) VXRepositoryList(org.apache.ranger.view.VXRepositoryList) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) VXRepository(org.apache.ranger.view.VXRepository) Test(org.junit.Test)

Example 8 with SearchFilter

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) 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 9 with SearchFilter

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXRepositoryList(org.apache.ranger.view.VXRepositoryList) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) VXRepository(org.apache.ranger.view.VXRepository) Test(org.junit.Test)

Example 10 with SearchFilter

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) 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