Search in sources :

Example 6 with RangerService

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

the class TestRangerServiceService method test7GetTransactionLogUpdate.

@Test
public void test7GetTransactionLogUpdate() {
    RangerService rangerService = rangerService();
    List<XXTrxLog> dbXXTrxLogList = serviceService.getTransactionLog(rangerService, 2);
    Assert.assertNull(dbXXTrxLogList);
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) XXTrxLog(org.apache.ranger.entity.XXTrxLog) Test(org.junit.Test)

Example 7 with RangerService

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

the class TestRangerServiceServiceBase method test2mapEntityToViewBean.

@Test
public void test2mapEntityToViewBean() {
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    RangerService rangerService = rangerService();
    XXService service = service();
    XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
    serviceVersionInfo.setServiceId(service.getId());
    serviceVersionInfo.setPolicyVersion(service.getPolicyVersion());
    serviceVersionInfo.setPolicyUpdateTime(service.getPolicyUpdateTime());
    serviceVersionInfo.setTagVersion(service.getTagVersion());
    serviceVersionInfo.setPolicyUpdateTime(service.getTagUpdateTime());
    Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
    Mockito.when(xServiceVersionInfoDao.findByServiceId(service.getId())).thenReturn(serviceVersionInfo);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(service.getType())).thenReturn(xServiceDef);
    RangerService dbRangerService = rangerServiceService.mapEntityToViewBean(rangerService, service);
    Assert.assertNotNull(dbRangerService);
    Assert.assertEquals(dbRangerService, rangerService);
    Assert.assertEquals(dbRangerService.getDescription(), rangerService.getDescription());
    Assert.assertEquals(dbRangerService.getGuid(), rangerService.getGuid());
    Assert.assertEquals(dbRangerService.getName(), rangerService.getName());
    Assert.assertEquals(dbRangerService.getId(), rangerService.getId());
    Assert.assertEquals(dbRangerService.getVersion(), rangerService.getVersion());
    Assert.assertEquals(dbRangerService.getType(), rangerService.getType());
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao) Test(org.junit.Test)

Example 8 with RangerService

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

the class TestRangerServiceServiceBase method rangerService.

private RangerService rangerService() {
    Map<String, String> configs = new HashMap<String, String>();
    configs.put("username", "servicemgr");
    configs.put("password", "servicemgr");
    configs.put("namenode", "servicemgr");
    configs.put("hadoop.security.authorization", "No");
    configs.put("hadoop.security.authentication", "Simple");
    configs.put("hadoop.security.auth_to_local", "");
    configs.put("dfs.datanode.kerberos.principal", "");
    configs.put("dfs.namenode.kerberos.principal", "");
    configs.put("dfs.secondary.namenode.kerberos.principal", "");
    configs.put("hadoop.rpc.protection", "Privacy");
    configs.put("commonNameForCertificate", "");
    RangerService rangerService = new RangerService();
    rangerService.setId(Id);
    rangerService.setConfigs(configs);
    rangerService.setCreateTime(new Date());
    rangerService.setDescription("service");
    rangerService.setGuid("serviceguid");
    rangerService.setIsEnabled(true);
    rangerService.setName("Hdfs service");
    rangerService.setPolicyUpdateTime(new Date());
    rangerService.setPolicyVersion(1L);
    rangerService.setType(null);
    rangerService.setUpdatedBy("Admin");
    rangerService.setUpdateTime(new Date());
    rangerService.setVersion(Id);
    return rangerService;
}
Also used : HashMap(java.util.HashMap) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date)

Example 9 with RangerService

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

the class TestAssetREST method testGrantPermissionWebApplicationException.

@Test
public void testGrantPermissionWebApplicationException() {
    RangerPolicy policy = rangerPolicy(Id);
    RangerService service = rangerService(Id);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
    grantRequestObj.setAccessTypes(null);
    grantRequestObj.setDelegateAdmin(true);
    grantRequestObj.setEnableAudit(true);
    grantRequestObj.setGrantor("read");
    grantRequestObj.setIsRecursive(true);
    WebApplicationException webApplicationException = new WebApplicationException();
    Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
    try {
        Mockito.when(serviceREST.grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenThrow(webApplicationException);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
    try {
        assetREST.grantPermission(request, vXPolicy);
        fail("Exception not thrown");
    } catch (WebApplicationException e) {
        Assert.assertTrue(true);
    }
    Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
    try {
        Mockito.verify(serviceREST).grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 10 with RangerService

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

the class TestAssetREST method testCreateXResource.

@Test
public void testCreateXResource() {
    VXResource vxResource = vxResource(Id);
    RangerPolicy rangerPolicy = rangerPolicy(Id);
    RangerService rangerService = rangerService(Id);
    Mockito.when(serviceREST.getService(vxResource.getAssetId())).thenReturn(rangerService);
    Mockito.when(serviceREST.createPolicy(rangerPolicy, null)).thenReturn(rangerPolicy);
    Mockito.when(serviceUtil.toRangerPolicy(vxResource, rangerService)).thenReturn(rangerPolicy);
    Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vxResource);
    VXResource actualvxResource = assetREST.createXResource(vxResource);
    Assert.assertNotNull(actualvxResource);
    Assert.assertEquals(vxResource, actualvxResource);
    Mockito.verify(serviceREST).getService(vxResource.getAssetId());
    Mockito.verify(serviceREST).createPolicy(rangerPolicy, null);
    Mockito.verify(serviceUtil).toRangerPolicy(vxResource, rangerService);
    Mockito.verify(serviceUtil).toVXResource(rangerPolicy, rangerService);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXResource(org.apache.ranger.view.VXResource) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12