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