|
@@ -1,406 +1,406 @@
|
|
|
-package com.mooctest.crowd.domain.repository;
|
|
|
-
|
|
|
-import com.mooctest.crowd.domain.dao.*;
|
|
|
-import com.mooctest.crowd.domain.domainobject.*;
|
|
|
-import com.mooctest.crowd.domain.exception.PermissionNotFoundException;
|
|
|
-import com.mooctest.crowd.domain.exception.RoleNotFoundException;
|
|
|
-import com.mooctest.crowd.domain.exception.UserNotExistException;
|
|
|
-import com.mooctest.crowd.domain.model.*;
|
|
|
-import org.junit.Assert;
|
|
|
-import org.junit.Before;
|
|
|
-import org.junit.Test;
|
|
|
-import org.junit.runner.RunWith;
|
|
|
-import org.mockito.InjectMocks;
|
|
|
-import org.mockito.Mock;
|
|
|
-import org.mockito.MockitoAnnotations;
|
|
|
-import org.mockito.runners.MockitoJUnitRunner;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
-import static org.mockito.Matchers.*;
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
-
|
|
|
-@RunWith(MockitoJUnitRunner.class)
|
|
|
-public class UserRepoTest {
|
|
|
- @InjectMocks
|
|
|
- private UserRepo userRepo = new UserRepo();
|
|
|
-
|
|
|
- @Mock
|
|
|
- private UserDao userDao;
|
|
|
- @Mock
|
|
|
- private UserToRoleDao userToRoleDao;
|
|
|
- @Mock
|
|
|
- private RoleDao roleDao;
|
|
|
- @Mock
|
|
|
- private RoleToPermissionDao roleToPermissionDao;
|
|
|
- @Mock
|
|
|
- private PermissionDao permissionDao;
|
|
|
- @Mock
|
|
|
- private EvaluationAgencyDao evaluationAgencyDao;
|
|
|
- @Mock
|
|
|
- private RegionalManagerToRegionalDao regionalManagerToRegionalDao;
|
|
|
- @Mock
|
|
|
- private RegionalDao regionalDao;
|
|
|
- @Mock
|
|
|
- private AgencyAbilityDao agencyAbilityDao;
|
|
|
- @Mock
|
|
|
- private AgencyResourceDao agencyResourceDao;
|
|
|
- @Mock
|
|
|
- private PersonalAuthenticationDao personalAuthenticationDao;
|
|
|
-
|
|
|
- @Mock
|
|
|
- private EvaluationAgencyRepo resourceRepo;
|
|
|
-
|
|
|
- private UserPO expectUserPO;
|
|
|
- private RolePO expectRolePO;
|
|
|
- private PermissionPO expectPermission;
|
|
|
- private List<UserToRolePO> expectUserToRolePOList;
|
|
|
- private List<RoleToPermissionPO> expectRoleToPermissionPOList;
|
|
|
- private UserToRolePO expectUserToRolePO;
|
|
|
- private RoleToPermissionPO expectRoleToPermissionPO;
|
|
|
- private RegionalManagerToRegionalPO expectRegionalPOManagerPO;
|
|
|
- private EvaluationAgencyPO expectEvaluationAgencyPO;
|
|
|
- private RegionalPO expectRegionalPO;
|
|
|
- private EvaluationAgencyAbilityPO evaluationAgencyAbilityPO;
|
|
|
- private EvaluationAgencyResourcePO evaluationAgencyResourcePO;
|
|
|
- private PersonalAuthenticationPO personalAuthenticationPO;
|
|
|
- private List<RegionalManagerToRegionalPO> expectRegionalPOManagerList = new ArrayList<>();
|
|
|
- private List<EvaluationAgencyPO> evaluationAgencyPOList = new ArrayList<>();
|
|
|
- private List<EvaluationAgencyAbilityPO> evaluationAgencyAbilityPOList = new ArrayList<>();
|
|
|
- private List<EvaluationAgencyResourcePO> evaluationAgencyResourcePOList = new ArrayList<>();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Before
|
|
|
- public void before() {
|
|
|
- MockitoAnnotations.initMocks(this);
|
|
|
-
|
|
|
- expectUserPO = new UserPO();
|
|
|
- expectUserPO.setId(1L);
|
|
|
- expectUserPO.setName("郭超");
|
|
|
- expectUserPO.setEmail("1021172957@qq.com");
|
|
|
- expectUserPO.setPassword("123456");
|
|
|
- expectUserPO.setMobile("13657094936");
|
|
|
-
|
|
|
- expectRolePO = new RolePO();
|
|
|
- expectRolePO.setId(1L);
|
|
|
- expectRolePO.setName("generalUser");
|
|
|
-
|
|
|
- expectUserToRolePO = new UserToRolePO();
|
|
|
- expectUserToRolePO.setId(1L);
|
|
|
- expectUserToRolePO.setRoleId(1L);
|
|
|
- expectUserToRolePO.setUserId(1L);
|
|
|
-
|
|
|
- expectPermission = new PermissionPO();
|
|
|
- expectPermission.setId(1L);
|
|
|
- expectPermission.setName("查看项目");
|
|
|
-
|
|
|
- expectRoleToPermissionPO = new RoleToPermissionPO();
|
|
|
- expectRoleToPermissionPO.setId(1L);
|
|
|
- expectRoleToPermissionPO.setPermissionId(1L);
|
|
|
-
|
|
|
- expectUserToRolePOList = new LinkedList<>();
|
|
|
- expectUserToRolePOList.add(expectUserToRolePO);
|
|
|
-
|
|
|
- expectRoleToPermissionPOList = new LinkedList<>();
|
|
|
- expectRoleToPermissionPOList.add(expectRoleToPermissionPO);
|
|
|
-
|
|
|
- expectEvaluationAgencyPO = new EvaluationAgencyPO();
|
|
|
- expectEvaluationAgencyPO.setId(1L);
|
|
|
- expectEvaluationAgencyPO.setIsAuthentication(-1);
|
|
|
- expectEvaluationAgencyPO.setBankAccount("123445666");
|
|
|
- expectEvaluationAgencyPO.setAgencyPhoto("http://mooctest.png");
|
|
|
- expectEvaluationAgencyPO.setUserId(1L);
|
|
|
- evaluationAgencyPOList.add(expectEvaluationAgencyPO);
|
|
|
-
|
|
|
- expectRegionalPO = new RegionalPO();
|
|
|
- expectRegionalPO.setId(1L);
|
|
|
-
|
|
|
- expectRegionalPOManagerPO = new RegionalManagerToRegionalPO();
|
|
|
- expectRegionalPOManagerPO.setId(1L);
|
|
|
- expectRegionalPOManagerPO.setUserId(1L);
|
|
|
-// expectRegionalPOManagerPO.set(1L);
|
|
|
- expectRegionalPOManagerList.add(expectRegionalPOManagerPO);
|
|
|
-
|
|
|
- evaluationAgencyAbilityPO = new EvaluationAgencyAbilityPO();
|
|
|
- evaluationAgencyAbilityPO.setId(1L);
|
|
|
- evaluationAgencyAbilityPO.setEvaluationAgencyId(1L);
|
|
|
- evaluationAgencyAbilityPO.setAbilityName("web测试");
|
|
|
- evaluationAgencyAbilityPOList.add(evaluationAgencyAbilityPO);
|
|
|
-
|
|
|
- evaluationAgencyResourcePO = new EvaluationAgencyResourcePO();
|
|
|
- evaluationAgencyResourcePO.setId(1L);
|
|
|
- evaluationAgencyResourcePO.setEvaluationAgencyId(1L);
|
|
|
- evaluationAgencyResourcePO.setTotalNum(10);
|
|
|
- evaluationAgencyResourcePO.setAvailableNum(5);
|
|
|
- evaluationAgencyResourcePOList.add(evaluationAgencyResourcePO);
|
|
|
-
|
|
|
- personalAuthenticationPO = new PersonalAuthenticationPO();
|
|
|
- personalAuthenticationPO.setUserId(expectUserPO.getId());
|
|
|
- when(personalAuthenticationDao.findByUserIdAndIsDeleted(expectUserPO.getId(),0)).thenReturn(personalAuthenticationPO);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_optional_when_get_by_id_success() {
|
|
|
- //arrange
|
|
|
- when(userDao.findById(anyLong())).thenReturn(Optional.of(expectUserPO));
|
|
|
- when(userToRoleDao.findByUserId(anyLong())).thenReturn(expectUserToRolePOList);
|
|
|
- when(roleDao.findById(anyLong())).thenReturn(Optional.of(expectRolePO));
|
|
|
- when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
- when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
- when(evaluationAgencyDao.findByUserId(anyLong())).thenReturn(expectEvaluationAgencyPO);
|
|
|
- when(agencyAbilityDao.findByEvaluationAgencyIdAndIsDeleted(anyLong(), anyInt())).thenReturn(evaluationAgencyAbilityPOList);
|
|
|
- when(agencyResourceDao.findByEvaluationAgencyIdAndIsDeleted(anyLong(), anyInt())).thenReturn(evaluationAgencyResourcePOList);
|
|
|
- when(regionalManagerToRegionalDao.findByUserId(anyLong())).thenReturn(expectRegionalPOManagerList);
|
|
|
- when(regionalDao.findById(anyLong())).thenReturn(Optional.of(expectRegionalPO));
|
|
|
- //action
|
|
|
- User user = userRepo.getByID(1L);
|
|
|
- //assert
|
|
|
- Assert.assertEquals(user.getId(),expectUserPO.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = UserNotExistException.class)
|
|
|
- public void should_throw_exception_when_get_by_id_get_null() {
|
|
|
- //arrange
|
|
|
- when(userDao.findById(anyLong())).thenReturn(Optional.empty());
|
|
|
- //action
|
|
|
- userRepo.getByID(1L);
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = RoleNotFoundException.class)
|
|
|
- public void should_throw_when_get_by_id_role_not_exist(){
|
|
|
- //arrange
|
|
|
- //arrange
|
|
|
- when(userDao.findById(anyLong())).thenReturn(Optional.of(expectUserPO));
|
|
|
- when(userToRoleDao.findByUserId(anyLong())).thenReturn(expectUserToRolePOList);
|
|
|
- when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
- when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
- when(evaluationAgencyDao.findByUserId(anyLong())).thenReturn(expectEvaluationAgencyPO);
|
|
|
- when(agencyAbilityDao.findByEvaluationAgencyIdAndIsDeleted(anyLong(), anyInt())).thenReturn(evaluationAgencyAbilityPOList);
|
|
|
- when(regionalManagerToRegionalDao.findByUserId(anyLong())).thenReturn(expectRegionalPOManagerList);
|
|
|
- when(regionalDao.findById(anyLong())).thenReturn(Optional.of(expectRegionalPO));
|
|
|
- when(roleDao.findById(anyLong())).thenReturn(Optional.empty());
|
|
|
- //action
|
|
|
- userRepo.getByID(1L);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_optional_when_get_by_mobile_number_success() {
|
|
|
- //arrange
|
|
|
- when(userDao.findByMobile("13657094936")).thenReturn(expectUserPO);
|
|
|
- when(userToRoleDao.findByUserId(anyLong())).thenReturn(expectUserToRolePOList);
|
|
|
- when(roleDao.findById(anyLong())).thenReturn(Optional.of(expectRolePO));
|
|
|
- when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
- when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
- //action
|
|
|
- User user = userRepo.getByMobileNum(expectUserPO.getMobile());
|
|
|
- //assert
|
|
|
- Assert.assertEquals(user.getId(),expectUserPO.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = UserNotExistException.class)
|
|
|
- public void should_throw_exception_when_get_by_mobile_number_get_null() {
|
|
|
- //arrange
|
|
|
- when(userDao.findByMobile(anyString())).thenReturn(null);
|
|
|
- //action
|
|
|
- userRepo.getByMobileNum("123");
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_when_save_user_and_role() {
|
|
|
- //arrange
|
|
|
- Role expectRole = new Role();
|
|
|
- List<Role> roleList = new LinkedList<>();
|
|
|
- roleList.add(expectRole);
|
|
|
- User user = new User();
|
|
|
- user.setRoleList(roleList);
|
|
|
- when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
- when(roleDao.findByName(anyString())).thenReturn(expectRolePO);
|
|
|
- when(userToRoleDao.save(any(UserToRolePO.class))).thenReturn(expectUserToRolePO);
|
|
|
- when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
- when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
- //action
|
|
|
- User resultUser = userRepo.saveUserAndRole(user);
|
|
|
- //assert
|
|
|
- Assert.assertEquals(resultUser.getId(), expectUserPO.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = PermissionNotFoundException.class)
|
|
|
- public void should_return_expert_when_save_user_and_role_permission_not_found() {
|
|
|
- //arrange
|
|
|
- Role expectRole = new Role();
|
|
|
- List<Role> roleList = new LinkedList<>();
|
|
|
- roleList.add(expectRole);
|
|
|
- User user = new User();
|
|
|
- user.setRoleList(roleList);
|
|
|
- when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
- when(roleDao.findByName(anyString())).thenReturn(expectRolePO);
|
|
|
- when(userToRoleDao.save(any(UserToRolePO.class))).thenReturn(expectUserToRolePO);
|
|
|
- when(roleToPermissionDao.findAllByRoleId(1L)).thenReturn(expectRoleToPermissionPOList);
|
|
|
- when(permissionDao.findById(anyLong())).thenReturn(Optional.empty());
|
|
|
- //action
|
|
|
- userRepo.saveUserAndRole(user);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_when_save_user() {
|
|
|
- //arrange
|
|
|
- List<Permission> permissionList = new LinkedList<>();
|
|
|
- Permission permission = new Permission();
|
|
|
- permissionList.add(permission);
|
|
|
- List<Role> roleList = new LinkedList<>();
|
|
|
- Role role = new Role();
|
|
|
- role.setId(1L);
|
|
|
- role.setPermissionList(permissionList);
|
|
|
- roleList.add(role);
|
|
|
- EvaluationAgency evaluationAgency = new EvaluationAgency();
|
|
|
- evaluationAgency.setId(1L);
|
|
|
- EvaluationAgencyAbility evaluationAgencyAbility = new EvaluationAgencyAbility();
|
|
|
- EvaluationAgencyResource evaluationAgencyResource = new EvaluationAgencyResource();
|
|
|
- List<EvaluationAgencyResource> evaluationAgencyResourceList = new ArrayList<>();
|
|
|
- List<EvaluationAgencyAbility> evaluationAgencyAbilityList = new ArrayList<>();
|
|
|
- evaluationAgencyAbility.setId(1L);
|
|
|
- evaluationAgencyAbility.setEvaluationAgencyId(1L);
|
|
|
- evaluationAgencyAbilityList.add(evaluationAgencyAbility);
|
|
|
-
|
|
|
- evaluationAgencyResource.setId(1L);
|
|
|
- evaluationAgencyResource.setEvaluationAgencyId(1L);
|
|
|
- evaluationAgencyResourceList.add(evaluationAgencyResource);
|
|
|
-
|
|
|
- evaluationAgency.setEvaluationAgencyAbilityList(evaluationAgencyAbilityList);
|
|
|
- evaluationAgency.setEvaluationAgencyResourceList(evaluationAgencyResourceList);
|
|
|
-
|
|
|
- User user = new User();
|
|
|
- user.setEvaluationAgency(evaluationAgency);
|
|
|
- user.setRoleList(roleList);
|
|
|
-
|
|
|
- expectUserPO.setId(0L);
|
|
|
-
|
|
|
- when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
- when(userDao.findById(any(Long.class))).thenReturn(Optional.of(expectUserPO));
|
|
|
- when(evaluationAgencyDao.save(any(EvaluationAgencyPO.class))).thenReturn(expectEvaluationAgencyPO);
|
|
|
- when(resourceRepo.saveEvaluationAgencyResource(any())).thenReturn(null);
|
|
|
- //action
|
|
|
- User resultUser = userRepo.saveUser(user);
|
|
|
- //assert
|
|
|
- Assert.assertEquals(resultUser.getId(),expectUserPO.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_when_save_user_role_is_null() {
|
|
|
- //arrange
|
|
|
- List<Permission> permissionList = new LinkedList<>();
|
|
|
- Permission permission = new Permission();
|
|
|
- permissionList.add(permission);
|
|
|
- List<Role> roleList = new LinkedList<>();
|
|
|
- Role role = new Role();
|
|
|
- role.setId(1L);
|
|
|
- role.setPermissionList(permissionList);
|
|
|
- roleList.add(role);
|
|
|
- EvaluationAgency evaluationAgency = new EvaluationAgency();
|
|
|
- evaluationAgency.setId(1L);
|
|
|
- EvaluationAgencyAbility evaluationAgencyAbility = new EvaluationAgencyAbility();
|
|
|
- EvaluationAgencyResource evaluationAgencyResource = new EvaluationAgencyResource();
|
|
|
- List<EvaluationAgencyResource> evaluationAgencyResourceList = new ArrayList<>();
|
|
|
- List<EvaluationAgencyAbility> evaluationAgencyAbilityList = new ArrayList<>();
|
|
|
- evaluationAgencyAbility.setId(1L);
|
|
|
- evaluationAgencyAbility.setEvaluationAgencyId(1L);
|
|
|
- evaluationAgencyAbilityList.add(evaluationAgencyAbility);
|
|
|
-
|
|
|
- evaluationAgencyResource.setId(1L);
|
|
|
- evaluationAgencyResource.setEvaluationAgencyId(1L);
|
|
|
- evaluationAgencyResourceList.add(evaluationAgencyResource);
|
|
|
-
|
|
|
- evaluationAgency.setEvaluationAgencyAbilityList(evaluationAgencyAbilityList);
|
|
|
- evaluationAgency.setEvaluationAgencyResourceList(evaluationAgencyResourceList);
|
|
|
-
|
|
|
- User user = new User();
|
|
|
- user.setEvaluationAgency(evaluationAgency);
|
|
|
- user.setRoleList(null);
|
|
|
-
|
|
|
- expectUserPO.setId(0L);
|
|
|
-
|
|
|
- when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
- when(userDao.findById(any(Long.class))).thenReturn(Optional.of(expectUserPO));
|
|
|
- when(evaluationAgencyDao.save(any(EvaluationAgencyPO.class))).thenReturn(expectEvaluationAgencyPO);
|
|
|
- when(resourceRepo.saveEvaluationAgencyResource(any())).thenReturn(null);
|
|
|
- //action
|
|
|
- User resultUser = userRepo.saveUser(user);
|
|
|
- //assert
|
|
|
- Assert.assertEquals(resultUser.getId(),expectUserPO.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_list_when_get_by_id_list() {
|
|
|
- //arrange
|
|
|
- List<UserPO> expectUserPOList = new LinkedList<>();
|
|
|
- expectUserPOList.add(new UserPO());
|
|
|
- expectUserPOList.add(new UserPO());
|
|
|
- when(userDao.findAllById(anyListOf(Long.class))).thenReturn(expectUserPOList);
|
|
|
- //action
|
|
|
- List<User> userList = userRepo.getByIdList(new LinkedList<>());
|
|
|
- //assert
|
|
|
- Assert.assertNotNull(userList);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_list_when_get_all_user() {
|
|
|
- //arrange
|
|
|
- List<UserPO> expectUserPOList = new LinkedList<>();
|
|
|
- expectUserPOList.add(new UserPO());
|
|
|
- expectUserPOList.add(new UserPO());
|
|
|
- when(userDao.findAll()).thenReturn(expectUserPOList);
|
|
|
- //action
|
|
|
- List<User> userList = userRepo.getAllUser();
|
|
|
- //assert
|
|
|
- Assert.assertNotNull(userList);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_void_when_remove_user() {
|
|
|
- //arrange
|
|
|
- User user = new User();
|
|
|
- //action
|
|
|
- userRepo.removeUser(user);
|
|
|
- //assert
|
|
|
- Assert.assertNull(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_void_when_remove_user_list() {
|
|
|
- //arrange
|
|
|
- List<User> userList = new LinkedList<>();
|
|
|
- userList.add(new User());
|
|
|
- //action
|
|
|
- userRepo.removeUserList(userList);
|
|
|
- //assert
|
|
|
- Assert.assertNull(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_user_list_when_get_apply_agency() {
|
|
|
- //arrange
|
|
|
- when(evaluationAgencyDao.findByIsAuthentication(-1)).thenReturn(evaluationAgencyPOList);
|
|
|
- when(userDao.findById(any(Long.class))).thenReturn(Optional.of(expectUserPO));
|
|
|
- //action
|
|
|
- List<User> applyAgencyList = userRepo.getApplyEvaluationAgencyByIsAuthenticated();
|
|
|
- //assert
|
|
|
- Assert.assertNotNull(applyAgencyList);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_role_when_get_role(){
|
|
|
- //arrange
|
|
|
- when(roleDao.findByName(anyString())).thenReturn(expectRolePO);
|
|
|
- //action
|
|
|
- Role role = userRepo.getRole(expectRolePO.getName());
|
|
|
- Assert.assertEquals(role.getName(),expectRolePO.getName());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.mooctest.crowd.domain.repository;
|
|
|
+//
|
|
|
+//import com.mooctest.crowd.domain.dao.*;
|
|
|
+//import com.mooctest.crowd.domain.domainobject.*;
|
|
|
+//import com.mooctest.crowd.domain.exception.PermissionNotFoundException;
|
|
|
+//import com.mooctest.crowd.domain.exception.RoleNotFoundException;
|
|
|
+//import com.mooctest.crowd.domain.exception.UserNotExistException;
|
|
|
+//import com.mooctest.crowd.domain.model.*;
|
|
|
+//import org.junit.Assert;
|
|
|
+//import org.junit.Before;
|
|
|
+//import org.junit.Test;
|
|
|
+//import org.junit.runner.RunWith;
|
|
|
+//import org.mockito.InjectMocks;
|
|
|
+//import org.mockito.Mock;
|
|
|
+//import org.mockito.MockitoAnnotations;
|
|
|
+//import org.mockito.runners.MockitoJUnitRunner;
|
|
|
+//
|
|
|
+//import java.util.ArrayList;
|
|
|
+//import java.util.LinkedList;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Optional;
|
|
|
+//
|
|
|
+//import static org.mockito.Matchers.*;
|
|
|
+//import static org.mockito.Mockito.when;
|
|
|
+//
|
|
|
+//@RunWith(MockitoJUnitRunner.class)
|
|
|
+//public class UserRepoTest {
|
|
|
+// @InjectMocks
|
|
|
+// private UserRepo userRepo = new UserRepo();
|
|
|
+//
|
|
|
+// @Mock
|
|
|
+// private UserDao userDao;
|
|
|
+// @Mock
|
|
|
+// private UserToRoleDao userToRoleDao;
|
|
|
+// @Mock
|
|
|
+// private RoleDao roleDao;
|
|
|
+// @Mock
|
|
|
+// private RoleToPermissionDao roleToPermissionDao;
|
|
|
+// @Mock
|
|
|
+// private PermissionDao permissionDao;
|
|
|
+// @Mock
|
|
|
+// private EvaluationAgencyDao evaluationAgencyDao;
|
|
|
+// @Mock
|
|
|
+// private RegionalManagerToRegionalDao regionalManagerToRegionalDao;
|
|
|
+// @Mock
|
|
|
+// private RegionalDao regionalDao;
|
|
|
+// @Mock
|
|
|
+// private AgencyAbilityDao agencyAbilityDao;
|
|
|
+// @Mock
|
|
|
+// private AgencyResourceDao agencyResourceDao;
|
|
|
+// @Mock
|
|
|
+// private PersonalAuthenticationDao personalAuthenticationDao;
|
|
|
+//
|
|
|
+// @Mock
|
|
|
+// private EvaluationAgencyRepo resourceRepo;
|
|
|
+//
|
|
|
+// private UserPO expectUserPO;
|
|
|
+// private RolePO expectRolePO;
|
|
|
+// private PermissionPO expectPermission;
|
|
|
+// private List<UserToRolePO> expectUserToRolePOList;
|
|
|
+// private List<RoleToPermissionPO> expectRoleToPermissionPOList;
|
|
|
+// private UserToRolePO expectUserToRolePO;
|
|
|
+// private RoleToPermissionPO expectRoleToPermissionPO;
|
|
|
+// private RegionalManagerToRegionalPO expectRegionalPOManagerPO;
|
|
|
+// private EvaluationAgencyPO expectEvaluationAgencyPO;
|
|
|
+// private RegionalPO expectRegionalPO;
|
|
|
+// private EvaluationAgencyAbilityPO evaluationAgencyAbilityPO;
|
|
|
+// private EvaluationAgencyResourcePO evaluationAgencyResourcePO;
|
|
|
+// private PersonalAuthenticationPO personalAuthenticationPO;
|
|
|
+// private List<RegionalManagerToRegionalPO> expectRegionalPOManagerList = new ArrayList<>();
|
|
|
+// private List<EvaluationAgencyPO> evaluationAgencyPOList = new ArrayList<>();
|
|
|
+// private List<EvaluationAgencyAbilityPO> evaluationAgencyAbilityPOList = new ArrayList<>();
|
|
|
+// private List<EvaluationAgencyResourcePO> evaluationAgencyResourcePOList = new ArrayList<>();
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// @Before
|
|
|
+// public void before() {
|
|
|
+// MockitoAnnotations.initMocks(this);
|
|
|
+//
|
|
|
+// expectUserPO = new UserPO();
|
|
|
+// expectUserPO.setId(1L);
|
|
|
+// expectUserPO.setName("郭超");
|
|
|
+// expectUserPO.setEmail("1021172957@qq.com");
|
|
|
+// expectUserPO.setPassword("123456");
|
|
|
+// expectUserPO.setMobile("13657094936");
|
|
|
+//
|
|
|
+// expectRolePO = new RolePO();
|
|
|
+// expectRolePO.setId(1L);
|
|
|
+// expectRolePO.setName("generalUser");
|
|
|
+//
|
|
|
+// expectUserToRolePO = new UserToRolePO();
|
|
|
+// expectUserToRolePO.setId(1L);
|
|
|
+// expectUserToRolePO.setRoleId(1L);
|
|
|
+// expectUserToRolePO.setUserId(1L);
|
|
|
+//
|
|
|
+// expectPermission = new PermissionPO();
|
|
|
+// expectPermission.setId(1L);
|
|
|
+// expectPermission.setName("查看项目");
|
|
|
+//
|
|
|
+// expectRoleToPermissionPO = new RoleToPermissionPO();
|
|
|
+// expectRoleToPermissionPO.setId(1L);
|
|
|
+// expectRoleToPermissionPO.setPermissionId(1L);
|
|
|
+//
|
|
|
+// expectUserToRolePOList = new LinkedList<>();
|
|
|
+// expectUserToRolePOList.add(expectUserToRolePO);
|
|
|
+//
|
|
|
+// expectRoleToPermissionPOList = new LinkedList<>();
|
|
|
+// expectRoleToPermissionPOList.add(expectRoleToPermissionPO);
|
|
|
+//
|
|
|
+// expectEvaluationAgencyPO = new EvaluationAgencyPO();
|
|
|
+// expectEvaluationAgencyPO.setId(1L);
|
|
|
+// expectEvaluationAgencyPO.setIsAuthentication(-1);
|
|
|
+// expectEvaluationAgencyPO.setBankAccount("123445666");
|
|
|
+// expectEvaluationAgencyPO.setAgencyPhoto("http://mooctest.png");
|
|
|
+// expectEvaluationAgencyPO.setUserId(1L);
|
|
|
+// evaluationAgencyPOList.add(expectEvaluationAgencyPO);
|
|
|
+//
|
|
|
+// expectRegionalPO = new RegionalPO();
|
|
|
+// expectRegionalPO.setId(1L);
|
|
|
+//
|
|
|
+// expectRegionalPOManagerPO = new RegionalManagerToRegionalPO();
|
|
|
+// expectRegionalPOManagerPO.setId(1L);
|
|
|
+// expectRegionalPOManagerPO.setUserId(1L);
|
|
|
+//// expectRegionalPOManagerPO.set(1L);
|
|
|
+// expectRegionalPOManagerList.add(expectRegionalPOManagerPO);
|
|
|
+//
|
|
|
+// evaluationAgencyAbilityPO = new EvaluationAgencyAbilityPO();
|
|
|
+// evaluationAgencyAbilityPO.setId(1L);
|
|
|
+// evaluationAgencyAbilityPO.setEvaluationAgencyId(1L);
|
|
|
+// evaluationAgencyAbilityPO.setAbilityName("web测试");
|
|
|
+// evaluationAgencyAbilityPOList.add(evaluationAgencyAbilityPO);
|
|
|
+//
|
|
|
+// evaluationAgencyResourcePO = new EvaluationAgencyResourcePO();
|
|
|
+// evaluationAgencyResourcePO.setId(1L);
|
|
|
+// evaluationAgencyResourcePO.setEvaluationAgencyId(1L);
|
|
|
+// evaluationAgencyResourcePO.setTotalNum(10);
|
|
|
+// evaluationAgencyResourcePO.setAvailableNum(5);
|
|
|
+// evaluationAgencyResourcePOList.add(evaluationAgencyResourcePO);
|
|
|
+//
|
|
|
+// personalAuthenticationPO = new PersonalAuthenticationPO();
|
|
|
+// personalAuthenticationPO.setUserId(expectUserPO.getId());
|
|
|
+// when(personalAuthenticationDao.findByUserIdAndIsDeleted(expectUserPO.getId(),0)).thenReturn(personalAuthenticationPO);
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_optional_when_get_by_id_success() {
|
|
|
+// //arrange
|
|
|
+// when(userDao.findById(anyLong())).thenReturn(Optional.of(expectUserPO));
|
|
|
+// when(userToRoleDao.findByUserId(anyLong())).thenReturn(expectUserToRolePOList);
|
|
|
+// when(roleDao.findById(anyLong())).thenReturn(Optional.of(expectRolePO));
|
|
|
+// when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
+// when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
+// when(evaluationAgencyDao.findByUserId(anyLong())).thenReturn(expectEvaluationAgencyPO);
|
|
|
+// when(agencyAbilityDao.findByEvaluationAgencyIdAndIsDeleted(anyLong(), anyInt())).thenReturn(evaluationAgencyAbilityPOList);
|
|
|
+// when(agencyResourceDao.findByEvaluationAgencyIdAndIsDeleted(anyLong(), anyInt())).thenReturn(evaluationAgencyResourcePOList);
|
|
|
+// when(regionalManagerToRegionalDao.findByUserId(anyLong())).thenReturn(expectRegionalPOManagerList);
|
|
|
+// when(regionalDao.findById(anyLong())).thenReturn(Optional.of(expectRegionalPO));
|
|
|
+// //action
|
|
|
+// User user = userRepo.getByID(1L);
|
|
|
+// //assert
|
|
|
+// Assert.assertEquals(user.getId(),expectUserPO.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = UserNotExistException.class)
|
|
|
+// public void should_throw_exception_when_get_by_id_get_null() {
|
|
|
+// //arrange
|
|
|
+// when(userDao.findById(anyLong())).thenReturn(Optional.empty());
|
|
|
+// //action
|
|
|
+// userRepo.getByID(1L);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = RoleNotFoundException.class)
|
|
|
+// public void should_throw_when_get_by_id_role_not_exist(){
|
|
|
+// //arrange
|
|
|
+// //arrange
|
|
|
+// when(userDao.findById(anyLong())).thenReturn(Optional.of(expectUserPO));
|
|
|
+// when(userToRoleDao.findByUserId(anyLong())).thenReturn(expectUserToRolePOList);
|
|
|
+// when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
+// when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
+// when(evaluationAgencyDao.findByUserId(anyLong())).thenReturn(expectEvaluationAgencyPO);
|
|
|
+// when(agencyAbilityDao.findByEvaluationAgencyIdAndIsDeleted(anyLong(), anyInt())).thenReturn(evaluationAgencyAbilityPOList);
|
|
|
+// when(regionalManagerToRegionalDao.findByUserId(anyLong())).thenReturn(expectRegionalPOManagerList);
|
|
|
+// when(regionalDao.findById(anyLong())).thenReturn(Optional.of(expectRegionalPO));
|
|
|
+// when(roleDao.findById(anyLong())).thenReturn(Optional.empty());
|
|
|
+// //action
|
|
|
+// userRepo.getByID(1L);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_optional_when_get_by_mobile_number_success() {
|
|
|
+// //arrange
|
|
|
+// when(userDao.findByMobile("13657094936")).thenReturn(expectUserPO);
|
|
|
+// when(userToRoleDao.findByUserId(anyLong())).thenReturn(expectUserToRolePOList);
|
|
|
+// when(roleDao.findById(anyLong())).thenReturn(Optional.of(expectRolePO));
|
|
|
+// when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
+// when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
+// //action
|
|
|
+// User user = userRepo.getByMobileNum(expectUserPO.getMobile());
|
|
|
+// //assert
|
|
|
+// Assert.assertEquals(user.getId(),expectUserPO.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = UserNotExistException.class)
|
|
|
+// public void should_throw_exception_when_get_by_mobile_number_get_null() {
|
|
|
+// //arrange
|
|
|
+// when(userDao.findByMobile(anyString())).thenReturn(null);
|
|
|
+// //action
|
|
|
+// userRepo.getByMobileNum("123");
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_when_save_user_and_role() {
|
|
|
+// //arrange
|
|
|
+// Role expectRole = new Role();
|
|
|
+// List<Role> roleList = new LinkedList<>();
|
|
|
+// roleList.add(expectRole);
|
|
|
+// User user = new User();
|
|
|
+// user.setRoleList(roleList);
|
|
|
+// when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
+// when(roleDao.findByName(anyString())).thenReturn(expectRolePO);
|
|
|
+// when(userToRoleDao.save(any(UserToRolePO.class))).thenReturn(expectUserToRolePO);
|
|
|
+// when(roleToPermissionDao.findAllByRoleId(anyLong())).thenReturn(expectRoleToPermissionPOList);
|
|
|
+// when(permissionDao.findById(anyLong())).thenReturn(Optional.of(expectPermission));
|
|
|
+// //action
|
|
|
+// User resultUser = userRepo.saveUserAndRole(user);
|
|
|
+// //assert
|
|
|
+// Assert.assertEquals(resultUser.getId(), expectUserPO.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = PermissionNotFoundException.class)
|
|
|
+// public void should_return_expert_when_save_user_and_role_permission_not_found() {
|
|
|
+// //arrange
|
|
|
+// Role expectRole = new Role();
|
|
|
+// List<Role> roleList = new LinkedList<>();
|
|
|
+// roleList.add(expectRole);
|
|
|
+// User user = new User();
|
|
|
+// user.setRoleList(roleList);
|
|
|
+// when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
+// when(roleDao.findByName(anyString())).thenReturn(expectRolePO);
|
|
|
+// when(userToRoleDao.save(any(UserToRolePO.class))).thenReturn(expectUserToRolePO);
|
|
|
+// when(roleToPermissionDao.findAllByRoleId(1L)).thenReturn(expectRoleToPermissionPOList);
|
|
|
+// when(permissionDao.findById(anyLong())).thenReturn(Optional.empty());
|
|
|
+// //action
|
|
|
+// userRepo.saveUserAndRole(user);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_when_save_user() {
|
|
|
+// //arrange
|
|
|
+// List<Permission> permissionList = new LinkedList<>();
|
|
|
+// Permission permission = new Permission();
|
|
|
+// permissionList.add(permission);
|
|
|
+// List<Role> roleList = new LinkedList<>();
|
|
|
+// Role role = new Role();
|
|
|
+// role.setId(1L);
|
|
|
+// role.setPermissionList(permissionList);
|
|
|
+// roleList.add(role);
|
|
|
+// EvaluationAgency evaluationAgency = new EvaluationAgency();
|
|
|
+// evaluationAgency.setId(1L);
|
|
|
+// EvaluationAgencyAbility evaluationAgencyAbility = new EvaluationAgencyAbility();
|
|
|
+// EvaluationAgencyResource evaluationAgencyResource = new EvaluationAgencyResource();
|
|
|
+// List<EvaluationAgencyResource> evaluationAgencyResourceList = new ArrayList<>();
|
|
|
+// List<EvaluationAgencyAbility> evaluationAgencyAbilityList = new ArrayList<>();
|
|
|
+// evaluationAgencyAbility.setId(1L);
|
|
|
+// evaluationAgencyAbility.setEvaluationAgencyId(1L);
|
|
|
+// evaluationAgencyAbilityList.add(evaluationAgencyAbility);
|
|
|
+//
|
|
|
+// evaluationAgencyResource.setId(1L);
|
|
|
+// evaluationAgencyResource.setEvaluationAgencyId(1L);
|
|
|
+// evaluationAgencyResourceList.add(evaluationAgencyResource);
|
|
|
+//
|
|
|
+// evaluationAgency.setEvaluationAgencyAbilityList(evaluationAgencyAbilityList);
|
|
|
+// evaluationAgency.setEvaluationAgencyResourceList(evaluationAgencyResourceList);
|
|
|
+//
|
|
|
+// User user = new User();
|
|
|
+// user.setEvaluationAgency(evaluationAgency);
|
|
|
+// user.setRoleList(roleList);
|
|
|
+//
|
|
|
+// expectUserPO.setId(0L);
|
|
|
+//
|
|
|
+// when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
+// when(userDao.findById(any(Long.class))).thenReturn(Optional.of(expectUserPO));
|
|
|
+// when(evaluationAgencyDao.save(any(EvaluationAgencyPO.class))).thenReturn(expectEvaluationAgencyPO);
|
|
|
+// when(resourceRepo.saveEvaluationAgencyResource(any())).thenReturn(null);
|
|
|
+// //action
|
|
|
+// User resultUser = userRepo.saveUser(user);
|
|
|
+// //assert
|
|
|
+// Assert.assertEquals(resultUser.getId(),expectUserPO.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_when_save_user_role_is_null() {
|
|
|
+// //arrange
|
|
|
+// List<Permission> permissionList = new LinkedList<>();
|
|
|
+// Permission permission = new Permission();
|
|
|
+// permissionList.add(permission);
|
|
|
+// List<Role> roleList = new LinkedList<>();
|
|
|
+// Role role = new Role();
|
|
|
+// role.setId(1L);
|
|
|
+// role.setPermissionList(permissionList);
|
|
|
+// roleList.add(role);
|
|
|
+// EvaluationAgency evaluationAgency = new EvaluationAgency();
|
|
|
+// evaluationAgency.setId(1L);
|
|
|
+// EvaluationAgencyAbility evaluationAgencyAbility = new EvaluationAgencyAbility();
|
|
|
+// EvaluationAgencyResource evaluationAgencyResource = new EvaluationAgencyResource();
|
|
|
+// List<EvaluationAgencyResource> evaluationAgencyResourceList = new ArrayList<>();
|
|
|
+// List<EvaluationAgencyAbility> evaluationAgencyAbilityList = new ArrayList<>();
|
|
|
+// evaluationAgencyAbility.setId(1L);
|
|
|
+// evaluationAgencyAbility.setEvaluationAgencyId(1L);
|
|
|
+// evaluationAgencyAbilityList.add(evaluationAgencyAbility);
|
|
|
+//
|
|
|
+// evaluationAgencyResource.setId(1L);
|
|
|
+// evaluationAgencyResource.setEvaluationAgencyId(1L);
|
|
|
+// evaluationAgencyResourceList.add(evaluationAgencyResource);
|
|
|
+//
|
|
|
+// evaluationAgency.setEvaluationAgencyAbilityList(evaluationAgencyAbilityList);
|
|
|
+// evaluationAgency.setEvaluationAgencyResourceList(evaluationAgencyResourceList);
|
|
|
+//
|
|
|
+// User user = new User();
|
|
|
+// user.setEvaluationAgency(evaluationAgency);
|
|
|
+// user.setRoleList(null);
|
|
|
+//
|
|
|
+// expectUserPO.setId(0L);
|
|
|
+//
|
|
|
+// when(userDao.save(any(UserPO.class))).thenReturn(expectUserPO);
|
|
|
+// when(userDao.findById(any(Long.class))).thenReturn(Optional.of(expectUserPO));
|
|
|
+// when(evaluationAgencyDao.save(any(EvaluationAgencyPO.class))).thenReturn(expectEvaluationAgencyPO);
|
|
|
+// when(resourceRepo.saveEvaluationAgencyResource(any())).thenReturn(null);
|
|
|
+// //action
|
|
|
+// User resultUser = userRepo.saveUser(user);
|
|
|
+// //assert
|
|
|
+// Assert.assertEquals(resultUser.getId(),expectUserPO.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_list_when_get_by_id_list() {
|
|
|
+// //arrange
|
|
|
+// List<UserPO> expectUserPOList = new LinkedList<>();
|
|
|
+// expectUserPOList.add(new UserPO());
|
|
|
+// expectUserPOList.add(new UserPO());
|
|
|
+// when(userDao.findAllById(anyListOf(Long.class))).thenReturn(expectUserPOList);
|
|
|
+// //action
|
|
|
+// List<User> userList = userRepo.getByIdList(new LinkedList<>());
|
|
|
+// //assert
|
|
|
+// Assert.assertNotNull(userList);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_list_when_get_all_user() {
|
|
|
+// //arrange
|
|
|
+// List<UserPO> expectUserPOList = new LinkedList<>();
|
|
|
+// expectUserPOList.add(new UserPO());
|
|
|
+// expectUserPOList.add(new UserPO());
|
|
|
+// when(userDao.findAll()).thenReturn(expectUserPOList);
|
|
|
+// //action
|
|
|
+// List<User> userList = userRepo.getAllUser();
|
|
|
+// //assert
|
|
|
+// Assert.assertNotNull(userList);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_void_when_remove_user() {
|
|
|
+// //arrange
|
|
|
+// User user = new User();
|
|
|
+// //action
|
|
|
+// userRepo.removeUser(user);
|
|
|
+// //assert
|
|
|
+// Assert.assertNull(null);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_void_when_remove_user_list() {
|
|
|
+// //arrange
|
|
|
+// List<User> userList = new LinkedList<>();
|
|
|
+// userList.add(new User());
|
|
|
+// //action
|
|
|
+// userRepo.removeUserList(userList);
|
|
|
+// //assert
|
|
|
+// Assert.assertNull(null);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_user_list_when_get_apply_agency() {
|
|
|
+// //arrange
|
|
|
+// when(evaluationAgencyDao.findByIsAuthentication(-1)).thenReturn(evaluationAgencyPOList);
|
|
|
+// when(userDao.findById(any(Long.class))).thenReturn(Optional.of(expectUserPO));
|
|
|
+// //action
|
|
|
+// List<User> applyAgencyList = userRepo.getApplyEvaluationAgencyByIsAuthenticated();
|
|
|
+// //assert
|
|
|
+// Assert.assertNotNull(applyAgencyList);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_role_when_get_role(){
|
|
|
+// //arrange
|
|
|
+// when(roleDao.findByName(anyString())).thenReturn(expectRolePO);
|
|
|
+// //action
|
|
|
+// Role role = userRepo.getRole(expectRolePO.getName());
|
|
|
+// Assert.assertEquals(role.getName(),expectRolePO.getName());
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|