Search in sources :

Example 81 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserREST method test12DeactivateUser.

@Test
public void test12DeactivateUser() {
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp = null;
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUserExp);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.anyString())).thenReturn(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userREST.deactivateUser(userId);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 82 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserREST method test16ChangePassword.

@Test
public void test16ChangePassword() {
    XXPortalUser xxPUser = new XXPortalUser();
    VXResponse vxResponseExp = new VXResponse();
    vxResponseExp.setStatusCode(10);
    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);
    VXResponse vxResponseAct = userREST.changePassword(userId, changePassword);
    Assert.assertNotNull(vxResponseAct);
    Assert.assertEquals(vxResponseExp, vxResponseAct);
    Assert.assertEquals(vxResponseExp.getStatusCode(), vxResponseAct.getStatusCode());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(userManager).checkAccessForUpdate(xxPUser);
    Mockito.verify(changePassword).setId(userId);
    Mockito.verify(userManager).changePassword(changePassword);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 83 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserREST method test9Update.

@Test
public void test9Update() {
    VXPortalUser vxPUserExp = new VXPortalUser();
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp = null;
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.anyString())).thenReturn(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userREST.update(vxPUserExp, request);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(userManager).checkAccess(xxPUserExp);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
}
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 84 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserREST method test8Update.

@Test
public void test8Update() {
    VXPortalUser vxPUserExp = CreateVXPortalUser();
    vxPUserExp.setLoginId(loginId);
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp.setLoginId(loginId);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPUserExp);
    Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
    Mockito.doNothing().when(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
    Mockito.when(userManager.updateUser(vxPUserExp)).thenReturn(xxPUserExp);
    Mockito.when(userManager.mapXXPortalUserVXPortalUser(xxPUserExp)).thenReturn(vxPUserExp);
    VXPortalUser vxPUserAct = userREST.update(vxPUserExp, request);
    Assert.assertNotNull(vxPUserAct);
    Assert.assertEquals(xxPUserExp.getLoginId(), vxPUserAct.getLoginId());
    Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
    Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(userManager).checkAccess(xxPUserExp);
    Mockito.verify(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
    Mockito.verify(userManager).updateUser(vxPUserExp);
    Mockito.verify(userManager).mapXXPortalUserVXPortalUser(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 85 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestXUserMgr method test111CreateOrUpdateXUsers.

@Test
public void test111CreateOrUpdateXUsers() {
    destroySession();
    setup();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    VXUser vXUser = vxUser();
    VXUser vXUser1 = vxUser();
    vXUser.setFirstName("null");
    vXUser.setLastName("null");
    vXUser.setEmailAddress("");
    vXUser1.setName("null");
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add(RangerConstants.ROLE_USER);
    userRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
    userRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
    vXUser.setUserRoleList(userRoleList);
    vXUser1.setUserRoleList(userRoleList);
    vXUserList.add(vXUser);
    vXUserList.add(vXUser1);
    VXUserList users = new VXUserList(vXUserList);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    XXUser xXUser = xxUser(vXUser);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setFirstName("null");
    vXPortalUser.setLastName("null");
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(null);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(userMgr.mapVXPortalUserToXXPortalUser((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    XXUser xUser = xxUser(vXUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(daoManager.getXXUser().findByUserName(vXUser.getName())).thenReturn(xUser);
    Mockito.when(xUserService.populateViewBean(xUser)).thenReturn(vXUser);
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    xUserMgr.createOrUpdateXUsers(users);
    Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    xUserMgr.createOrUpdateXUsers(users);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserDao(org.apache.ranger.db.XXUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserList(org.apache.ranger.view.VXUserList) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)192 Test (org.junit.Test)113 ArrayList (java.util.ArrayList)93 VXPortalUser (org.apache.ranger.view.VXPortalUser)86 VXString (org.apache.ranger.view.VXString)82 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)74 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)46 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)44 XXUserPermission (org.apache.ranger.entity.XXUserPermission)36 UserSessionBase (org.apache.ranger.common.UserSessionBase)34 VXUser (org.apache.ranger.view.VXUser)34 WebApplicationException (javax.ws.rs.WebApplicationException)33 Date (java.util.Date)30 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)29 XXUser (org.apache.ranger.entity.XXUser)27 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)25 XXModuleDef (org.apache.ranger.entity.XXModuleDef)25 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 VXUserPermission (org.apache.ranger.view.VXUserPermission)19