Search in sources :

Example 16 with RangerService

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

the class TestPublicAPIs method test6countRepositories.

@Test
public void test6countRepositories() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    VXLong vXLong = new VXLong();
    List<RangerService> ret = new ArrayList<RangerService>();
    RangerService rangerService = rangerService();
    VXRepository vXRepository = vXRepository(rangerService);
    List<VXRepository> repoList = new ArrayList<VXRepository>();
    repoList.add(vXRepository);
    VXRepositoryList vXRepositoryList = new VXRepositoryList(repoList);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getServices(filter)).thenReturn(ret);
    Mockito.when(serviceUtil.rangerServiceListToPublicObjectList(ret)).thenReturn(vXRepositoryList);
    VXRepositoryList dbVXRepositoryList = publicAPIs.searchRepositories(request);
    vXLong.setValue(dbVXRepositoryList.getResultSize());
    Assert.assertNotNull(vXLong);
    Assert.assertEquals(vXLong.getValue(), 1);
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields);
    Mockito.verify(serviceREST).getServices(filter);
    Mockito.verify(serviceUtil).rangerServiceListToPublicObjectList(ret);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXLong(org.apache.ranger.view.VXLong) VXRepositoryList(org.apache.ranger.view.VXRepositoryList) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) VXRepository(org.apache.ranger.view.VXRepository) Test(org.junit.Test)

Example 17 with RangerService

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

the class TestPublicAPIs 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 policy");
    rangerService.setGuid("1427365526516_835_0");
    rangerService.setIsEnabled(true);
    rangerService.setName("HDFS_1");
    rangerService.setPolicyUpdateTime(new Date());
    rangerService.setType("1");
    rangerService.setUpdatedBy("Admin");
    rangerService.setUpdateTime(new Date());
    return rangerService;
}
Also used : HashMap(java.util.HashMap) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date)

Example 18 with RangerService

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

the class TestPublicAPIs method test12countPolicies.

@Test
public void test12countPolicies() throws Exception {
    VXLong vXLong = new VXLong();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerService service = rangerService();
    RangerPolicy policy = rangerPolicy();
    List<RangerPolicy> policyList = new ArrayList<RangerPolicy>();
    policyList.add(policy);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>();
    vXPolicies.add(vXPolicy);
    VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    filter.setStartIndex(0);
    filter.setMaxRows(10);
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList);
    Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList, filter)).thenReturn(vXPolicyList);
    VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request);
    vXLong.setValue(dbVXPolicyList.getResultSize());
    Assert.assertNotNull(vXLong);
    Assert.assertEquals(vXLong.getValue(), 1);
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    Mockito.verify(serviceREST).getPolicies(filter);
    Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) VXPolicyList(org.apache.ranger.view.VXPolicyList) ArrayList(java.util.ArrayList) VXPolicy(org.apache.ranger.view.VXPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 19 with RangerService

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

the class TestPublicAPIs method test2createRepository.

@Test
public void test2createRepository() throws Exception {
    VXAsset vXAsset = new VXAsset();
    RangerService rangerService = rangerService();
    VXRepository vXRepository = vXRepository(rangerService);
    Mockito.when(serviceUtil.publicObjecttoVXAsset(vXRepository)).thenReturn(vXAsset);
    Mockito.when(serviceUtil.toRangerService(vXAsset)).thenReturn(rangerService);
    Mockito.when(serviceREST.createService(rangerService)).thenReturn(rangerService);
    Mockito.when(serviceUtil.toVXAsset(rangerService)).thenReturn(vXAsset);
    Mockito.when(serviceUtil.vXAssetToPublicObject(vXAsset)).thenReturn(vXRepository);
    VXRepository dbVXRepository = publicAPIs.createRepository(vXRepository);
    Assert.assertNotNull(dbVXRepository);
    Assert.assertEquals(dbVXRepository, vXRepository);
    Assert.assertEquals(dbVXRepository.getId(), vXRepository.getId());
    Assert.assertEquals(dbVXRepository.getName(), vXRepository.getName());
    Mockito.verify(serviceREST).createService(rangerService);
    Mockito.verify(serviceUtil).publicObjecttoVXAsset(vXRepository);
    Mockito.verify(serviceUtil).toRangerService(vXAsset);
    Mockito.verify(serviceUtil).toVXAsset(rangerService);
    Mockito.verify(serviceUtil).vXAssetToPublicObject(vXAsset);
}
Also used : VXAsset(org.apache.ranger.view.VXAsset) RangerService(org.apache.ranger.plugin.model.RangerService) VXRepository(org.apache.ranger.view.VXRepository) Test(org.junit.Test)

Example 20 with RangerService

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

the class TestPublicAPIs method test5searchRepositories.

@Test
public void test5searchRepositories() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    List<RangerService> ret = new ArrayList<RangerService>();
    RangerService rangerService = rangerService();
    VXRepository vXRepository = vXRepository(rangerService);
    List<VXRepository> repoList = new ArrayList<VXRepository>();
    repoList.add(vXRepository);
    VXRepositoryList vXRepositoryList = new VXRepositoryList(repoList);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getServices(filter)).thenReturn(ret);
    Mockito.when(serviceUtil.rangerServiceListToPublicObjectList(ret)).thenReturn(vXRepositoryList);
    VXRepositoryList dbVXRepositoryList = publicAPIs.searchRepositories(request);
    Assert.assertNotNull(dbVXRepositoryList);
    Assert.assertEquals(dbVXRepositoryList.getResultSize(), vXRepositoryList.getResultSize());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXRepositoryList(org.apache.ranger.view.VXRepositoryList) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) VXRepository(org.apache.ranger.view.VXRepository) 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