Search in sources :

Example 11 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao in project ranger by apache.

the class TestRangerPolicyService method test8getTransactionLog.

@Test
public void test8getTransactionLog() {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    XXService xService = xService();
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByName(rangerPolicy.getService())).thenReturn(xService);
    List<XXTrxLog> dbXXTrxLogList = policyService.getTransactionLog(rangerPolicy, 1);
    Assert.assertNotNull(dbXXTrxLogList);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) Test(org.junit.Test)

Example 12 with XXServiceDao

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);
    RangerPolicy rangerPolicy = rangerPolicy();
    XXPolicy policy = policy();
    int OPERATION_CONTEXT = 0;
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByName(rangerPolicy.getService())).thenReturn(xService);
    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();
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Example 13 with XXServiceDao

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();
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Example 14 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao in project ranger by apache.

the class TestTagREST method test57getSecureServiceTagsIfUpdated.

@Test
public void test57getSecureServiceTagsIfUpdated() {
    boolean isAdmin = false;
    boolean isKeyAdmin = false;
    boolean isAllowed = true;
    ServiceTags oldServiceTag = null;
    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) {
    }
    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);
    try {
        Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
    } catch (Exception e) {
    }
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) WebApplicationException(javax.ws.rs.WebApplicationException) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 15 with XXServiceDao

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)).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) {
    }
    try {
        Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
    } catch (Exception e) {
    }
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

XXServiceDao (org.apache.ranger.db.XXServiceDao)20 XXService (org.apache.ranger.entity.XXService)19 Test (org.junit.Test)17 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)13 XXServiceDef (org.apache.ranger.entity.XXServiceDef)13 RangerService (org.apache.ranger.plugin.model.RangerService)9 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)6 ExpectedException (org.junit.rules.ExpectedException)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)4 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)4 VXString (org.apache.ranger.view.VXString)4 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)3 XXPolicy (org.apache.ranger.entity.XXPolicy)3 XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1