Search in sources :

Example 16 with RangerServiceResource

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

the class TestTagREST method test29createServiceResource.

@Test
public void test29createServiceResource() {
    RangerServiceResource oldRSR = new RangerServiceResource();
    try {
        Mockito.when(validator.preCreateServiceResource(oldRSR)).thenReturn(oldRSR);
    } catch (Exception e) {
    }
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    tagREST.createServiceResource(oldRSR, false);
    try {
        Mockito.verify(validator).preCreateServiceResource(oldRSR);
    } catch (Exception e) {
    }
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 17 with RangerServiceResource

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

the class TestTagREST method test36getServiceResourceByServiceAndResourceSignature.

@Test
public void test36getServiceResourceByServiceAndResourceSignature() {
    RangerServiceResource oldSRS = new RangerServiceResource();
    oldSRS.setId(id);
    oldSRS.setResourceSignature(resourceSignature);
    oldSRS.setServiceName(serviceName);
    try {
        Mockito.when(tagStore.getServiceResourceByServiceAndResourceSignature(serviceName, resourceSignature)).thenReturn(oldSRS);
    } catch (Exception e) {
    }
    RangerServiceResource rangerServiceResource = tagREST.getServiceResourceByServiceAndResourceSignature(serviceName, resourceSignature);
    Assert.assertEquals(rangerServiceResource.getId(), oldSRS.getId());
    Assert.assertEquals(rangerServiceResource.getServiceName(), oldSRS.getServiceName());
    Assert.assertEquals(rangerServiceResource.getResourceSignature(), oldSRS.getResourceSignature());
    try {
        Mockito.verify(tagStore).getServiceResourceByServiceAndResourceSignature(serviceName, resourceSignature);
    } catch (Exception e) {
    }
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 18 with RangerServiceResource

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

the class TestTagREST method test32getServiceResource.

@Test
public void test32getServiceResource() {
    RangerServiceResource oldSRS = new RangerServiceResource();
    oldSRS.setId(id);
    oldSRS.setGuid(gId);
    try {
        Mockito.when(tagStore.getServiceResource(id)).thenReturn(oldSRS);
    } catch (Exception e) {
    }
    RangerServiceResource rangerServiceResource = tagREST.getServiceResource(id);
    Assert.assertNotNull(rangerServiceResource);
    Assert.assertEquals(rangerServiceResource.getId(), oldSRS.getId());
    Assert.assertEquals(rangerServiceResource.getGuid(), oldSRS.getGuid());
    try {
        Mockito.verify(tagStore).getServiceResource(id);
    } catch (Exception e) {
    }
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 19 with RangerServiceResource

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

the class TestTagREST method test37getAllServiceResources.

@Test
public void test37getAllServiceResources() {
    List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
    RangerServiceResource rangerServiceResource = new RangerServiceResource();
    rangerServiceResource.setId(id);
    rangerServiceResource.setServiceName(serviceName);
    ret.add(rangerServiceResource);
    try {
        Mockito.when(tagStore.getServiceResources((SearchFilter) Mockito.any())).thenReturn(ret);
    } catch (Exception e) {
    }
    List<RangerServiceResource> result = tagREST.getAllServiceResources();
    Assert.assertNotNull(result.get(0).getId());
    Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
    Assert.assertEquals(result.get(0).getServiceName(), ret.get(0).getServiceName());
    try {
        Mockito.verify(tagStore).getServiceResources((SearchFilter) Mockito.any());
    } catch (Exception e) {
    }
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ArrayList(java.util.ArrayList) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 20 with RangerServiceResource

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

the class TestTagREST method test61deleteServiceResourceByGuid.

@Test
public void test61deleteServiceResourceByGuid() {
    RangerServiceResource oldRSR = new RangerServiceResource();
    oldRSR.setId(id);
    oldRSR.setGuid(gId);
    List<RangerTagResourceMap> tagResourceMaps = new ArrayList<RangerTagResourceMap>();
    try {
        Mockito.when(validator.preDeleteServiceResourceByGuid(gId, true)).thenReturn(oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.when(tagStore.getTagResourceMapsForResourceGuid(oldRSR.getGuid())).thenReturn(tagResourceMaps);
    } catch (Exception e) {
    }
    tagREST.deleteServiceResourceByGuid(gId, true);
    try {
        Mockito.verify(validator).preDeleteServiceResourceByGuid(gId, true);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).getTagResourceMapsForResourceGuid(oldRSR.getGuid());
    } catch (Exception e) {
    }
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ArrayList(java.util.ArrayList) RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)65 Test (org.junit.Test)42 HashMap (java.util.HashMap)37 RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)30 WebApplicationException (javax.ws.rs.WebApplicationException)17 ExpectedException (org.junit.rules.ExpectedException)14 ArrayList (java.util.ArrayList)10 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)7 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)5 Predicate (org.apache.commons.collections.Predicate)4 XXServiceResource (org.apache.ranger.entity.XXServiceResource)4 RangerTag (org.apache.ranger.plugin.model.RangerTag)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 PUT (javax.ws.rs.PUT)2 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2