Search in sources :

Example 26 with RangerTag

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

the class TestTagREST method test18createTag.

@Test
public void test18createTag() {
    RangerTag oldTag = new RangerTag();
    RangerTag newTag = new RangerTag();
    oldTag.setId(id);
    newTag.setId(id);
    newTag.setVersion(5L);
    try {
        Mockito.when(validator.preCreateTag(oldTag)).thenReturn(oldTag);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(validator).preUpdateTag(oldTag.getId(), oldTag);
    } catch (Exception e1) {
    }
    try {
        Mockito.when(tagStore.updateTag(oldTag)).thenReturn(newTag);
    } catch (Exception e) {
    }
    RangerTag rangerTag = tagREST.createTag(oldTag, true);
    Assert.assertEquals(rangerTag.getVersion(), newTag.getVersion());
    Assert.assertNotNull(newTag.getVersion());
    Assert.assertNotEquals(oldTag.getVersion(), newTag.getVersion());
    Assert.assertEquals(oldTag.getId(), newTag.getId());
    try {
        Mockito.verify(validator).preCreateTag(oldTag);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(validator).preUpdateTag(oldTag.getId(), oldTag);
    } catch (Exception e1) {
    }
    try {
        Mockito.verify(tagStore).updateTag(oldTag);
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 27 with RangerTag

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

the class TestTagREST method test24getTagByGuid.

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

Example 28 with RangerTag

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

the class TestTagREST method test26getAllTags.

@Test
public void test26getAllTags() {
    List<RangerTag> ret = new ArrayList<RangerTag>();
    RangerTag rangerTag = new RangerTag();
    rangerTag.setId(id);
    rangerTag.setGuid(gId);
    ret.add(rangerTag);
    try {
        Mockito.when(tagStore.getTags((SearchFilter) Mockito.any())).thenReturn(ret);
    } catch (Exception e) {
    }
    List<RangerTag> result = tagREST.getAllTags();
    Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
    Assert.assertEquals(result.get(0).getVersion(), ret.get(0).getVersion());
    Assert.assertNotNull(result.get(0).getId());
    try {
        Mockito.verify(tagStore).getTags((SearchFilter) Mockito.any());
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 29 with RangerTag

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

the class TestTagREST method test22deleteTagByGuid.

@Test
public void test22deleteTagByGuid() {
    RangerTag oldTag = new RangerTag();
    oldTag.setId(id);
    oldTag.setGuid(gId);
    try {
        Mockito.when(validator.preDeleteTagByGuid(gId)).thenReturn(oldTag);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(tagStore).deleteTag(oldTag.getId());
    } catch (Exception e) {
    }
    tagREST.deleteTagByGuid(gId);
    Assert.assertNotNull(oldTag.getId());
    Assert.assertNotNull(oldTag.getGuid());
    try {
        Mockito.verify(validator).preDeleteTagByGuid(gId);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).deleteTag(oldTag.getId());
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 30 with RangerTag

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

the class TestTagREST method test20updateTagByGuid.

@Test
public void test20updateTagByGuid() {
    RangerTag oldTag = new RangerTag();
    RangerTag newTag = new RangerTag();
    oldTag.setGuid(gId);
    newTag.setGuid(gId);
    newTag.setVersion(5L);
    try {
        Mockito.doNothing().when(validator).preUpdateTagByGuid(gId, oldTag);
    } catch (Exception e) {
    }
    try {
        Mockito.when(tagStore.updateTag(oldTag)).thenReturn(newTag);
    } catch (Exception e) {
    }
    RangerTag rangerTag = tagREST.updateTagByGuid(gId, oldTag);
    Assert.assertEquals(oldTag.getGuid(), newTag.getGuid());
    Assert.assertNotEquals(rangerTag.getVersion(), oldTag.getVersion());
    Assert.assertEquals(rangerTag.getVersion(), newTag.getVersion());
    try {
        Mockito.verify(validator).preUpdateTagByGuid(gId, oldTag);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).updateTag(oldTag);
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerTag (org.apache.ranger.plugin.model.RangerTag)30 WebApplicationException (javax.ws.rs.WebApplicationException)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 ExpectedException (org.junit.rules.ExpectedException)10 XXTag (org.apache.ranger.entity.XXTag)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)4 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)4 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Predicate (org.apache.commons.collections.Predicate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 HashSet (java.util.HashSet)2 List (java.util.List)2 PUT (javax.ws.rs.PUT)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)2