Search in sources :

Example 26 with RangerTagResourceMap

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

the class TestTagREST method test41deleteTagResourceMap.

@Test
public void test41deleteTagResourceMap() {
    RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
    oldTagResourceMap.setId(id);
    try {
        Mockito.when(validator.preDeleteTagResourceMap(id)).thenReturn(oldTagResourceMap);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(tagStore).deleteTagResourceMap(id);
    } catch (Exception e) {
    }
    tagREST.deleteTagResourceMap(id);
    Assert.assertNotNull(oldTagResourceMap.getId());
    try {
        Mockito.verify(validator).preDeleteTagResourceMap(id);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).deleteTagResourceMap(id);
    } catch (Exception e) {
    }
}
Also used : RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 27 with RangerTagResourceMap

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

the class TestTagREST method test44getTagResourceMap.

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

Example 28 with RangerTagResourceMap

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

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

the class TestTagREST method test45getTagResourceMapByGuid.

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

Example 30 with RangerTagResourceMap

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

the class TestTagREST method test47getAllTagResourceMaps.

@Test
public void test47getAllTagResourceMaps() {
    List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
    RangerTagResourceMap rangerTagResourceMap = new RangerTagResourceMap();
    rangerTagResourceMap.setId(id);
    rangerTagResourceMap.setTagId(id);
    ret.add(rangerTagResourceMap);
    try {
        Mockito.when(tagStore.getTagResourceMaps((SearchFilter) Mockito.any())).thenReturn(ret);
    } catch (Exception e) {
    }
    List<RangerTagResourceMap> result = tagREST.getAllTagResourceMaps();
    Assert.assertNotNull(result.get(0).getId());
    Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
    Assert.assertEquals(result.get(0).getTagId(), ret.get(0).getTagId());
    try {
        Mockito.verify(tagStore).getTagResourceMaps((SearchFilter) Mockito.any());
    } catch (Exception e) {
    }
}
Also used : 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

RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)16 Test (org.junit.Test)12 ExpectedException (org.junit.rules.ExpectedException)12 ArrayList (java.util.ArrayList)9 XXTagResourceMap (org.apache.ranger.entity.XXTagResourceMap)8 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)7 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 HashMap (java.util.HashMap)3 DELETE (javax.ws.rs.DELETE)3 Predicate (org.apache.commons.collections.Predicate)3 RangerTag (org.apache.ranger.plugin.model.RangerTag)3 Map (java.util.Map)2 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2 List (java.util.List)1 POST (javax.ws.rs.POST)1