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);
}
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;
}
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);
}
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);
}
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());
}
Aggregations