Search in sources :

Example 11 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class TestAssetREST method testSearchXAssets.

@Test
public void testSearchXAssets() {
    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);
    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);
    VXAssetList vXAssetList = assetREST.searchXAssets(request);
    Assert.assertNotNull(vXAssetList);
    Assert.assertEquals(expectedVXAsset.getVXAssets(), vXAssetList.getVXAssets());
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequestForRepositorySearch(request, null);
    Mockito.verify(serviceREST).getServices(searchFilter);
    Mockito.verify(serviceUtil, Mockito.times(1)).toVXAsset(rangerService1);
    Mockito.verify(serviceUtil, Mockito.times(1)).toVXAsset(rangerService2);
}
Also used : VXAsset(org.apache.ranger.view.VXAsset) 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 12 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class TestAssetREST method testCountXResource.

@Test
public void testCountXResource() {
    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);
    }
    VXLong expectedXResouce = new VXLong();
    expectedXResouce.setValue(2l);
    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);
    VXLong actualXResource = assetREST.countXResources(request);
    Assert.assertEquals(expectedXResouce.getValue(), actualXResource.getValue());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) 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 13 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class TestAssetREST method testUpdateXAsset.

@Test
public void testUpdateXAsset() {
    RangerService rangerService = rangerService(Id);
    HttpServletRequest request = null;
    VXAsset vXAsset = vXAsset(Id);
    Mockito.when(serviceUtil.toRangerService(vXAsset)).thenReturn(rangerService);
    Mockito.when(serviceREST.updateService(rangerService, request)).thenReturn(rangerService);
    Mockito.when(serviceUtil.toVXAsset(rangerService)).thenReturn(vXAsset);
    VXAsset asset = assetREST.updateXAsset(vXAsset);
    Assert.assertNotNull(asset);
    Assert.assertEquals(vXAsset, asset);
    Mockito.verify(serviceREST).updateService(rangerService, request);
    Mockito.verify(serviceUtil).toRangerService(vXAsset);
    Mockito.verify(serviceUtil).toVXAsset(rangerService);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXAsset(org.apache.ranger.view.VXAsset) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 14 with RangerService

use of org.apache.ranger.plugin.model.RangerService 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 15 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class TestAssetREST method testRevokePermissionWebApplicationException.

@Test
public void testRevokePermissionWebApplicationException() {
    RangerPolicy policy = rangerPolicy(Id);
    RangerService service = rangerService(Id);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
    grantRequestObj.setAccessTypes(null);
    grantRequestObj.setDelegateAdmin(true);
    grantRequestObj.setEnableAudit(true);
    grantRequestObj.setGrantor("read");
    grantRequestObj.setIsRecursive(true);
    WebApplicationException webApplicationException = new WebApplicationException();
    Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
    try {
        Mockito.when(serviceREST.revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenThrow(webApplicationException);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
    try {
        assetREST.revokePermission(request, vXPolicy);
        fail("Exception not thrown");
    } catch (WebApplicationException e) {
        Assert.assertTrue(true);
    }
    Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
    try {
        Mockito.verify(serviceREST).revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12