|
|
@ -15,12 +15,19 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT; |
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_CREATE; |
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_DELETE; |
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_UPDATE; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
@ -35,7 +42,14 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
@ -46,8 +60,6 @@ import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* project service test |
|
|
|
* project service test |
|
|
|
**/ |
|
|
|
**/ |
|
|
@ -84,23 +96,23 @@ public class ProjectServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
User loginUser = getLoginUser(); |
|
|
|
User loginUser = getLoginUser(); |
|
|
|
loginUser.setId(1); |
|
|
|
loginUser.setId(1); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, 1, PROJECT_CREATE , baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, 1, PROJECT_CREATE, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, null, 1, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, null, 1, baseServiceLogger)).thenReturn(true); |
|
|
|
Map<String, Object> result = projectService.createProject(loginUser, projectName, getDesc()); |
|
|
|
Result result = projectService.createProject(loginUser, projectName, getDesc()); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), 10001); |
|
|
|
|
|
|
|
|
|
|
|
//project name exist
|
|
|
|
//project name exist
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject()); |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject()); |
|
|
|
result = projectService.createProject(loginUser, projectName, projectName); |
|
|
|
result = projectService.createProject(loginUser, projectName, projectName); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.PROJECT_ALREADY_EXISTS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.PROJECT_ALREADY_EXISTS.getCode(), result.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
|
|
//success
|
|
|
|
//success
|
|
|
|
Mockito.when(projectMapper.insert(Mockito.any(Project.class))).thenReturn(1); |
|
|
|
Mockito.when(projectMapper.insert(Mockito.any(Project.class))).thenReturn(1); |
|
|
|
result = projectService.createProject(loginUser, "test", "test"); |
|
|
|
result = projectService.createProject(loginUser, "test", "test"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -118,7 +130,7 @@ public class ProjectServiceTest { |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
//USER_NO_OPERATION_PROJECT_PERM
|
|
|
|
//USER_NO_OPERATION_PROJECT_PERM
|
|
|
|
project.setUserId(2); |
|
|
|
project.setUserId(2); |
|
|
|
result = projectService.checkProjectAndAuth(loginUser, project, projectCode,PROJECT); |
|
|
|
result = projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
@ -126,14 +138,14 @@ public class ProjectServiceTest { |
|
|
|
project.setUserId(1); |
|
|
|
project.setUserId(1); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, project.getUserId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, project.getUserId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{project.getId()}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {project.getId()}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
result = projectService.checkProjectAndAuth(loginUser, project, projectCode,PROJECT); |
|
|
|
result = projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result2 = new HashMap<>(); |
|
|
|
Map<String, Object> result2 = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
result2 = projectService.checkProjectAndAuth(loginUser, null, projectCode,PROJECT); |
|
|
|
result2 = projectService.checkProjectAndAuth(loginUser, null, projectCode, PROJECT); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_EXIST, result2.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_EXIST, result2.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
Project project1 = getProject(); |
|
|
|
Project project1 = getProject(); |
|
|
@ -141,12 +153,12 @@ public class ProjectServiceTest { |
|
|
|
project1.setUserId(2); |
|
|
|
project1.setUserId(2); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
result2 = projectService.checkProjectAndAuth(loginUser, project1, projectCode,PROJECT); |
|
|
|
result2 = projectService.checkProjectAndAuth(loginUser, project1, projectCode, PROJECT); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result2.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result2.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//success
|
|
|
|
//success
|
|
|
|
project1.setUserId(1); |
|
|
|
project1.setUserId(1); |
|
|
|
projectService.checkProjectAndAuth(loginUser, project1, projectCode,PROJECT); |
|
|
|
projectService.checkProjectAndAuth(loginUser, project1, projectCode, PROJECT); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -162,7 +174,7 @@ public class ProjectServiceTest { |
|
|
|
tempUser.setId(Integer.MAX_VALUE); |
|
|
|
tempUser.setId(Integer.MAX_VALUE); |
|
|
|
tempUser.setUserType(UserType.GENERAL_USER); |
|
|
|
tempUser.setUserType(UserType.GENERAL_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, tempUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, tempUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
boolean checkResult = projectService.hasProjectAndPerm(tempUser, project, result,null); |
|
|
|
boolean checkResult = projectService.hasProjectAndPerm(tempUser, project, result, null); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertFalse(checkResult); |
|
|
|
Assert.assertFalse(checkResult); |
|
|
|
|
|
|
|
|
|
|
@ -171,8 +183,8 @@ public class ProjectServiceTest { |
|
|
|
project.setUserId(1); |
|
|
|
project.setUserId(1); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{project.getId()}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {project.getId()}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
checkResult = projectService.hasProjectAndPerm(loginUser, project, result,null); |
|
|
|
checkResult = projectService.hasProjectAndPerm(loginUser, project, result, null); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertTrue(checkResult); |
|
|
|
Assert.assertTrue(checkResult); |
|
|
|
} |
|
|
|
} |
|
|
@ -183,31 +195,31 @@ public class ProjectServiceTest { |
|
|
|
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject()); |
|
|
|
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject()); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT_DELETE, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT_DELETE, baseServiceLogger)).thenReturn(true); |
|
|
|
//PROJECT_NOT_FOUNT
|
|
|
|
//PROJECT_NOT_FOUNT
|
|
|
|
Map<String, Object> result = projectService.deleteProject(loginUser, 11L); |
|
|
|
Result result = projectService.deleteProject(loginUser, 11L); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_EXIST, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.PROJECT_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
loginUser.setId(2); |
|
|
|
loginUser.setId(2); |
|
|
|
//USER_NO_OPERATION_PROJECT_PERM
|
|
|
|
//USER_NO_OPERATION_PROJECT_PERM
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},loginUser.getId() , baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {1}, loginUser.getId(), baseServiceLogger)).thenReturn(true); |
|
|
|
result = projectService.deleteProject(loginUser, 1L); |
|
|
|
result = projectService.deleteProject(loginUser, 1L); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.USER_NO_OPERATION_PROJECT_PERM.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
//DELETE_PROJECT_ERROR_DEFINES_NOT_NULL
|
|
|
|
//DELETE_PROJECT_ERROR_DEFINES_NOT_NULL
|
|
|
|
Mockito.when(processDefinitionMapper.queryAllDefinitionList(1L)).thenReturn(getProcessDefinitions()); |
|
|
|
Mockito.when(processDefinitionMapper.queryAllDefinitionList(1L)).thenReturn(getProcessDefinitions()); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setId(1); |
|
|
|
loginUser.setId(1); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},0 , baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {1}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
result = projectService.deleteProject(loginUser, 1L); |
|
|
|
result = projectService.deleteProject(loginUser, 1L); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.DELETE_PROJECT_ERROR_DEFINES_NOT_NULL, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.DELETE_PROJECT_ERROR_DEFINES_NOT_NULL.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
//success
|
|
|
|
//success
|
|
|
|
Mockito.when(projectMapper.deleteById(1)).thenReturn(1); |
|
|
|
Mockito.when(projectMapper.deleteById(1)).thenReturn(1); |
|
|
|
Mockito.when(processDefinitionMapper.queryAllDefinitionList(1L)).thenReturn(new ArrayList<>()); |
|
|
|
Mockito.when(processDefinitionMapper.queryAllDefinitionList(1L)).thenReturn(new ArrayList<>()); |
|
|
|
result = projectService.deleteProject(loginUser, 1L); |
|
|
|
result = projectService.deleteProject(loginUser, 1L); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.SUCCESS.getCode() == result.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -216,23 +228,23 @@ public class ProjectServiceTest { |
|
|
|
User loginUser = getLoginUser(); |
|
|
|
User loginUser = getLoginUser(); |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
project.setCode(2L); |
|
|
|
project.setCode(2L); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT_UPDATE , baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT_UPDATE, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},loginUser.getId() , baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {1}, loginUser.getId(), baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); |
|
|
|
Mockito.when(projectMapper.queryByCode(2L)).thenReturn(getProject()); |
|
|
|
Mockito.when(projectMapper.queryByCode(2L)).thenReturn(getProject()); |
|
|
|
// PROJECT_NOT_FOUNT
|
|
|
|
// PROJECT_NOT_FOUNT
|
|
|
|
Map<String, Object> result = projectService.update(loginUser, 1L, projectName, "desc", "testUser"); |
|
|
|
Result result = projectService.update(loginUser, 1L, projectName, "desc", "testUser"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.PROJECT_NOT_FOUND.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
//PROJECT_ALREADY_EXISTS
|
|
|
|
//PROJECT_ALREADY_EXISTS
|
|
|
|
result = projectService.update(loginUser, 2L, projectName, "desc", userName); |
|
|
|
result = projectService.update(loginUser, 2L, projectName, "desc", userName); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.PROJECT_ALREADY_EXISTS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.PROJECT_ALREADY_EXISTS.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(null); |
|
|
|
Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(null); |
|
|
|
result = projectService.update(loginUser, 2L, "test", "desc", "testuser"); |
|
|
|
result = projectService.update(loginUser, 2L, "test", "desc", "testuser"); |
|
|
|
Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
//success
|
|
|
|
//success
|
|
|
|
Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(new User()); |
|
|
|
Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(new User()); |
|
|
@ -240,7 +252,7 @@ public class ProjectServiceTest { |
|
|
|
Mockito.when(projectMapper.updateById(Mockito.any(Project.class))).thenReturn(1); |
|
|
|
Mockito.when(projectMapper.updateById(Mockito.any(Project.class))).thenReturn(1); |
|
|
|
result = projectService.update(loginUser, 2L, "test", "desc", "testUser"); |
|
|
|
result = projectService.update(loginUser, 2L, "test", "desc", "testUser"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.SUCCESS.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -252,16 +264,16 @@ public class ProjectServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
// test admin user
|
|
|
|
// test admin user
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
Map<String, Object> result = projectService.queryAuthorizedProject(loginUser, 2); |
|
|
|
Result result = projectService.queryAuthorizedProject(loginUser, 2); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
List<Project> projects = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
List<Project> projects = (List<Project>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
|
|
|
|
|
|
|
|
// test non-admin user
|
|
|
|
// test non-admin user
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setId(3); |
|
|
|
loginUser.setId(3); |
|
|
|
result = projectService.queryAuthorizedProject(loginUser, 2); |
|
|
|
result = projectService.queryAuthorizedProject(loginUser, 2); |
|
|
|
projects = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
projects = (List<Project>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -270,34 +282,34 @@ public class ProjectServiceTest { |
|
|
|
final User loginUser = this.getLoginUser(); |
|
|
|
final User loginUser = this.getLoginUser(); |
|
|
|
|
|
|
|
|
|
|
|
// Failure 1: PROJECT_NOT_FOUND
|
|
|
|
// Failure 1: PROJECT_NOT_FOUND
|
|
|
|
Map<String, Object> result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
Result result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
logger.info("FAILURE 1: {}", result.toString()); |
|
|
|
logger.info("FAILURE 1: {}", result.toString()); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.PROJECT_NOT_FOUND.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// Failure 2: USER_NO_OPERATION_PROJECT_PERM
|
|
|
|
// Failure 2: USER_NO_OPERATION_PROJECT_PERM
|
|
|
|
loginUser.setId(100); |
|
|
|
loginUser.setId(100); |
|
|
|
Mockito.when(this.projectMapper.queryByCode(Mockito.anyLong())).thenReturn(this.getProject()); |
|
|
|
Mockito.when(this.projectMapper.queryByCode(Mockito.anyLong())).thenReturn(this.getProject()); |
|
|
|
result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
logger.info("FAILURE 2: {}", result.toString()); |
|
|
|
logger.info("FAILURE 2: {}", result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); |
|
|
|
Assert.assertTrue(Status.USER_NO_OPERATION_PROJECT_PERM.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
// SUCCESS
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {1}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(this.userMapper.queryAuthedUserListByProjectId(1)).thenReturn(this.getUserList()); |
|
|
|
Mockito.when(this.userMapper.queryAuthedUserListByProjectId(1)).thenReturn(this.getUserList()); |
|
|
|
result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
logger.info("SUCCESS 1: {}", result.toString()); |
|
|
|
logger.info("SUCCESS 1: {}", result.toString()); |
|
|
|
List<User> users = (List<User>) result.get(Constants.DATA_LIST); |
|
|
|
List<User> users = (List<User>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(users)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(users)); |
|
|
|
|
|
|
|
|
|
|
|
loginUser.setId(1); |
|
|
|
loginUser.setId(1); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS, loginUser.getId(), PROJECT, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, 1, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[] {1}, 1, baseServiceLogger)).thenReturn(true); |
|
|
|
result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
result = this.projectService.queryAuthorizedUser(loginUser, 3682329499136L); |
|
|
|
logger.info("SUCCESS 2: {}", result.toString()); |
|
|
|
logger.info("SUCCESS 2: {}", result.toString()); |
|
|
|
users = (List<User>) result.get(Constants.DATA_LIST); |
|
|
|
users = (List<User>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(users)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(users)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -320,7 +332,7 @@ public class ProjectServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQueryProjectCreatedAndAuthorizedByUser() { |
|
|
|
public void testQueryProjectCreatedAndAuthorizedByUser() { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = null; |
|
|
|
Result result; |
|
|
|
User loginUser = getLoginUser(); |
|
|
|
User loginUser = getLoginUser(); |
|
|
|
Set<Integer> set = new HashSet(); |
|
|
|
Set<Integer> set = new HashSet(); |
|
|
|
set.add(1); |
|
|
|
set.add(1); |
|
|
@ -330,7 +342,7 @@ public class ProjectServiceTest { |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(projectMapper.selectBatchIds(set)).thenReturn(getList()); |
|
|
|
Mockito.when(projectMapper.selectBatchIds(set)).thenReturn(getList()); |
|
|
|
result = projectService.queryProjectCreatedAndAuthorizedByUser(loginUser); |
|
|
|
result = projectService.queryProjectCreatedAndAuthorizedByUser(loginUser); |
|
|
|
List<Project> notAdminUserResult = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
List<Project> notAdminUserResult = (List<Project>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(notAdminUserResult)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(notAdminUserResult)); |
|
|
|
|
|
|
|
|
|
|
|
//admin user
|
|
|
|
//admin user
|
|
|
@ -338,7 +350,7 @@ public class ProjectServiceTest { |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(projectMapper.selectBatchIds(set)).thenReturn(getList()); |
|
|
|
Mockito.when(projectMapper.selectBatchIds(set)).thenReturn(getList()); |
|
|
|
result = projectService.queryProjectCreatedAndAuthorizedByUser(loginUser); |
|
|
|
result = projectService.queryProjectCreatedAndAuthorizedByUser(loginUser); |
|
|
|
List<Project> projects = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
List<Project> projects = (List<Project>) result.getData(); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
|
|
|
|
|
|
|
@ -350,9 +362,9 @@ public class ProjectServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
user.setId(0); |
|
|
|
user.setId(0); |
|
|
|
Map<String, Object> result = projectService.queryAllProjectList(user); |
|
|
|
Result result = projectService.queryAllProjectList(user); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
List<Project> projects = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
List<Project> projects = (List<Project>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -368,20 +380,20 @@ public class ProjectServiceTest { |
|
|
|
List<Integer> list = new ArrayList<>(1); |
|
|
|
List<Integer> list = new ArrayList<>(1); |
|
|
|
list.add(1); |
|
|
|
list.add(1); |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(projectMapper.listAuthorizedProjects(loginUser.getUserType().equals(UserType.ADMIN_USER) ? 0 : loginUser.getId(),list)).thenReturn(getList()); |
|
|
|
Mockito.when(projectMapper.listAuthorizedProjects(loginUser.getUserType().equals(UserType.ADMIN_USER) ? 0 : loginUser.getId(), list)).thenReturn(getList()); |
|
|
|
Map<String, Object> result = projectService.queryUnauthorizedProject(loginUser, 2); |
|
|
|
Result result = projectService.queryUnauthorizedProject(loginUser, 2); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
List<Project> projects = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
List<Project> projects = (List<Project>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
|
|
|
|
|
|
|
|
// test non-admin user
|
|
|
|
// test non-admin user
|
|
|
|
loginUser.setId(2); |
|
|
|
loginUser.setId(2); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), projectLogger)).thenReturn(set); |
|
|
|
Mockito.when(projectMapper.listAuthorizedProjects(loginUser.getUserType().equals(UserType.ADMIN_USER) ? 0 : loginUser.getId(),list)).thenReturn(getList()); |
|
|
|
Mockito.when(projectMapper.listAuthorizedProjects(loginUser.getUserType().equals(UserType.ADMIN_USER) ? 0 : loginUser.getId(), list)).thenReturn(getList()); |
|
|
|
result = projectService.queryUnauthorizedProject(loginUser, 3); |
|
|
|
result = projectService.queryUnauthorizedProject(loginUser, 3); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
projects = (List<Project>) result.get(Constants.DATA_LIST); |
|
|
|
projects = (List<Project>) result.getData(); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -428,6 +440,7 @@ public class ProjectServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get general user |
|
|
|
* Get general user |
|
|
|
|
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private User getGeneralUser() { |
|
|
|
private User getGeneralUser() { |
|
|
@ -440,6 +453,7 @@ public class ProjectServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get user list |
|
|
|
* Get user list |
|
|
|
|
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<User> getUserList() { |
|
|
|
private List<User> getUserList() { |
|
|
@ -472,9 +486,9 @@ public class ProjectServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
private String getDesc() { |
|
|
|
private String getDesc() { |
|
|
|
return "projectUserMapper.deleteProjectRelation(projectId,userId)projectUserMappe" |
|
|
|
return "projectUserMapper.deleteProjectRelation(projectId,userId)projectUserMappe" |
|
|
|
+ ".deleteProjectRelation(projectId,userId)projectUserMappe" |
|
|
|
+ ".deleteProjectRelation(projectId,userId)projectUserMappe" |
|
|
|
+ "r.deleteProjectRelation(projectId,userId)projectUserMapper" |
|
|
|
+ "r.deleteProjectRelation(projectId,userId)projectUserMapper" |
|
|
|
+ ".deleteProjectRelation(projectId,userId)projectUserMapper.deleteProjectRelation(projectId,userId)"; |
|
|
|
+ ".deleteProjectRelation(projectId,userId)projectUserMapper.deleteProjectRelation(projectId,userId)"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |