Browse Source

[Feature][JsonSplit-api] replace projectName with projectCode for taskDefinition (#5815)

* fix processDefinitonController projectCode

* queryAllByProjectCode of processDefinition

* query taskNodeList of processDefinition

* replace projectName with projectCode for taskDefinition

Co-authored-by: JinyLeeChina <297062848@qq.com>
2.0.7-release
JinyLeeChina 3 years ago committed by GitHub
parent
commit
47de7cae7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
  2. 36
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java
  3. 90
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
  4. 81
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

56
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java

@ -37,8 +37,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
@ -62,11 +60,9 @@ import springfox.documentation.annotations.ApiIgnore;
*/
@Api(tags = "TASK_DEFINITION_TAG")
@RestController
@RequestMapping("projects/{projectName}/task")
@RequestMapping("projects/{projectCode}/task")
public class TaskDefinitionController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(TaskDefinitionController.class);
@Autowired
private TaskDefinitionService taskDefinitionService;
@ -74,7 +70,7 @@ public class TaskDefinitionController extends BaseController {
* create task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionJson task definition json
* @return create result code
*/
@ -88,10 +84,9 @@ public class TaskDefinitionController extends BaseController {
@ApiException(CREATE_TASK_DEFINITION)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result createTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) {
Map<String, Object> result = taskDefinitionService.createTaskDefinition(loginUser, projectName, taskDefinitionJson);
Map<String, Object> result = taskDefinitionService.createTaskDefinition(loginUser, projectCode, taskDefinitionJson);
return returnDataList(result);
}
@ -99,7 +94,7 @@ public class TaskDefinitionController extends BaseController {
* update task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionCode task definition code
* @param taskDefinitionJson task definition json
* @return update result code
@ -115,10 +110,10 @@ public class TaskDefinitionController extends BaseController {
@ApiException(UPDATE_TASK_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result updateTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) {
Map<String, Object> result = taskDefinitionService.updateTaskDefinition(loginUser, projectName, taskDefinitionCode, taskDefinitionJson);
Map<String, Object> result = taskDefinitionService.updateTaskDefinition(loginUser, projectCode, taskDefinitionCode, taskDefinitionJson);
return returnDataList(result);
}
@ -126,7 +121,7 @@ public class TaskDefinitionController extends BaseController {
* query task definition version paging list info
*
* @param loginUser login user info
* @param projectName project name
* @param projectCode project code
* @param pageNo the task definition version list current page number
* @param pageSize the task definition version list page size
* @param taskDefinitionCode the task definition code
@ -143,12 +138,11 @@ public class TaskDefinitionController extends BaseController {
@ApiException(QUERY_TASK_DEFINITION_VERSIONS_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "pageNo") int pageNo,
@RequestParam(value = "pageSize") int pageSize,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) {
Map<String, Object> result = taskDefinitionService.queryTaskDefinitionVersions(loginUser,
projectName, pageNo, pageSize, taskDefinitionCode);
Map<String, Object> result = taskDefinitionService.queryTaskDefinitionVersions(loginUser, projectCode, pageNo, pageSize, taskDefinitionCode);
return returnDataList(result);
}
@ -156,7 +150,7 @@ public class TaskDefinitionController extends BaseController {
* switch task definition version
*
* @param loginUser login user info
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionCode the task definition code
* @param version the version user want to switch
* @return switch version result code
@ -171,10 +165,10 @@ public class TaskDefinitionController extends BaseController {
@ApiException(SWITCH_TASK_DEFINITION_VERSION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result switchTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode,
@RequestParam(value = "version") int version) {
Map<String, Object> result = taskDefinitionService.switchVersion(loginUser, projectName, taskDefinitionCode, version);
Map<String, Object> result = taskDefinitionService.switchVersion(loginUser, projectCode, taskDefinitionCode, version);
return returnDataList(result);
}
@ -182,7 +176,7 @@ public class TaskDefinitionController extends BaseController {
* delete the certain task definition version by version and code
*
* @param loginUser login user info
* @param projectName the task definition project name
* @param projectCode project code
* @param taskDefinitionCode the task definition code
* @param version the task definition version user want to delete
* @return delete version result code
@ -197,10 +191,10 @@ public class TaskDefinitionController extends BaseController {
@ApiException(DELETE_TASK_DEFINITION_VERSION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode,
@RequestParam(value = "version") int version) {
Map<String, Object> result = taskDefinitionService.deleteByCodeAndVersion(loginUser, projectName, taskDefinitionCode, version);
Map<String, Object> result = taskDefinitionService.deleteByCodeAndVersion(loginUser, projectCode, taskDefinitionCode, version);
return returnDataList(result);
}
@ -208,7 +202,7 @@ public class TaskDefinitionController extends BaseController {
* delete task definition by code
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionCode the task definition code
* @return delete result code
*/
@ -221,9 +215,9 @@ public class TaskDefinitionController extends BaseController {
@ApiException(DELETE_TASK_DEFINE_BY_CODE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteTaskDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) {
Map<String, Object> result = taskDefinitionService.deleteTaskDefinitionByCode(loginUser, projectName, taskDefinitionCode);
Map<String, Object> result = taskDefinitionService.deleteTaskDefinitionByCode(loginUser, projectCode, taskDefinitionCode);
return returnDataList(result);
}
@ -231,7 +225,7 @@ public class TaskDefinitionController extends BaseController {
* query detail of task definition by code
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionCode the task definition code
* @return task definition detail
*/
@ -244,9 +238,9 @@ public class TaskDefinitionController extends BaseController {
@ApiException(QUERY_DETAIL_OF_TASK_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionDetail(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) {
Map<String, Object> result = taskDefinitionService.queryTaskDefinitionDetail(loginUser, projectName, taskDefinitionCode);
Map<String, Object> result = taskDefinitionService.queryTaskDefinitionDetail(loginUser, projectCode, taskDefinitionCode);
return returnDataList(result);
}
@ -254,7 +248,7 @@ public class TaskDefinitionController extends BaseController {
* query task definition list paging
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
@ -273,7 +267,7 @@ public class TaskDefinitionController extends BaseController {
@ApiException(QUERY_TASK_DEFINITION_LIST_PAGING_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
@ -283,7 +277,7 @@ public class TaskDefinitionController extends BaseController {
return returnDataListPaging(result);
}
searchVal = ParameterUtils.handleEscapes(searchVal);
result = taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId);
result = taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, searchVal, pageNo, pageSize, userId);
return returnDataListPaging(result);
}
}

36
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java

@ -30,45 +30,45 @@ public interface TaskDefinitionService {
* create task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionJson task definition json
*/
Map<String, Object> createTaskDefinition(User loginUser,
String projectName,
long projectCode,
String taskDefinitionJson);
/**
* query task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskName task name
*/
Map<String, Object> queryTaskDefinitionByName(User loginUser,
String projectName,
long projectCode,
String taskName);
/**
* delete task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode task code
*/
Map<String, Object> deleteTaskDefinitionByCode(User loginUser,
String projectName,
long projectCode,
long taskCode);
/**
* update task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode task code
* @param taskDefinitionJson task definition json
*/
Map<String, Object> updateTaskDefinition(User loginUser,
String projectName,
long projectCode,
long taskCode,
String taskDefinitionJson);
@ -76,12 +76,12 @@ public interface TaskDefinitionService {
* update task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode task code
* @param version the version user want to switch
*/
Map<String, Object> switchVersion(User loginUser,
String projectName,
long projectCode,
long taskCode,
int version);
@ -89,14 +89,14 @@ public interface TaskDefinitionService {
* query the pagination versions info by one certain task definition code
*
* @param loginUser login user info to check auth
* @param projectName project name
* @param projectCode project code
* @param pageNo page number
* @param pageSize page size
* @param taskCode task definition code
* @return the pagination task definition versions info of the certain task definition
*/
Map<String, Object> queryTaskDefinitionVersions(User loginUser,
String projectName,
long projectCode,
int pageNo,
int pageSize,
long taskCode);
@ -105,13 +105,13 @@ public interface TaskDefinitionService {
* delete the certain task definition version by version and code
*
* @param loginUser login user info
* @param projectName the task definition project name
* @param projectCode project code
* @param taskCode the task definition code
* @param version the task definition version user want to delete
* @return delete version result code
*/
Map<String, Object> deleteByCodeAndVersion(User loginUser,
String projectName,
long projectCode,
long taskCode,
int version);
@ -119,19 +119,19 @@ public interface TaskDefinitionService {
* query detail of task definition by code
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode the task definition code
* @return task definition detail
*/
Map<String, Object> queryTaskDefinitionDetail(User loginUser,
String projectName,
long projectCode,
long taskCode);
/**
* query task definition list paging
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
@ -139,7 +139,7 @@ public interface TaskDefinitionService {
* @return task definition page
*/
Map<String, Object> queryTaskDefinitionListPaging(User loginUser,
String projectName,
long projectCode,
String searchVal,
Integer pageNo,
Integer pageSize,

90
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java

@ -41,7 +41,6 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.service.process.ProcessService;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -83,22 +82,19 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* create task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskDefinitionJson task definition json
*/
@Transactional(rollbackFor = RuntimeException.class)
@Override
public Map<String, Object> createTaskDefinition(User loginUser,
String projectName,
long projectCode,
String taskDefinitionJson) {
Map<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByName(projectName);
// check project auth
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -130,18 +126,16 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* query task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskName task name
*/
@Override
public Map<String, Object> queryTaskDefinitionByName(User loginUser, String projectName, String taskName) {
Map<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByName(projectName);
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
public Map<String, Object> queryTaskDefinitionByName(User loginUser, long projectCode, String taskName) {
Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionName(project.getCode(), taskName);
@ -158,19 +152,17 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* delete task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode task code
*/
@Transactional(rollbackFor = RuntimeException.class)
@Override
public Map<String, Object> deleteTaskDefinitionByCode(User loginUser, String projectName, long taskCode) {
Map<String, Object> result = new HashMap<>(5);
Project project = projectMapper.queryByName(projectName);
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultEnum = (Status) checkResult.get(Constants.STATUS);
if (resultEnum != Status.SUCCESS) {
return checkResult;
public Map<String, Object> deleteTaskDefinitionByCode(User loginUser, long projectCode, long taskCode) {
Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByTaskCode(taskCode);
if (!processTaskRelationList.isEmpty()) {
@ -194,20 +186,18 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* update task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode task code
* @param taskDefinitionJson task definition json
*/
@Transactional(rollbackFor = RuntimeException.class)
@Override
public Map<String, Object> updateTaskDefinition(User loginUser, String projectName, long taskCode, String taskDefinitionJson) {
Map<String, Object> result = new HashMap<>(5);
Project project = projectMapper.queryByName(projectName);
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultEnum = (Status) checkResult.get(Constants.STATUS);
if (resultEnum != Status.SUCCESS) {
return checkResult;
public Map<String, Object> updateTaskDefinition(User loginUser, long projectCode, long taskCode, String taskDefinitionJson) {
Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
if (processService.isTaskOnline(taskCode)) {
putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE);
@ -246,19 +236,17 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* update task definition
*
* @param loginUser login user
* @param projectName project name
* @param projectCode project code
* @param taskCode task code
* @param version the version user want to switch
*/
@Override
public Map<String, Object> switchVersion(User loginUser, String projectName, long taskCode, int version) {
Map<String, Object> result = new HashMap<>(5);
Project project = projectMapper.queryByName(projectName);
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultEnum = (Status) checkResult.get(Constants.STATUS);
if (resultEnum != Status.SUCCESS) {
return checkResult;
public Map<String, Object> switchVersion(User loginUser, long projectCode, long taskCode, int version) {
Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
if (processService.isTaskOnline(taskCode)) {
putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE);
@ -279,23 +267,23 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
}
@Override
public Map<String, Object> queryTaskDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, long taskCode) {
public Map<String, Object> queryTaskDefinitionVersions(User loginUser, long projectCode, int pageNo, int pageSize, long taskCode) {
return null;
}
@Override
public Map<String, Object> deleteByCodeAndVersion(User loginUser, String projectName, long taskCode, int version) {
public Map<String, Object> deleteByCodeAndVersion(User loginUser, long projectCode, long taskCode, int version) {
return null;
}
@Override
public Map<String, Object> queryTaskDefinitionDetail(User loginUser, String projectName, long taskCode) {
public Map<String, Object> queryTaskDefinitionDetail(User loginUser, long projectCode, long taskCode) {
return null;
}
@Override
public Map<String, Object> queryTaskDefinitionListPaging(User loginUser,
String projectName,
long projectCode,
String searchVal,
Integer pageNo,
Integer pageSize,

81
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

@ -119,20 +119,18 @@ public class TaskDefinitionServiceImplTest {
@Test
public void createTaskDefinition() {
String projectName = "project_test1";
long projectCode = 1L;
Project project = getProject(projectName);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User();
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -143,7 +141,7 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(1);
Map<String, Object> relation = taskDefinitionService
.createTaskDefinition(loginUser, projectName, taskDefinitionJson);
.createTaskDefinition(loginUser, projectCode, taskDefinitionJson);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
@ -151,20 +149,19 @@ public class TaskDefinitionServiceImplTest {
@Test
public void queryTaskDefinitionByName() {
String projectName = "project_test1";
String taskName = "task";
Project project = getProject(projectName);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
long projectCode = 1L;
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User();
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -172,27 +169,25 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(new TaskDefinition());
Map<String, Object> relation = taskDefinitionService
.queryTaskDefinitionByName(loginUser, projectName, taskName);
.queryTaskDefinitionByName(loginUser, projectCode, taskName);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
}
@Test
public void deleteTaskDefinitionByCode() {
String projectName = "project_test1";
long projectCode = 1L;
Project project = getProject(projectName);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User();
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -200,7 +195,7 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(1);
Map<String, Object> relation = taskDefinitionService
.deleteTaskDefinitionByCode(loginUser, projectName, 11L);
.deleteTaskDefinitionByCode(loginUser, projectCode, 11L);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
@ -208,20 +203,18 @@ public class TaskDefinitionServiceImplTest {
@Test
public void updateTaskDefinition() {
String projectName = "project_test1";
long projectCode = 1L;
Project project = getProject(projectName);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User();
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -235,28 +228,27 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(new TaskDefinition());
Map<String, Object> relation = taskDefinitionService
.updateTaskDefinition(loginUser, projectName, 11L, taskDefinitionJson);
.updateTaskDefinition(loginUser, projectCode, 11L, taskDefinitionJson);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
}
@Test
public void switchVersion() {
String projectName = "project_test1";
int version = 1;
Long taskCode = 11L;
Project project = getProject(projectName);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
long taskCode = 11L;
long projectCode = 1L;
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User();
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -267,7 +259,7 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(new TaskDefinition());
Map<String, Object> relation = taskDefinitionService
.switchVersion(loginUser, projectName, taskCode, version);
.switchVersion(loginUser, projectCode, taskCode, version);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
}
@ -284,13 +276,14 @@ public class TaskDefinitionServiceImplTest {
/**
* get mock Project
*
* @param projectName projectName
* @param projectCode projectCode
* @return Project
*/
private Project getProject(String projectName) {
private Project getProject(long projectCode) {
Project project = new Project();
project.setId(1);
project.setName(projectName);
project.setCode(projectCode);
project.setName("test");
project.setUserId(1);
return project;
}

Loading…
Cancel
Save