Search in sources :

Example 26 with RangerService

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

the class TestPublicAPIsv2 method test19searchPolicies.

@Test
public void test19searchPolicies() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    List<RangerPolicy> policiesList = new ArrayList<RangerPolicy>();
    RangerService service = rangerService();
    String serviceName = service.getName();
    RangerPolicy rangerPolicy = rangerPolicy();
    policiesList.add(rangerPolicy);
    RangerPolicyList policyList = new RangerPolicyList(policiesList);
    Mockito.when(serviceREST.getServicePoliciesByName(serviceName, request)).thenReturn(policyList);
    List<RangerPolicy> dbRangerPolicyList = publicAPIsv2.searchPolicies(serviceName, request);
    Assert.assertNotNull(dbRangerPolicyList);
    Assert.assertEquals(dbRangerPolicyList.size(), policiesList.size());
    Mockito.verify(serviceREST).getServicePoliciesByName(serviceName, request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Test(org.junit.Test)

Example 27 with RangerService

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

the class TestPublicAPIsv2 method test25deletePolicyByName.

@Test
public void test25deletePolicyByName() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    String policyName = rangerPolicy.getName();
    RangerService rangerService = rangerService();
    String serviceName = rangerService.getName();
    List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
    policies.add(rangerPolicy);
    Mockito.when(serviceREST.getPolicies((SearchFilter) Mockito.any())).thenReturn(policies);
    Mockito.doNothing().when(serviceREST).deletePolicy(Id);
    publicAPIsv2.deletePolicyByName(serviceName, policyName, request);
    Mockito.verify(serviceREST).getPolicies((SearchFilter) Mockito.any());
    Mockito.verify(serviceREST).deletePolicy(Id);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 28 with RangerService

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

the class TestServiceREST method test11getServiceByName.

@Test
public void test11getServiceByName() throws Exception {
    RangerService rangerService = rangerService();
    Mockito.when(svcStore.getServiceByName(rangerService.getName())).thenReturn(rangerService);
    RangerService dbRangerService = serviceREST.getServiceByName(rangerService.getName());
    Assert.assertNotNull(dbRangerService);
    Assert.assertEquals(dbRangerService.getName(), dbRangerService.getName());
    Mockito.verify(svcStore).getServiceByName(dbRangerService.getName());
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 29 with RangerService

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

the class TestServiceREST method test34countServices.

@Test
public void test34countServices() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    PList<RangerService> ret = Mockito.mock(PList.class);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(svcStore.getPaginatedServices(filter)).thenReturn(ret);
    Long data = serviceREST.countServices(request);
    Assert.assertNotNull(data);
    Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
    Mockito.verify(svcStore).getPaginatedServices(filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 30 with RangerService

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

the class TestServiceREST method test6createService.

@Test
public void test6createService() throws Exception {
    RangerService rangerService = rangerService();
    XXServiceDef xServiceDef = serviceDef();
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    Mockito.when(validatorFactory.getServiceValidator(svcStore)).thenReturn(serviceValidator);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.findByName(rangerService.getType())).thenReturn(xServiceDef);
    Mockito.when(svcStore.createService((RangerService) Mockito.any())).thenReturn(rangerService);
    RangerService dbRangerService = serviceREST.createService(rangerService);
    Assert.assertNotNull(dbRangerService);
    Assert.assertEquals(rangerService, dbRangerService);
    Assert.assertEquals(rangerService.getId(), dbRangerService.getId());
    Assert.assertEquals(rangerService.getConfigs(), dbRangerService.getConfigs());
    Assert.assertEquals(rangerService.getDescription(), dbRangerService.getDescription());
    Assert.assertEquals(rangerService.getGuid(), dbRangerService.getGuid());
    Assert.assertEquals(rangerService.getName(), dbRangerService.getName());
    Assert.assertEquals(rangerService.getPolicyVersion(), dbRangerService.getPolicyVersion());
    Assert.assertEquals(rangerService.getType(), dbRangerService.getType());
    Assert.assertEquals(rangerService.getVersion(), dbRangerService.getVersion());
    Assert.assertEquals(rangerService.getCreateTime(), dbRangerService.getCreateTime());
    Assert.assertEquals(rangerService.getUpdateTime(), dbRangerService.getUpdateTime());
    Assert.assertEquals(rangerService.getUpdatedBy(), dbRangerService.getUpdatedBy());
    Mockito.verify(validatorFactory).getServiceValidator(svcStore);
    Mockito.verify(svcStore).createService(rangerService);
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) 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