Search in sources :

Example 56 with RangerServiceResource

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

the class TestKafkaResourceMapper method testKafkaResourceFromMissingAttribs.

@Test
public void testKafkaResourceFromMissingAttribs() throws Exception {
    Map<String, Object> entAttribs = new HashMap<String, Object>();
    RangerAtlasEntity entity = getKafkaTopicEntity(entAttribs);
    try {
        RangerServiceResource resource = resourceMapper.buildResource(entity);
        Assert.fail("expected exception. Found " + resource);
    } catch (Exception excp) {
    // ignore
    }
}
Also used : RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) HashMap(java.util.HashMap) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) Test(org.junit.Test)

Example 57 with RangerServiceResource

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

the class TestTagREST method test27createServiceResource.

@Test
public void test27createServiceResource() {
    RangerServiceResource oldRSR = null;
    RangerServiceResource newRSR = new RangerServiceResource();
    newRSR.setId(id);
    newRSR.setGuid(gId);
    try {
        Mockito.when(validator.preCreateServiceResource(oldRSR)).thenReturn(oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.when(tagStore.createServiceResource(oldRSR)).thenReturn(newRSR);
    } catch (Exception e) {
    }
    RangerServiceResource rangerServiceResource = tagREST.createServiceResource(oldRSR, false);
    Assert.assertNotNull(rangerServiceResource.getId());
    Assert.assertEquals(rangerServiceResource.getId(), newRSR.getId());
    Assert.assertEquals(rangerServiceResource.getGuid(), newRSR.getGuid());
    try {
        Mockito.verify(validator).preCreateServiceResource(oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).createServiceResource(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 58 with RangerServiceResource

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

the class TestTagREST method test49deleteServiceResourceByGuid.

@Test
public void test49deleteServiceResourceByGuid() {
    RangerServiceResource oldRSR = new RangerServiceResource();
    oldRSR.setId(id);
    oldRSR.setGuid(gId);
    try {
        Mockito.when(validator.preDeleteServiceResourceByGuid(gId, false)).thenReturn(oldRSR);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(tagStore).deleteServiceResource(oldRSR.getId());
    } catch (Exception e) {
    }
    tagREST.deleteServiceResourceByGuid(gId, false);
    try {
        Mockito.verify(validator).preDeleteServiceResourceByGuid(gId, false);
    } 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 59 with RangerServiceResource

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

the class TestTagREST method test30updateServiceResourceByGuid.

@Test
public void test30updateServiceResourceByGuid() {
    RangerServiceResource oldSRS = new RangerServiceResource();
    RangerServiceResource newSRS = new RangerServiceResource();
    oldSRS.setId(id);
    oldSRS.setGuid(gId);
    newSRS.setId(id);
    newSRS.setGuid(gId);
    newSRS.setVersion(5L);
    try {
        Mockito.doNothing().when(validator).preUpdateServiceResourceByGuid(gId, oldSRS);
    } catch (Exception e) {
    }
    try {
        Mockito.when(tagStore.updateServiceResource(oldSRS)).thenReturn(newSRS);
    } catch (Exception e) {
    }
    RangerServiceResource rangerServiceResource = tagREST.updateServiceResourceByGuid(gId, oldSRS);
    Assert.assertEquals(oldSRS.getId(), newSRS.getId());
    Assert.assertEquals(oldSRS.getGuid(), newSRS.getGuid());
    Assert.assertNotEquals(oldSRS.getVersion(), newSRS.getVersion());
    Assert.assertEquals(rangerServiceResource.getVersion(), newSRS.getVersion());
    try {
        Mockito.verify(validator).preUpdateServiceResourceByGuid(gId, oldSRS);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).updateServiceResource(oldSRS);
    } 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 60 with RangerServiceResource

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

the class TestTagREST method test35getServiceResourcesByService.

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

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