Search in sources :

Example 1 with VXResource

use of org.apache.ranger.view.VXResource in project ranger by apache.

the class TestAssetREST method testCreateXResource.

@Test
public void testCreateXResource() {
    VXResource vxResource = vxResource(Id);
    RangerPolicy rangerPolicy = rangerPolicy(Id);
    RangerService rangerService = rangerService(Id);
    Mockito.when(serviceREST.getService(vxResource.getAssetId())).thenReturn(rangerService);
    Mockito.when(serviceREST.createPolicy(rangerPolicy, null)).thenReturn(rangerPolicy);
    Mockito.when(serviceUtil.toRangerPolicy(vxResource, rangerService)).thenReturn(rangerPolicy);
    Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vxResource);
    VXResource actualvxResource = assetREST.createXResource(vxResource);
    Assert.assertNotNull(actualvxResource);
    Assert.assertEquals(vxResource, actualvxResource);
    Mockito.verify(serviceREST).getService(vxResource.getAssetId());
    Mockito.verify(serviceREST).createPolicy(rangerPolicy, null);
    Mockito.verify(serviceUtil).toRangerPolicy(vxResource, rangerService);
    Mockito.verify(serviceUtil).toVXResource(rangerPolicy, rangerService);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXResource(org.apache.ranger.view.VXResource) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 2 with VXResource

use of org.apache.ranger.view.VXResource 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 3 with VXResource

use of org.apache.ranger.view.VXResource in project ranger by apache.

the class TestAssetREST method vxResource.

private VXResource vxResource(Long id) {
    VXResource vXResource = new VXResource();
    vXResource.setName("HDFS_1-1-20150316062453");
    vXResource.setAssetId(id);
    return vXResource;
}
Also used : VXResource(org.apache.ranger.view.VXResource)

Example 4 with VXResource

use of org.apache.ranger.view.VXResource 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 5 with VXResource

use of org.apache.ranger.view.VXResource in project ranger by apache.

the class TestAssetREST method testGetXResourceFile.

@Test
public void testGetXResourceFile() {
    File file = new File("testGetXResource");
    Response expectedResponse = Response.ok(file, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment;filename=" + file.getName()).build();
    VXResource vxResource = vxResource(Id);
    Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), (String) Mockito.any(), (String) Mockito.any(), (String) Mockito.any())).thenReturn("json");
    Mockito.when(assetREST.getXResource(Id)).thenReturn(vxResource);
    Mockito.when(assetMgr.getXResourceFile(vxResource, "json")).thenReturn(file);
    Response reponse = assetREST.getXResourceFile(request, Id);
    Assert.assertEquals(expectedResponse.getStatus(), reponse.getStatus());
    Mockito.verify(assetMgr).getXResourceFile(vxResource, "json");
    Mockito.verify(searchUtil).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), (String) Mockito.any(), (String) Mockito.any(), (String) Mockito.any());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) Response(javax.ws.rs.core.Response) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) VXResource(org.apache.ranger.view.VXResource) File(java.io.File) Test(org.junit.Test)

Aggregations

VXResource (org.apache.ranger.view.VXResource)28 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)9 VXResponse (org.apache.ranger.view.VXResponse)7 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)6 VXAuditMap (org.apache.ranger.view.VXAuditMap)6 VXPermMap (org.apache.ranger.view.VXPermMap)6 RangerService (org.apache.ranger.plugin.model.RangerService)5 VXResourceList (org.apache.ranger.view.VXResourceList)5 XXResource (org.apache.ranger.entity.XXResource)3 List (java.util.List)2 UserSessionBase (org.apache.ranger.common.UserSessionBase)2 XXAsset (org.apache.ranger.entity.XXAsset)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 VXPolicy (org.apache.ranger.view.VXPolicy)2 VXPolicyList (org.apache.ranger.view.VXPolicyList)2 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1