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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations