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