use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestRangerPolicyService method test1ValidateForCreate.
@Test
public void test1ValidateForCreate() {
RangerPolicy rangerPolicy = rangerPolicy();
policyService.validateForCreate(rangerPolicy);
Assert.assertNotNull(rangerPolicy);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestRangerPolicyService method test2ValidateForUpdate.
@Test
public void test2ValidateForUpdate() {
RangerPolicy rangerPolicy = rangerPolicy();
XXPolicy policy = policy();
policyService.validateForUpdate(rangerPolicy, policy);
Assert.assertNotNull(rangerPolicy);
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestRangerPolicyServiceBase method test3mapEntityToViewBean.
@Test
public void test3mapEntityToViewBean() {
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXService xService = Mockito.mock(XXService.class);
RangerPolicy rangerPolicy = rangerPolicy();
XXPolicy policy = policy();
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.getById(policy.getService())).thenReturn(xService);
RangerPolicy dbRangerPolicy = policyService.mapEntityToViewBean(rangerPolicy, policy);
Assert.assertNotNull(dbRangerPolicy);
Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
Assert.assertEquals(dbRangerPolicy.getGuid(), rangerPolicy.getGuid());
Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName());
Assert.assertEquals(dbRangerPolicy.getIsEnabled(), rangerPolicy.getIsEnabled());
Assert.assertEquals(dbRangerPolicy.getVersion(), rangerPolicy.getVersion());
Assert.assertEquals(dbRangerPolicy.getDescription(), rangerPolicy.getDescription());
Mockito.verify(daoManager).getXXService();
}
use of org.apache.ranger.plugin.model.RangerPolicy 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());
}
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class TestAssetREST method rangerPolicy.
private RangerPolicy rangerPolicy(Long id) {
List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
List<String> users = new ArrayList<String>();
List<String> groups = new ArrayList<String>();
List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
rangerPolicyItem.setAccesses(accesses);
rangerPolicyItem.setConditions(conditions);
rangerPolicyItem.setGroups(groups);
rangerPolicyItem.setUsers(users);
rangerPolicyItem.setDelegateAdmin(false);
policyItems.add(rangerPolicyItem);
Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
rangerPolicyResource.setIsExcludes(true);
rangerPolicyResource.setIsRecursive(true);
rangerPolicyResource.setValue("1");
rangerPolicyResource.setValues(users);
policyResource.put("resource", rangerPolicyResource);
RangerPolicy policy = new RangerPolicy();
policy.setId(id);
policy.setCreateTime(new Date());
policy.setDescription("policy");
policy.setGuid("policyguid");
policy.setIsEnabled(true);
policy.setName("HDFS_1-1-20150316062453");
policy.setUpdatedBy("Admin");
policy.setUpdateTime(new Date());
policy.setService("HDFS_1-1-20150316062453");
policy.setIsAuditEnabled(true);
policy.setPolicyItems(policyItems);
policy.setResources(policyResource);
policy.setService("HDFS_1");
return policy;
}
Aggregations