|
|
@ -70,7 +70,7 @@ import com.google.common.collect.Lists; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* users service test |
|
|
|
* users service test |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
@RunWith(MockitoJUnitRunner.Silent.class) |
|
|
|
public class UsersServiceTest { |
|
|
|
public class UsersServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UsersServiceTest.class); |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UsersServiceTest.class); |
|
|
@ -340,24 +340,43 @@ public class UsersServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGrantProjectByCode() { |
|
|
|
public void testGrantProjectByCode() { |
|
|
|
when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
// Mock Project, User
|
|
|
|
|
|
|
|
final long projectCode = 1L; |
|
|
|
// user no permission
|
|
|
|
final int projectCreator = 1; |
|
|
|
|
|
|
|
final int authorizer = 100; |
|
|
|
|
|
|
|
Mockito.when(this.userMapper.selectById(authorizer)).thenReturn(this.getUser()); |
|
|
|
|
|
|
|
Mockito.when(this.userMapper.selectById(projectCreator)).thenReturn(this.getUser()); |
|
|
|
|
|
|
|
Mockito.when(this.projectMapper.queryByCode(projectCode)).thenReturn(this.getProject()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ERROR: USER_NOT_EXIST
|
|
|
|
User loginUser = new User(); |
|
|
|
User loginUser = new User(); |
|
|
|
String projectCodes = "3682329499136,3643998558592"; |
|
|
|
Map<String, Object> result = this.usersService.grantProjectByCode(loginUser, 999, projectCode); |
|
|
|
Map<String, Object> result = this.usersService.grantProjectByCode(loginUser, 1, projectCodes); |
|
|
|
logger.info(result.toString()); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ERROR: PROJECT_NOT_FOUNT
|
|
|
|
|
|
|
|
result = this.usersService.grantProjectByCode(loginUser, authorizer, 999); |
|
|
|
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ERROR: USER_NO_OPERATION_PERM
|
|
|
|
|
|
|
|
loginUser.setId(999); |
|
|
|
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
result = this.usersService.grantProjectByCode(loginUser, authorizer, projectCode); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// user not exist
|
|
|
|
// SUCCESS: USER IS PROJECT OWNER
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setId(projectCreator); |
|
|
|
result = this.usersService.grantProjectByCode(loginUser, 2, projectCodes); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
result = this.usersService.grantProjectByCode(loginUser, authorizer, projectCode); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
// SUCCESS: USER IS ADMINISTRATOR
|
|
|
|
Mockito.when(this.projectMapper.queryByCodes(Mockito.anyCollection())).thenReturn(Lists.newArrayList(new Project())); |
|
|
|
loginUser.setId(999); |
|
|
|
result = this.usersService.grantProjectByCode(loginUser, 1, projectCodes); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
|
|
|
result = this.usersService.grantProjectByCode(loginUser, authorizer, projectCode); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
@ -667,6 +686,22 @@ public class UsersServiceTest { |
|
|
|
return user; |
|
|
|
return user; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get project |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Project getProject() { |
|
|
|
|
|
|
|
Project project = new Project(); |
|
|
|
|
|
|
|
project.setId(1); |
|
|
|
|
|
|
|
project.setCode(1L); |
|
|
|
|
|
|
|
project.setUserId(1); |
|
|
|
|
|
|
|
project.setName("PJ-001"); |
|
|
|
|
|
|
|
project.setPerm(7); |
|
|
|
|
|
|
|
project.setDefCount(0); |
|
|
|
|
|
|
|
project.setInstRunningCount(0); |
|
|
|
|
|
|
|
return project; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get user |
|
|
|
* get user |
|
|
|
*/ |
|
|
|
*/ |
|
|
|