Search in sources :

Example 16 with XXServiceDefDao

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

the class TestRangerServiceServiceBase method test1MapViewToEntityBean.

@Test
public void test1MapViewToEntityBean() {
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    RangerService rangerService = rangerService();
    XXService service = service();
    int OPERATION_CONTEXT = 1;
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.findByName(rangerService.getType())).thenReturn(xServiceDef);
    XXService dbService = rangerServiceService.mapViewToEntityBean(rangerService, service, OPERATION_CONTEXT);
    Assert.assertNotNull(dbService);
    Assert.assertEquals(dbService, service);
    Assert.assertEquals(dbService.getDescription(), service.getDescription());
    Assert.assertEquals(dbService.getGuid(), service.getGuid());
    Assert.assertEquals(dbService.getName(), service.getName());
    Assert.assertEquals(dbService.getAddedByUserId(), service.getAddedByUserId());
    Assert.assertEquals(dbService.getId(), service.getId());
    Assert.assertEquals(dbService.getVersion(), service.getVersion());
    Assert.assertEquals(dbService.getType(), service.getType());
    Assert.assertEquals(dbService.getUpdatedByUserId(), service.getUpdatedByUserId());
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) Test(org.junit.Test)

Example 17 with XXServiceDefDao

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

the class TestServiceREST method test8updateServiceDef.

@Test
public void test8updateServiceDef() throws Exception {
    RangerService rangerService = rangerService();
    XXServiceDef xServiceDef = serviceDef();
    HttpServletRequest request = null;
    Map<String, Object> options = null;
    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.updateService((RangerService) Mockito.any(), (Map<String, Object>) Mockito.any())).thenReturn(rangerService);
    RangerService dbRangerService = serviceREST.updateService(rangerService, request);
    Assert.assertNotNull(dbRangerService);
    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(daoManager).getXXServiceDef();
    Mockito.verify(svcStore).updateService(rangerService, options);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerService(org.apache.ranger.plugin.model.RangerService) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 18 with XXServiceDefDao

use of org.apache.ranger.db.XXServiceDefDao 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 19 with XXServiceDefDao

use of org.apache.ranger.db.XXServiceDefDao 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)

Example 20 with XXServiceDefDao

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

the class TestServiceREST method test19getPolicyFalse.

@Test
public void test19getPolicyFalse() throws Exception {
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(svcStore.getPolicy(rangerPolicy.getId())).thenReturn(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(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.getPolicy(rangerPolicy.getId());
    Assert.assertNotNull(dbRangerPolicy);
    Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
    Mockito.verify(svcStore).getPolicy(rangerPolicy.getId());
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

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