Search in sources :

Example 31 with RangerTagResourceMap

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

the class TestTagREST method test38createTagResourceMap.

@Test
public void test38createTagResourceMap() {
    RangerTagResourceMap oldTagResourceMap = null;
    RangerTagResourceMap newTagResourceMap = new RangerTagResourceMap();
    newTagResourceMap.setTagId(id);
    newTagResourceMap.setResourceId(id);
    try {
        Mockito.when(tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid)).thenReturn(oldTagResourceMap);
    } catch (Exception e) {
    }
    try {
        Mockito.when(validator.preCreateTagResourceMap(tagGuid, resourceGuid)).thenReturn(newTagResourceMap);
    } catch (Exception e) {
    }
    try {
        Mockito.when(tagStore.createTagResourceMap(newTagResourceMap)).thenReturn(newTagResourceMap);
    } catch (Exception e) {
    }
    RangerTagResourceMap rangerTagResourceMap = tagREST.createTagResourceMap(tagGuid, resourceGuid, false);
    Assert.assertEquals(rangerTagResourceMap.getTagId(), newTagResourceMap.getTagId());
    Assert.assertEquals(rangerTagResourceMap.getResourceId(), newTagResourceMap.getResourceId());
    try {
        Mockito.verify(tagStore).getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(validator).preCreateTagResourceMap(tagGuid, resourceGuid);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).createTagResourceMap(newTagResourceMap);
    } 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 32 with RangerTagResourceMap

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

the class TestTagREST method test42deleteTagResourceMapByGuid.

@Test
public void test42deleteTagResourceMapByGuid() {
    RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
    oldTagResourceMap.setId(id);
    oldTagResourceMap.setGuid(gId);
    try {
        Mockito.when(validator.preDeleteTagResourceMapByGuid(gId)).thenReturn(oldTagResourceMap);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(tagStore).deleteServiceResource(oldTagResourceMap.getId());
    } catch (Exception e) {
    }
    tagREST.deleteTagResourceMapByGuid(gId);
    Assert.assertNotNull(oldTagResourceMap.getId());
    Assert.assertNotNull(oldTagResourceMap.getGuid());
    try {
        Mockito.verify(validator).preDeleteTagResourceMapByGuid(gId);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).deleteServiceResource(oldTagResourceMap.getId());
    } 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)

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