use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestServiceREST method test5getServiceDefByName.
@Test
public void test5getServiceDefByName() throws Exception {
RangerServiceDef rangerServiceDef = rangerServiceDef();
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.findByName(xServiceDef.getName())).thenReturn(xServiceDef);
Mockito.when(!bizUtil.hasAccess(xServiceDef, null)).thenReturn(true);
Mockito.when(svcStore.getServiceDefByName(rangerServiceDef.getName())).thenReturn(rangerServiceDef);
RangerServiceDef dbRangerServiceDef = serviceREST.getServiceDefByName(rangerServiceDef.getName());
Assert.assertNotNull(dbRangerServiceDef);
Assert.assertEquals(dbRangerServiceDef.getName(), rangerServiceDef.getName());
Mockito.verify(svcStore).getServiceDefByName(rangerServiceDef.getName());
Mockito.verify(daoManager).getXXServiceDef();
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestServiceREST method test12deleteServiceDef.
@Test
public void test12deleteServiceDef() {
RangerServiceDef rangerServiceDef = rangerServiceDef();
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(validatorFactory.getServiceDefValidator(svcStore)).thenReturn(serviceDefValidator);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(Id)).thenReturn(xServiceDef);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
serviceREST.deleteServiceDef(rangerServiceDef.getId(), request);
Mockito.verify(validatorFactory).getServiceDefValidator(svcStore);
Mockito.verify(daoManager).getXXServiceDef();
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestServiceREST method serviceDef.
private XXServiceDef serviceDef() {
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setAddedByUserId(Id);
xServiceDef.setCreateTime(new Date());
xServiceDef.setDescription("HDFS Repository");
xServiceDef.setGuid("1427365526516_835_0");
xServiceDef.setId(Id);
xServiceDef.setUpdateTime(new Date());
xServiceDef.setUpdatedByUserId(Id);
xServiceDef.setImplclassname("RangerServiceHdfs");
xServiceDef.setLabel("HDFS Repository");
xServiceDef.setRbkeylabel(null);
xServiceDef.setRbkeydescription(null);
xServiceDef.setIsEnabled(true);
return xServiceDef;
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestTagREST method test56getSecureServiceTagsIfUpdatedIsAllowedFalse.
@Test
public void test56getSecureServiceTagsIfUpdatedIsAllowedFalse() {
boolean isAdmin = false;
boolean isKeyAdmin = false;
boolean isAllowed = false;
ServiceTags oldServiceTag = new ServiceTags();
oldServiceTag.setServiceName(serviceName);
oldServiceTag.setTagVersion(5L);
XXService xService = new XXService();
xService.setId(id);
xService.setName(serviceName);
xService.setType(5L);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setId(id);
xServiceDef.setVersion(5L);
RangerService rangerService = new RangerService();
rangerService.setId(id);
rangerService.setName(serviceName);
XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
try {
Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
} catch (Exception e) {
}
Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
Mockito.verify(bizUtil).isAdmin();
Mockito.verify(bizUtil).isKeyAdmin();
Mockito.verify(daoManager).getXXService();
Mockito.verify(xXServiceDao).findByName(serviceName);
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(xXServiceDefDao).getById(xService.getType());
try {
Mockito.verify(svcStore).getServiceByName(serviceName);
} catch (Exception e) {
}
Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestTagREST method test55getSecureServiceTagsIfUpdatedIsAdminFalse.
@Test
public void test55getSecureServiceTagsIfUpdatedIsAdminFalse() {
boolean isAdmin = false;
boolean isKeyAdmin = false;
boolean isAllowed = true;
ServiceTags oldServiceTag = new ServiceTags();
oldServiceTag.setServiceName(serviceName);
oldServiceTag.setTagVersion(5L);
XXService xService = new XXService();
xService.setId(id);
xService.setName(serviceName);
xService.setType(5L);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setId(id);
xServiceDef.setVersion(5L);
RangerService rangerService = new RangerService();
rangerService.setId(id);
rangerService.setName(serviceName);
XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
try {
Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
} catch (Exception e) {
}
Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
try {
Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
} catch (Exception e) {
}
ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
Assert.assertNotNull(result.getServiceName());
Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
Mockito.verify(bizUtil).isAdmin();
Mockito.verify(bizUtil).isKeyAdmin();
Mockito.verify(daoManager).getXXService();
Mockito.verify(xXServiceDao).findByName(serviceName);
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(xXServiceDefDao).getById(xService.getType());
try {
Mockito.verify(svcStore).getServiceByName(serviceName);
} catch (Exception e) {
}
Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
try {
Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
} catch (Exception e) {
}
}
Aggregations