@Test public void test02CreateUser() { setup(); XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class); XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class); VXPortalUser userProfile = userProfile(); Collection<String> userRoleList = new ArrayList<String>(); userRoleList.add("ROLE_USER"); userProfile.setUserRoleList(userRoleList); XXPortalUser user = new XXPortalUser(); user.setEmailAddress(userProfile.getEmailAddress()); user.setFirstName(userProfile.getFirstName()); user.setLastName(userProfile.getLastName()); user.setLoginId(userProfile.getLoginId()); user.setPassword(userProfile.getPassword()); user.setUserSource(userProfile.getUserSource()); user.setPublicScreenName(userProfile.getPublicScreenName()); user.setId(userProfile.getId()); XXPortalUserRole XXPortalUserRole = new XXPortalUserRole(); XXPortalUserRole.setId(user.getId()); XXPortalUserRole.setUserRole("ROLE_USER"); List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>(); list.add(XXPortalUserRole); Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao); Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user); Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao); Mockito.when(roleDao.findByUserId(userId)).thenReturn(list); Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser(); XXPortalUser dbxxPortalUser = userMgr.createUser(userProfile, 1); userId = dbxxPortalUser.getId(); Assert.assertNotNull(dbxxPortalUser); Assert.assertEquals(userId, dbxxPortalUser.getId()); Assert.assertEquals(userProfile.getFirstName(),dbxxPortalUser.getFirstName()); Assert.assertEquals(userProfile.getFirstName(),dbxxPortalUser.getFirstName()); Assert.assertEquals(userProfile.getLastName(),dbxxPortalUser.getLastName()); Assert.assertEquals(userProfile.getLoginId(),dbxxPortalUser.getLoginId()); Assert.assertEquals(userProfile.getEmailAddress(),dbxxPortalUser.getEmailAddress()); Assert.assertEquals(userProfile.getPassword(),dbxxPortalUser.getPassword()); Mockito.verify(daoManager).getXXPortalUser(); Mockito.verify(daoManager).getXXPortalUserRole(); }
public XXPortalUser createUser(VXPortalUser userProfile, int userStatus, Collection<String> userRoleList) { XXPortalUser user = mapVXPortalUserToXXPortalUser(userProfile); checkAdminAccess(); rangerBizUtil.blockAuditorRoleUser(); List<String> userRolesList = new ArrayList<String>(userRoleList); xUserMgr.checkAccessRoles(userRolesList); user = createUser(user, userStatus, userRoleList); return user; }
UserMgr { public XXPortalUser createUser(VXPortalUser userProfile, int userStatus, Collection<String> userRoleList) { XXPortalUser user = mapVXPortalUserToXXPortalUser(userProfile); checkAdminAccess(); rangerBizUtil.blockAuditorRoleUser(); List<String> userRolesList = new ArrayList<String>(userRoleList); xUserMgr.checkAccessRoles(userRolesList); user = createUser(user, userStatus, userRoleList); return user; } }
UserMgr { public XXPortalUser createUser(VXPortalUser userProfile, int userStatus, Collection<String> userRoleList) { XXPortalUser user = mapVXPortalUserToXXPortalUser(userProfile); checkAdminAccess(); rangerBizUtil.blockAuditorRoleUser(); List<String> userRolesList = new ArrayList<String>(userRoleList); xUserMgr.checkAccessRoles(userRolesList); user = createUser(user, userStatus, userRoleList); return user; } UserMgr(); }
UserMgr { public XXPortalUser createUser(VXPortalUser userProfile, int userStatus, Collection<String> userRoleList) { XXPortalUser user = mapVXPortalUserToXXPortalUser(userProfile); checkAdminAccess(); rangerBizUtil.blockAuditorRoleUser(); List<String> userRolesList = new ArrayList<String>(userRoleList); xUserMgr.checkAccessRoles(userRolesList); user = createUser(user, userStatus, userRoleList); return user; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForUpdate(XXPortalUser gjUser); String encrypt(String loginId, String password); String encryptWithOlderAlgo(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword,boolean logAudits); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updateOldUserName(String userLoginId,String newUserName, String currentPassword); }
UserMgr { public XXPortalUser createUser(VXPortalUser userProfile, int userStatus, Collection<String> userRoleList) { XXPortalUser user = mapVXPortalUserToXXPortalUser(userProfile); checkAdminAccess(); rangerBizUtil.blockAuditorRoleUser(); List<String> userRolesList = new ArrayList<String>(userRoleList); xUserMgr.checkAccessRoles(userRolesList); user = createUser(user, userStatus, userRoleList); return user; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForUpdate(XXPortalUser gjUser); String encrypt(String loginId, String password); String encryptWithOlderAlgo(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword,boolean logAudits); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updateOldUserName(String userLoginId,String newUserName, String currentPassword);  }