use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestRangerServiceService method test3PopulateViewBean.
@Test
public void test3PopulateViewBean() {
XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXService xService = xService();
String name = "fdfdfds";
List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
XXServiceConfigMap xConfMap = new XXServiceConfigMap();
xConfMap.setAddedByUserId(null);
xConfMap.setConfigkey(name);
xConfMap.setConfigvalue(name);
xConfMap.setCreateTime(new Date());
xConfMap.setServiceId(null);
xConfMap.setUpdatedByUserId(null);
xConfMap.setUpdateTime(new Date());
svcConfigMapList.add(xConfMap);
XXPortalUser tUser = new XXPortalUser();
tUser.setAddedByUserId(userId);
tUser.setCreateTime(new Date());
tUser.setEmailAddress("test@gmail.com");
tUser.setFirstName(name);
tUser.setId(userId);
tUser.setLastName(name);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setAddedByUserId(userId);
xServiceDef.setCreateTime(new Date());
xServiceDef.setDescription("test");
xServiceDef.setGuid("1427365526516_835_0");
xServiceDef.setId(userId);
XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
serviceVersionInfo.setServiceId(xService.getId());
serviceVersionInfo.setPolicyVersion(xService.getPolicyVersion());
serviceVersionInfo.setPolicyUpdateTime(xService.getPolicyUpdateTime());
serviceVersionInfo.setTagVersion(xService.getTagVersion());
serviceVersionInfo.setTagUpdateTime(xService.getTagUpdateTime());
Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
Mockito.when(xServiceVersionInfoDao.findByServiceId(xService.getId())).thenReturn(serviceVersionInfo);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(tUser);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
Mockito.when(xServiceConfigMapDao.findByServiceId(xService.getId())).thenReturn(svcConfigMapList);
RangerService dbService = serviceService.populateViewBean(xService);
Assert.assertNotNull(dbService);
Assert.assertEquals(userId, dbService.getId());
Assert.assertEquals(xService.getAddedByUserId(), dbService.getId());
Assert.assertEquals(xService.getId(), dbService.getId());
Assert.assertEquals(xService.getDescription(), dbService.getDescription());
Assert.assertEquals(xService.getGuid(), dbService.getGuid());
Assert.assertEquals(xService.getName(), dbService.getName());
Assert.assertEquals(xService.getPolicyUpdateTime(), dbService.getPolicyUpdateTime());
Assert.assertEquals(xService.getPolicyVersion(), dbService.getPolicyVersion());
Assert.assertEquals(xService.getVersion(), dbService.getVersion());
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(daoManager).getXXServiceConfigMap();
}
use of org.apache.ranger.entity.XXServiceDef 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.entity.XXServiceDef in project ranger by apache.
the class TestAssetREST method testGetAccessLogsForKms.
@Test
public void testGetAccessLogsForKms() {
SearchCriteria searchCriteria = new SearchCriteria();
List<SortField> sortFields = null;
List<VXAccessAudit> vXAccessAudits = new ArrayList<VXAccessAudit>();
VXAccessAuditList vXAccessAuditList = new VXAccessAuditList();
vXAccessAuditList.setVXAccessAudits(vXAccessAudits);
Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("test");
Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Integer) 8);
Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(new Date());
Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l);
Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l);
Mockito.when(msBizUtil.isKeyAdmin()).thenReturn(true);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xxServiceDefDao);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setId(Id);
Mockito.when(xxServiceDefDao.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME)).thenReturn(xServiceDef);
Mockito.when(assetMgr.getAccessLogs(searchCriteria)).thenReturn(vXAccessAuditList);
VXAccessAuditList expectedVXAccessAuditList = assetREST.getAccessLogs(request);
Assert.assertEquals(vXAccessAuditList, expectedVXAccessAuditList);
Mockito.verify(msBizUtil).isKeyAdmin();
Mockito.verify(assetMgr).getAccessLogs(searchCriteria);
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(searchUtil, Mockito.times(12)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.nullable(String.class));
Mockito.verify(searchUtil, Mockito.times(4)).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
Mockito.verify(searchUtil).extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
}
use of org.apache.ranger.entity.XXServiceDef 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);
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestServiceREST method test17updatePolicyFalse.
@Test
public void test17updatePolicyFalse() throws Exception {
RangerPolicy rangerPolicy = rangerPolicy();
String userName = "admin";
Set<String> userGroupsList = new HashSet<String>();
userGroupsList.add("group1");
userGroupsList.add("group2");
List<RangerAccessTypeDef> rangerAccessTypeDefList = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
rangerAccessTypeDefObj.setLabel("Read");
rangerAccessTypeDefObj.setName("read");
rangerAccessTypeDefObj.setRbKeyLabel(null);
rangerAccessTypeDefList.add(rangerAccessTypeDefObj);
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(Mockito.anyString())).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
RangerPolicy dbRangerPolicy = serviceREST.updatePolicy(rangerPolicy);
Assert.assertNull(dbRangerPolicy);
Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
}
Aggregations