Search in sources :

Example 21 with XXPortalUserDao

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

the class TestRangerServiceService method test4GetPopulatedViewObject.

@Test
public void test4GetPopulatedViewObject() {
    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.getPopulatedViewObject(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();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) XXServiceConfigMapDao(org.apache.ranger.db.XXServiceConfigMapDao) Date(java.util.Date) XXServiceConfigMap(org.apache.ranger.entity.XXServiceConfigMap) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao) Test(org.junit.Test)

Example 22 with XXPortalUserDao

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

the class TestUserREST method test11DeactivateUser.

@Test
public void test11DeactivateUser() {
    VXPortalUser vxPUserExp = CreateVXPortalUser();
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp.setLoginId(loginId);
    xxPUserExp.setStatus(1);
    vxPUserExp.setStatus(5);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUserExp);
    Mockito.when(userManager.deactivateUser(xxPUserExp)).thenReturn(vxPUserExp);
    VXPortalUser vxPUserAct = userREST.deactivateUser(userId);
    Assert.assertNotNull(vxPUserAct);
    Assert.assertEquals(xxPUserExp.getLoginId(), vxPUserAct.getLoginId());
    Assert.assertEquals(vxPUserExp.getStatus(), vxPUserAct.getStatus());
    Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
    Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(userManager).deactivateUser(xxPUserExp);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 23 with XXPortalUserDao

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

the class TestUserREST method test18ChangeEmailAddress.

@Test
public void test18ChangeEmailAddress() {
    XXPortalUser xxPUser = new XXPortalUser();
    VXPortalUser vxPUserExp = CreateVXPortalUser();
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    VXPortalUser vxPortalUserAct = userREST.changeEmailAddress(userId, changePassword);
    Assert.assertNotNull(vxPortalUserAct);
    Assert.assertEquals(vxPUserExp, vxPortalUserAct);
    Assert.assertEquals(vxPUserExp.getId(), vxPortalUserAct.getId());
    Assert.assertEquals(vxPUserExp.getFirstName(), vxPortalUserAct.getFirstName());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(userManager).checkAccessForUpdate(xxPUser);
    Mockito.verify(changePassword).setId(userId);
    Mockito.verify(userManager).changeEmailAddress(xxPUser, changePassword);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 24 with XXPortalUserDao

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

the class TestRangerBizUtil method testGetXUserId_NoUser.

@Test
public void testGetXUserId_NoUser() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    XXPortalUser xxPortalUser = new XXPortalUser();
    xxPortalUser.setId(id);
    xxPortalUser.setLoginId("12121");
    context.getUserSession().setXXPortalUser(xxPortalUser);
    XXUser xxUser = new XXUser();
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPortalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Long chk = rangerBizUtil.getXUserId();
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertNull(chk);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) XXUserDao(org.apache.ranger.db.XXUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 25 with XXPortalUserDao

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

the class TestRangerBizUtil method testGetXUserId.

@Test
public void testGetXUserId() {
    XXPortalUser xxPortalUser = new XXPortalUser();
    xxPortalUser.setId(id);
    xxPortalUser.setLoginId("12121");
    XXUser xxUser = new XXUser();
    xxUser.setId(id);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    RangerSecurityContext context = new RangerSecurityContext();
    UserSessionBase userSessionBase = new UserSessionBase();
    userSessionBase.setUserAdmin(true);
    context.setUserSession(userSessionBase);
    userSessionBase.setXXPortalUser(xxPortalUser);
    RangerContextHolder.setSecurityContext(context);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPortalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Long chk = rangerBizUtil.getXUserId();
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertEquals(chk, id);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) XXUserDao(org.apache.ranger.db.XXUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Aggregations

XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)35 Test (org.junit.Test)34 XXPortalUser (org.apache.ranger.entity.XXPortalUser)32 VXPortalUser (org.apache.ranger.view.VXPortalUser)21 ArrayList (java.util.ArrayList)16 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)13 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)12 VXString (org.apache.ranger.view.VXString)11 Date (java.util.Date)10 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)9 XXUserPermission (org.apache.ranger.entity.XXUserPermission)9 WebApplicationException (javax.ws.rs.WebApplicationException)7 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)7 XXModuleDef (org.apache.ranger.entity.XXModuleDef)6 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)5 XXUserDao (org.apache.ranger.db.XXUserDao)5 XXUser (org.apache.ranger.entity.XXUser)5 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)4