use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestRangerPolicyServiceBase method test2mapViewToEntityBeanNullValue.
@Test
public void test2mapViewToEntityBeanNullValue() {
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
RangerPolicy rangerPolicy = rangerPolicy();
XXPolicy policy = policy();
int OPERATION_CONTEXT = 0;
Mockito.when(restErrorUtil.createRESTException("No corresponding service found for policyName: " + rangerPolicy.getName() + "Service Not Found : " + rangerPolicy.getName(), MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(rangerPolicy.getService())).thenReturn(null);
XXPolicy dbPolicy = policyService.mapViewToEntityBean(rangerPolicy, policy, OPERATION_CONTEXT);
Assert.assertNotNull(dbPolicy);
Assert.assertEquals(dbPolicy.getId(), policy.getId());
Assert.assertEquals(dbPolicy.getGuid(), policy.getGuid());
Assert.assertEquals(dbPolicy.getName(), policy.getName());
Assert.assertEquals(dbPolicy.getAddedByUserId(), policy.getAddedByUserId());
Assert.assertEquals(dbPolicy.getIsEnabled(), policy.getIsEnabled());
Assert.assertEquals(dbPolicy.getVersion(), policy.getVersion());
Assert.assertEquals(dbPolicy.getDescription(), policy.getDescription());
Mockito.verify(daoManager).getXXService();
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestRangerPolicyServiceBase method test1mapViewToEntityBean.
@Test
public void test1mapViewToEntityBean() {
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXService xService = Mockito.mock(XXService.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
RangerPolicy rangerPolicy = rangerPolicy();
XXPolicy policy = policy();
int OPERATION_CONTEXT = 0;
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(rangerPolicy.getService())).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
XXPolicy dbPolicy = policyService.mapViewToEntityBean(rangerPolicy, policy, OPERATION_CONTEXT);
Assert.assertNotNull(dbPolicy);
Assert.assertEquals(dbPolicy.getId(), policy.getId());
Assert.assertEquals(dbPolicy.getGuid(), policy.getGuid());
Assert.assertEquals(dbPolicy.getName(), policy.getName());
Assert.assertEquals(dbPolicy.getAddedByUserId(), policy.getAddedByUserId());
Assert.assertEquals(dbPolicy.getIsEnabled(), policy.getIsEnabled());
Assert.assertEquals(dbPolicy.getVersion(), policy.getVersion());
Assert.assertEquals(dbPolicy.getDescription(), policy.getDescription());
Mockito.verify(daoManager).getXXService();
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestServiceREST method test9deleteService.
@Test
public void test9deleteService() throws Exception {
RangerService rangerService = rangerService();
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getServiceValidator(svcStore)).thenReturn(serviceValidator);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
serviceREST.deleteService(rangerService.getId());
Mockito.verify(validatorFactory).getServiceValidator(svcStore);
Mockito.verify(daoManager).getXXService();
Mockito.verify(daoManager).getXXServiceDef();
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestServiceREST method test18deletePolicyFalse.
@Test
public void test18deletePolicyFalse() throws Exception {
RangerPolicy rangerPolicy = rangerPolicy();
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
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(svcStore.getPolicy(Id)).thenReturn(rangerPolicy);
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);
serviceREST.deletePolicy(rangerPolicy.getId());
Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestTagREST method test53getSecureServiceTagsIfUpdatedIsAdminTrue.
@Test
public void test53getSecureServiceTagsIfUpdatedIsAdminTrue() {
boolean isAdmin = true;
boolean isKeyAdmin = 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) {
}
try {
Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion, true)).thenReturn(oldServiceTag);
} catch (Exception e) {
}
ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, false, capabilityVector, 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) {
}
try {
Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion, true);
} catch (Exception e) {
}
}
Aggregations