Search in sources :

Example 61 with RangerServiceResource

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

the class TestTagREST method test48deleteServiceResourceByGuid.

@Test
public void test48deleteServiceResourceByGuid() {
    RangerServiceResource oldRSR = new RangerServiceResource();
    oldRSR.setId(id);
    oldRSR.setGuid(gId);
    List<RangerTagResourceMap> tagResourceMaps = new ArrayList<RangerTagResourceMap>();
    RangerTagResourceMap rangerTagResourceMap = new RangerTagResourceMap();
    rangerTagResourceMap.setId(id);
    rangerTagResourceMap.setTagId(id);
    tagResourceMaps.add(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)

Example 62 with RangerServiceResource

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

the class TestTagREST method test31deleteServiceResource.

@Test
public void test31deleteServiceResource() {
    RangerServiceResource oldSRS = new RangerServiceResource();
    oldSRS.setId(id);
    try {
        Mockito.when(validator.preDeleteServiceResource(id)).thenReturn(oldSRS);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(tagStore).deleteServiceResource(id);
    } catch (Exception e) {
    }
    tagREST.deleteServiceResource(id);
    Assert.assertNotNull(oldSRS.getId());
    try {
        Mockito.verify(validator).preDeleteServiceResource(id);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).deleteServiceResource(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 63 with RangerServiceResource

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

the class TestTagREST method test28createServiceResource.

@Test
public void test28createServiceResource() {
    RangerServiceResource oldRSR = new RangerServiceResource();
    RangerServiceResource newRSR = new RangerServiceResource();
    oldRSR.setId(id);
    newRSR.setId(id);
    newRSR.setVersion(5L);
    try {
        Mockito.when(validator.preCreateServiceResource(oldRSR)).thenReturn(oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(validator).preUpdateServiceResource(oldRSR.getId(), oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.when(tagStore.updateServiceResource(oldRSR)).thenReturn(newRSR);
    } catch (Exception e) {
    }
    RangerServiceResource rangerServiceResource = tagREST.createServiceResource(oldRSR, true);
    Assert.assertNotEquals(oldRSR.getVersion(), newRSR.getVersion());
    Assert.assertEquals(rangerServiceResource.getId(), newRSR.getId());
    Assert.assertEquals(rangerServiceResource.getId(), oldRSR.getId());
    try {
        Mockito.verify(validator).preCreateServiceResource(oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(validator).preUpdateServiceResource(oldRSR.getId(), oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).updateServiceResource(oldRSR);
    } 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 64 with RangerServiceResource

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

the class TestTagREST method test34getServiceResourcesByService.

@Test
public void test34getServiceResourcesByService() {
    List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
    RangerServiceResource rangerServiceResource = new RangerServiceResource();
    rangerServiceResource.setId(id);
    rangerServiceResource.setServiceName(serviceName);
    ret.add(rangerServiceResource);
    try {
        Mockito.when(tagStore.getServiceResourcesByService(serviceName)).thenReturn(ret);
    } catch (Exception e) {
    }
    List<RangerServiceResource> reslut = tagREST.getServiceResourcesByService(serviceName);
    Assert.assertNotNull(reslut.get(0).getId());
    Assert.assertEquals(reslut.get(0).getId(), ret.get(0).getId());
    Assert.assertEquals(reslut.get(0).getServiceName(), ret.get(0).getServiceName());
    try {
        Mockito.verify(tagStore).getServiceResourcesByService(serviceName);
    } 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 65 with RangerServiceResource

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

the class TestTagREST method test33getServiceResourceByGuid.

@Test
public void test33getServiceResourceByGuid() {
    RangerServiceResource oldSRS = new RangerServiceResource();
    oldSRS.setId(id);
    oldSRS.setGuid(gId);
    try {
        Mockito.when(tagStore.getServiceResourceByGuid(gId)).thenReturn(oldSRS);
    } catch (Exception e) {
    }
    RangerServiceResource rangerServiceResource = tagREST.getServiceResourceByGuid(gId);
    Assert.assertNotNull(rangerServiceResource);
    Assert.assertEquals(rangerServiceResource.getGuid(), oldSRS.getGuid());
    Assert.assertEquals(rangerServiceResource.getId(), oldSRS.getId());
    try {
        Mockito.verify(tagStore).getServiceResourceByGuid(gId);
    } 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)

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