Browse Source

[Improvement-4898][API] the paging query interface validates page params (#4899)

* fix api list-paging method check page params.

* update process definition version class check page params.

* add ProcessInstanceControllerTest in the pom xml file.

* solve sonar exception.

* add project controller test class.

* update create project return result

* update project controller test class code style.

* update sonar problem.

* update QueueController test class.
zhuangchong 4 years ago
parent
commit
fe144e46a3

+ 97 - 27
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java

@@ -126,7 +126,13 @@ public class ProcessDefinitionController extends BaseController {
 
         logger.info("login user {}, create  process definition, project name: {}, process definition name: {}, "
                 + "process_definition_json: {}, desc: {} locations:{}, connects:{}",
-            loginUser.getUserName(), projectName, name, json, description, locations, connects);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(name),
+                RegexUtils.escapeNRT(json),
+                RegexUtils.escapeNRT(description),
+                RegexUtils.escapeNRT(locations),
+                RegexUtils.escapeNRT(connects));
         Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json,
             description, locations, connects);
         return returnDataList(result);
@@ -213,7 +219,9 @@ public class ProcessDefinitionController extends BaseController {
                                               @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
                                               @RequestParam(value = "name", required = true) String name) {
         logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}",
-            loginUser.getUserName(), projectName, name);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(name));
         Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectName, name);
         return returnDataList(result);
     }
@@ -255,9 +263,16 @@ public class ProcessDefinitionController extends BaseController {
                                           @RequestParam(value = "description", required = false) String description,
                                           @RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) {
 
-        logger.info("login user {}, update process define, project name: {}, process define name: {}, "
+        logger.info("login user {}, update process define, project name: {}, process define name: {},"
                 + "process_definition_json: {}, desc: {}, locations:{}, connects:{}",
-            loginUser.getUserName(), projectName, name, processDefinitionJson, description, locations, connects);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(name),
+                RegexUtils.escapeNRT(processDefinitionJson),
+                RegexUtils.escapeNRT(description),
+                RegexUtils.escapeNRT(locations),
+                RegexUtils.escapeNRT(connects));
+
         Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectName, id, name,
             processDefinitionJson, description, locations, connects);
         //  If the update fails, the result will be returned directly
@@ -297,7 +312,18 @@ public class ProcessDefinitionController extends BaseController {
                                                  @RequestParam(value = "pageSize") int pageSize,
                                                  @RequestParam(value = "processDefinitionId") int processDefinitionId) {
 
-        Map<String, Object> result = processDefinitionVersionService.queryProcessDefinitionVersions(loginUser
+        logger.info("query process definition versions, login user {}, project name: {}, process define id: {}, list paging, pageNo: {}, pageSize: {}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                processDefinitionId,
+                pageNo,
+                pageSize);
+
+        Map<String, Object> result = checkPageParams(pageNo, pageSize);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return returnDataListPaging(result);
+        }
+        result = processDefinitionVersionService.queryProcessDefinitionVersions(loginUser
             , projectName, pageNo, pageSize, processDefinitionId);
         return returnDataList(result);
     }
@@ -323,7 +349,11 @@ public class ProcessDefinitionController extends BaseController {
                                                  @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
                                                  @RequestParam(value = "processDefinitionId") int processDefinitionId,
                                                  @RequestParam(value = "version") long version) {
-
+        logger.info("switch certain process definition version, login user {}, project name:{}, process definition id:{}, version:{}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                processDefinitionId,
+                version);
         Map<String, Object> result = processDefinitionService.switchProcessDefinitionVersion(loginUser, projectName
             , processDefinitionId, version);
         return returnDataList(result);
@@ -350,7 +380,11 @@ public class ProcessDefinitionController extends BaseController {
                                                  @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
                                                  @RequestParam(value = "processDefinitionId") int processDefinitionId,
                                                  @RequestParam(value = "version") long version) {
-
+        logger.info("delete the certain process definition version by version and process definition id, login user {}, project name:{}, process definition id:{}, version:{}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                processDefinitionId,
+                version);
         Map<String, Object> result = processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectName, processDefinitionId, version);
         return returnDataList(result);
     }
@@ -379,13 +413,15 @@ public class ProcessDefinitionController extends BaseController {
                                            @RequestParam(value = "releaseState", required = true) ReleaseState releaseState) {
 
         logger.info("login user {}, release process definition, project name: {}, release state: {}",
-            loginUser.getUserName(), projectName, releaseState);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                releaseState);
         Map<String, Object> result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState);
         return returnDataList(result);
     }
 
     /**
-     * query datail of process definition by id
+     * query detail of process definition by id
      *
      * @param loginUser   login user
      * @param projectName project name
@@ -401,16 +437,18 @@ public class ProcessDefinitionController extends BaseController {
     @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR)
     public Result queryProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                              @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
-                                             @RequestParam("processId") Integer processId
-    ) {
+                                             @RequestParam("processId") Integer processId) {
+
         logger.info("query detail of process definition, login user:{}, project name:{}, process definition id:{}",
-            loginUser.getUserName(), projectName, processId);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                processId);
         Map<String, Object> result = processDefinitionService.queryProcessDefinitionById(loginUser, projectName, processId);
         return returnDataList(result);
     }
 
     /**
-     * query datail of process definition by name
+     * query detail of process definition by name
      *
      * @param loginUser login user
      * @param projectName project name
@@ -426,8 +464,12 @@ public class ProcessDefinitionController extends BaseController {
     @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR)
     public Result<ProcessDefinition> queryProcessDefinitionByName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                                                   @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
-                                                                  @RequestParam("processDefinitionName") String processDefinitionName
-    ) {
+                                                                  @RequestParam("processDefinitionName") String processDefinitionName) {
+
+        logger.info("query detail of process definition by name, login user:{}, project name:{}, process definition id:{}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(processDefinitionName));
         Map<String, Object> result = processDefinitionService.queryProcessDefinitionByName(loginUser, projectName, processDefinitionName);
         return returnDataList(result);
     }
@@ -444,10 +486,11 @@ public class ProcessDefinitionController extends BaseController {
     @ResponseStatus(HttpStatus.OK)
     @ApiException(QUERY_PROCESS_DEFINITION_LIST)
     public Result queryProcessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
-                                             @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName
-    ) {
+                                             @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName) {
+
         logger.info("query process definition list, login user:{}, project name:{}",
-            loginUser.getUserName(), projectName);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName));
         Map<String, Object> result = processDefinitionService.queryProcessDefinitionList(loginUser, projectName);
         return returnDataList(result);
     }
@@ -479,7 +522,13 @@ public class ProcessDefinitionController extends BaseController {
                                                    @RequestParam(value = "searchVal", required = false) String searchVal,
                                                    @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
                                                    @RequestParam("pageSize") Integer pageSize) {
-        logger.info("query process definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName);
+
+        logger.info("query process definition list paging, login user:{}, project name:{}, searchVal:{}, userId:{}, pageSize:{}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(searchVal),
+                userId,
+                pageSize);
         Map<String, Object> result = checkPageParams(pageNo, pageSize);
         if (result.get(Constants.STATUS) != Status.SUCCESS) {
             return returnDataListPaging(result);
@@ -490,7 +539,7 @@ public class ProcessDefinitionController extends BaseController {
     }
 
     /**
-     * encapsulation treeview structure
+     * encapsulation tree view structure
      *
      * @param loginUser   login user
      * @param projectName project name
@@ -510,6 +559,12 @@ public class ProcessDefinitionController extends BaseController {
                            @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
                            @RequestParam("processId") Integer id,
                            @RequestParam("limit") Integer limit) throws Exception {
+
+        logger.info("encapsulation tree view structure, login user:{}, project name:{}, processId:{}, limit:{}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                id,
+                limit);
         Map<String, Object> result = processDefinitionService.viewTree(id, limit);
         return returnDataList(result);
     }
@@ -533,8 +588,11 @@ public class ProcessDefinitionController extends BaseController {
         @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
         @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
         @RequestParam("processDefinitionId") Integer processDefinitionId) throws Exception {
+
         logger.info("query task node name list by definitionId, login user:{}, project name:{}, id : {}",
-            loginUser.getUserName(), projectName, processDefinitionId);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                processDefinitionId);
         Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionId(processDefinitionId);
         return returnDataList(result);
     }
@@ -560,7 +618,9 @@ public class ProcessDefinitionController extends BaseController {
         @RequestParam("processDefinitionIdList") String processDefinitionIdList) {
 
         logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}",
-            loginUser.getUserName(), projectName, processDefinitionIdList);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(processDefinitionIdList));
         Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionIdList(processDefinitionIdList);
         return returnDataList(result);
     }
@@ -584,8 +644,11 @@ public class ProcessDefinitionController extends BaseController {
                                               @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
                                               @RequestParam("processDefinitionId") Integer processDefinitionId
     ) {
+
         logger.info("delete process definition by id, login user:{}, project name:{}, process definition id:{}",
-            loginUser.getUserName(), projectName, processDefinitionId);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                processDefinitionId);
         Map<String, Object> result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId);
         return returnDataList(result);
     }
@@ -609,9 +672,11 @@ public class ProcessDefinitionController extends BaseController {
                                                     @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
                                                     @RequestParam("processDefinitionIds") String processDefinitionIds
     ) {
-        logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}",
-            loginUser.getUserName(), projectName, processDefinitionIds);
 
+        logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}",
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                RegexUtils.escapeNRT(projectName),
+                RegexUtils.escapeNRT(processDefinitionIds));
         Map<String, Object> result = new HashMap<>();
         List<String> deleteFailedIdList = new ArrayList<>();
         if (StringUtils.isNotEmpty(processDefinitionIds)) {
@@ -660,8 +725,11 @@ public class ProcessDefinitionController extends BaseController {
                                                   @RequestParam("processDefinitionIds") String processDefinitionIds,
                                                   HttpServletResponse response) {
         try {
+
             logger.info("batch export process definition by ids, login user:{}, project name:{}, process definition ids:{}",
-                loginUser.getUserName(), projectName, processDefinitionIds);
+                    RegexUtils.escapeNRT(loginUser.getUserName()),
+                    RegexUtils.escapeNRT(projectName),
+                    RegexUtils.escapeNRT(processDefinitionIds));
             processDefinitionService.batchExportProcessDefinitionByIds(loginUser, projectName, processDefinitionIds, response);
         } catch (Exception e) {
             logger.error(Status.BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(), e);
@@ -681,8 +749,10 @@ public class ProcessDefinitionController extends BaseController {
     @ApiException(QUERY_PROCESS_DEFINITION_LIST)
     public Result queryProcessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                                        @RequestParam("projectId") Integer projectId) {
+
         logger.info("query process definition list, login user:{}, project id:{}",
-            loginUser.getUserName(), projectId);
+                RegexUtils.escapeNRT(loginUser.getUserName()),
+                projectId);
         Map<String, Object> result = processDefinitionService.queryProcessDefinitionAllByProjectId(projectId);
         return returnDataList(result);
     }

+ 5 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java

@@ -126,8 +126,12 @@ public class ProcessInstanceController extends BaseController {
                         "search value:{},executor name:{},state type:{},host:{},start time:{}, end time:{},page number:{}, page size:{}",
                 loginUser.getUserName(), projectName, processDefinitionId, searchVal, executorName, stateType, host,
                 startTime, endTime, pageNo, pageSize);
+        Map<String, Object> result = checkPageParams(pageNo, pageSize);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return returnDataListPaging(result);
+        }
         searchVal = ParameterUtils.handleEscapes(searchVal);
-        Map<String, Object> result = processInstanceService.queryProcessInstanceList(
+        result = processInstanceService.queryProcessInstanceList(
                 loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize);
         return returnDataListPaging(result);
     }

+ 6 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java

@@ -27,6 +27,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS
 import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_PROJECT_ERROR;
 import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR;
 
+import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.exceptions.ApiException;
 import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
 import org.apache.dolphinscheduler.api.service.ProjectService;
@@ -172,8 +173,12 @@ public class ProjectController extends BaseController {
     ) {
 
         logger.info("login user {}, query project list paging", loginUser.getUserName());
+        Map<String, Object> result = checkPageParams(pageNo, pageSize);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return returnDataListPaging(result);
+        }
         searchVal = ParameterUtils.handleEscapes(searchVal);
-        Map<String, Object> result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal);
+        result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal);
         return returnDataListPaging(result);
     }
 

+ 7 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java

@@ -27,10 +27,12 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_P
 import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_SCHEDULE_ERROR;
 import static org.apache.dolphinscheduler.common.Constants.SESSION_USER;
 
+import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.exceptions.ApiException;
 import org.apache.dolphinscheduler.api.service.SchedulerService;
 import org.apache.dolphinscheduler.api.utils.RegexUtils;
 import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.FailureStrategy;
 import org.apache.dolphinscheduler.common.enums.Priority;
 import org.apache.dolphinscheduler.common.enums.ReleaseState;
@@ -245,8 +247,12 @@ public class SchedulerController extends BaseController {
                                           @RequestParam("pageSize") Integer pageSize) {
         logger.info("login user {}, query schedule, project name: {}, process definition id: {}",
                 loginUser.getUserName(), projectName, processDefinitionId);
+        Map<String, Object> result = checkPageParams(pageNo, pageSize);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return returnDataListPaging(result);
+        }
         searchVal = ParameterUtils.handleEscapes(searchVal);
-        Map<String, Object> result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize);
+        result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize);
         return returnDataListPaging(result);
     }
 

+ 7 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java

@@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.controller;
 import static org.apache.dolphinscheduler.api.enums.Status.FORCE_TASK_SUCCESS_ERROR;
 import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR;
 
+import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.exceptions.ApiException;
 import org.apache.dolphinscheduler.api.service.TaskInstanceService;
 import org.apache.dolphinscheduler.api.utils.RegexUtils;
@@ -122,8 +123,13 @@ public class TaskInstanceController extends BaseController {
                 RegexUtils.escapeNRT(host),
                 RegexUtils.escapeNRT(startTime),
                 RegexUtils.escapeNRT(endTime));
+
+        Map<String, Object> result = checkPageParams(pageNo, pageSize);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return returnDataListPaging(result);
+        }
         searchVal = ParameterUtils.handleEscapes(searchVal);
-        Map<String, Object> result = taskInstanceService.queryTaskListPaging(
+        result = taskInstanceService.queryTaskListPaging(
                 loginUser, projectName, processInstanceId, processInstanceName, taskName, executorName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize);
         return returnDataListPaging(result);
     }

+ 6 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java

@@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_ADDRESS_
 import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_GROUP_FAIL;
 import static org.apache.dolphinscheduler.api.enums.Status.SAVE_ERROR;
 
+import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.exceptions.ApiException;
 import org.apache.dolphinscheduler.api.service.WorkerGroupService;
 import org.apache.dolphinscheduler.api.utils.RegexUtils;
@@ -117,8 +118,12 @@ public class WorkerGroupController extends BaseController {
     ) {
         logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}",
                 RegexUtils.escapeNRT(loginUser.getUserName()), pageNo, pageSize, searchVal);
+        Map<String, Object> result = checkPageParams(pageNo, pageSize);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return returnDataListPaging(result);
+        }
         searchVal = ParameterUtils.handleEscapes(searchVal);
-        Map<String, Object> result = workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal);
+        result = workerGroupService.queryAllGroupPaging(loginUser, pageNo, pageSize, searchVal);
         return returnDataListPaging(result);
     }
 

+ 0 - 11
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java

@@ -119,17 +119,6 @@ public class ProcessDefinitionVersionServiceImpl extends BaseServiceImpl impleme
     @Override
     public Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, int processDefinitionId) {
 
-        Map<String, Object> result = new HashMap<>();
-
-        // check the if pageNo or pageSize less than 1
-        if (pageNo <= 0 || pageSize <= 0) {
-            putMsg(result
-                    , Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
-                    , pageNo
-                    , pageSize);
-            return result;
-        }
-
         Project project = projectMapper.queryByName(projectName);
 
         // check project auth

+ 1 - 2
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java

@@ -38,7 +38,6 @@ import org.springframework.web.context.WebApplicationContext;
 /**
  * abstract controller test
  */
-@Ignore
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes = ApiApplicationServer.class)
 public class AbstractControllerTest {
@@ -64,7 +63,7 @@ public class AbstractControllerTest {
     }
 
     @After
-    public void after(){
+    public void after() throws Exception {
         sessionService.signOut("127.0.0.1", user);
     }
 

+ 13 - 35
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java

@@ -390,22 +390,18 @@ public class ProcessDefinitionControllerTest {
     @Test
     public void testQueryProcessDefinitionVersions() {
         String projectName = "test";
+
+        Result result = processDefinitionController.queryProcessDefinitionVersions(user, projectName, 1, -10, 1);
+        Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), result.getCode().intValue());
+
+        result = processDefinitionController.queryProcessDefinitionVersions(user, projectName, -1, 10, 1);
+        Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), result.getCode().intValue());
+
         Map<String, Object> resultMap = new HashMap<>();
         putMsg(resultMap, Status.SUCCESS);
         resultMap.put(Constants.DATA_LIST, new PageInfo<ProcessDefinitionVersion>(1, 10));
-        Mockito.when(processDefinitionVersionService.queryProcessDefinitionVersions(
-                user
-                , projectName
-                , 1
-                , 10
-                , 1))
-                .thenReturn(resultMap);
-        Result result = processDefinitionController.queryProcessDefinitionVersions(
-                user
-                , projectName
-                , 1
-                , 10
-                , 1);
+        Mockito.when(processDefinitionVersionService.queryProcessDefinitionVersions(user, projectName, 1, 10, 1)).thenReturn(resultMap);
+        result = processDefinitionController.queryProcessDefinitionVersions(user, projectName, 1, 10, 1);
 
         Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
     }
@@ -415,17 +411,8 @@ public class ProcessDefinitionControllerTest {
         String projectName = "test";
         Map<String, Object> resultMap = new HashMap<>();
         putMsg(resultMap, Status.SUCCESS);
-        Mockito.when(processDefinitionService.switchProcessDefinitionVersion(
-                user
-                , projectName
-                , 1
-                , 10))
-                .thenReturn(resultMap);
-        Result result = processDefinitionController.switchProcessDefinitionVersion(
-                user
-                , projectName
-                , 1
-                , 10);
+        Mockito.when(processDefinitionService.switchProcessDefinitionVersion(user, projectName, 1, 10)).thenReturn(resultMap);
+        Result result = processDefinitionController.switchProcessDefinitionVersion(user, projectName, 1, 10);
 
         Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
     }
@@ -435,17 +422,8 @@ public class ProcessDefinitionControllerTest {
         String projectName = "test";
         Map<String, Object> resultMap = new HashMap<>();
         putMsg(resultMap, Status.SUCCESS);
-        Mockito.when(processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(
-                user
-                , projectName
-                , 1
-                , 10))
-                .thenReturn(resultMap);
-        Result result = processDefinitionController.deleteProcessDefinitionVersion(
-                user
-                , projectName
-                , 1
-                , 10);
+        Mockito.when(processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(user, projectName, 1, 10)).thenReturn(resultMap);
+        Result result = processDefinitionController.deleteProcessDefinitionVersion(user, projectName, 1, 10);
 
         Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
     }

+ 42 - 28
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java

@@ -26,7 +26,9 @@ import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.utils.Result;
 import org.apache.dolphinscheduler.common.utils.JSONUtils;
 
+import org.junit.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -36,19 +38,32 @@ import org.springframework.test.web.servlet.MvcResult;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 
+import com.fasterxml.jackson.core.type.TypeReference;
+
 /**
  * project controller test
  */
-public class ProjectControllerTest extends AbstractControllerTest{
+public class ProjectControllerTest extends AbstractControllerTest {
 
     private static Logger logger = LoggerFactory.getLogger(ProjectControllerTest.class);
 
-    @Test
-    public void testCreateProject() throws Exception {
+    private String projectId;
+
+    @Before
+    public void before() throws Exception {
+        projectId = testCreateProject("project_test1", "the test project");
+    }
+
+    @After
+    public void after() throws Exception {
+        testDeleteProject(projectId);
+    }
+
+    private String testCreateProject(String projectName, String description) throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("projectName","project_test1");
-        paramsMap.add("description","the test project");
+        paramsMap.add("projectName",projectName);
+        paramsMap.add("description",description);
 
         MvcResult mvcResult = mockMvc.perform(post("/projects/create")
                 .header(SESSION_ID, sessionId)
@@ -57,17 +72,19 @@ public class ProjectControllerTest extends AbstractControllerTest{
                 .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
                 .andReturn();
 
-        Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
+        Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference<Result<String>>() {});
         Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
         Assert.assertNotNull(result.getData());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("create project return result:{}", mvcResult.getResponse().getContentAsString());
+
+        return (String)result.getData();
     }
 
     @Test
     public void testUpdateProject() throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("projectId","18");
+        paramsMap.add("projectId", projectId);
         paramsMap.add("projectName","project_test_update");
         paramsMap.add("desc","the test project update");
 
@@ -80,16 +97,15 @@ public class ProjectControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
-    }
-
+        logger.info("update project return result:{}", mvcResult.getResponse().getContentAsString());
 
+    }
 
     @Test
     public void testQueryProjectById() throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("projectId","18");
+        paramsMap.add("projectId", projectId);
 
         MvcResult mvcResult = mockMvc.perform(get("/projects/query-by-id")
                 .header(SESSION_ID, sessionId)
@@ -99,8 +115,10 @@ public class ProjectControllerTest extends AbstractControllerTest{
                 .andReturn();
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
-        Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
+        Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
         logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("query project by id :{}, return result:{}", projectId, mvcResult.getResponse().getContentAsString());
+
     }
 
     @Test
@@ -111,7 +129,6 @@ public class ProjectControllerTest extends AbstractControllerTest{
         paramsMap.add("pageSize","2");
         paramsMap.add("pageNo","2");
 
-
         MvcResult mvcResult = mockMvc.perform(get("/projects/list-paging")
                 .header(SESSION_ID, sessionId)
                 .params(paramsMap))
@@ -121,10 +138,9 @@ public class ProjectControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("query list-paging project return result:{}", mvcResult.getResponse().getContentAsString());
     }
 
-
     @Test
     public void testQueryUnauthorizedProject() throws Exception {
 
@@ -140,16 +156,14 @@ public class ProjectControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("query unauth project return result:{}", mvcResult.getResponse().getContentAsString());
     }
 
-
-
     @Test
     public void testQueryAuthorizedProject() throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("userId","2");
+        paramsMap.add("userId",String.valueOf(user.getId()));
 
         MvcResult mvcResult = mockMvc.perform(get("/projects/authed-project")
                 .header(SESSION_ID, sessionId)
@@ -160,9 +174,9 @@ public class ProjectControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
-    }
+        logger.info("query authed project return result:{}", mvcResult.getResponse().getContentAsString());
 
+    }
 
     @Test
     public void testQueryAllProjectList() throws Exception {
@@ -178,7 +192,8 @@ public class ProjectControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("query all project return result:{}", mvcResult.getResponse().getContentAsString());
+
     }
 
     @Ignore
@@ -200,12 +215,10 @@ public class ProjectControllerTest extends AbstractControllerTest{
         logger.info(mvcResult.getResponse().getContentAsString());
     }
 
-
-    @Test
-    public void testDeleteProject() throws Exception {
+    private void testDeleteProject(String projectId) throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("projectId","18");
+        paramsMap.add("projectId", projectId);
 
         MvcResult mvcResult = mockMvc.perform(get("/projects/delete")
                 .header(SESSION_ID, sessionId)
@@ -216,6 +229,7 @@ public class ProjectControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("delete project return result:{}", mvcResult.getResponse().getContentAsString());
     }
+
 }

+ 34 - 19
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/QueueControllerTest.java

@@ -38,10 +38,12 @@ import org.springframework.util.MultiValueMap;
 /**
  * queue controller test
  */
-public class QueueControllerTest extends AbstractControllerTest{
+public class QueueControllerTest extends AbstractControllerTest {
 
     private static Logger logger = LoggerFactory.getLogger(QueueControllerTest.class);
 
+    private static final String QUEUE_CREATE_STRING = "queue1";
+
     @Test
     public void testQueryList() throws Exception {
 
@@ -53,14 +55,13 @@ public class QueueControllerTest extends AbstractControllerTest{
 
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("query list queue return result:{}", mvcResult.getResponse().getContentAsString());
     }
 
     @Test
     public void testQueryQueueListPaging() throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        //paramsMap.add("processInstanceId","1380");
         paramsMap.add("searchVal","");
         paramsMap.add("pageNo","1");
         paramsMap.add("pageSize","20");
@@ -73,18 +74,16 @@ public class QueueControllerTest extends AbstractControllerTest{
                 .andReturn();
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
         Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
-    }
-
-
+        logger.info("query list-paging queue return result:{}", mvcResult.getResponse().getContentAsString());
 
+    }
 
     @Test
     public void testCreateQueue() throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("queue","ait");
-        paramsMap.add("queueName","ait");
+        paramsMap.add("queue", QUEUE_CREATE_STRING);
+        paramsMap.add("queueName","root.queue1");
 
         MvcResult mvcResult = mockMvc.perform(post("/queue/create")
                 .header(SESSION_ID, sessionId)
@@ -93,17 +92,17 @@ public class QueueControllerTest extends AbstractControllerTest{
                 .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
                 .andReturn();
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
-//        Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
+        logger.info("create queue return result:{}", mvcResult.getResponse().getContentAsString());
     }
 
     @Test
     public void testUpdateQueue() throws Exception {
 
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("id","2");
-        paramsMap.add("queue","ait12");
-        paramsMap.add("queueName","aitName");
+        paramsMap.add("id","1");
+        paramsMap.add("queue","queue2");
+        paramsMap.add("queueName","root.queue2");
 
         MvcResult mvcResult = mockMvc.perform(post("/queue/update")
                 .header(SESSION_ID, sessionId)
@@ -112,16 +111,17 @@ public class QueueControllerTest extends AbstractControllerTest{
                 .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
                 .andReturn();
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
-        //Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
-        logger.info(mvcResult.getResponse().getContentAsString());
+        Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
+        logger.info("update queue return result:{}", mvcResult.getResponse().getContentAsString());
     }
 
     @Test
     public void testVerifyQueue() throws Exception {
 
+        // queue value exist
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("queue","ait123");
-        paramsMap.add("queueName","aitName");
+        paramsMap.add("queue",QUEUE_CREATE_STRING);
+        paramsMap.add("queueName","queue.name");
 
         MvcResult mvcResult = mockMvc.perform(post("/queue/verify-queue")
                 .header(SESSION_ID, sessionId)
@@ -130,7 +130,22 @@ public class QueueControllerTest extends AbstractControllerTest{
                 .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
                 .andReturn();
         Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
-        //Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
+        Assert.assertEquals(Status.QUEUE_VALUE_EXIST.getCode(),result.getCode().intValue());
+
+        // success
+        paramsMap.clear();
+        paramsMap.add("queue","ait123");
+        paramsMap.add("queueName","aitName");
+
+        mvcResult = mockMvc.perform(post("/queue/verify-queue")
+                .header(SESSION_ID, sessionId)
+                .params(paramsMap))
+                .andExpect(status().isOk())
+                .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
+                .andReturn();
+        result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
+        Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
         logger.info(mvcResult.getResponse().getContentAsString());
+        logger.info("verify queue return result:{}", mvcResult.getResponse().getContentAsString());
     }
 }

+ 0 - 20
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java

@@ -91,26 +91,6 @@ public class ProcessDefinitionVersionServiceTest {
         User loginUser = new User();
         loginUser.setId(-1);
         loginUser.setUserType(UserType.GENERAL_USER);
-        Map<String, Object> resultMap1 = processDefinitionVersionService.queryProcessDefinitionVersions(
-                loginUser
-                , projectName
-                , pageNo
-                , pageSize
-                , processDefinitionId);
-        Assert.assertEquals(Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
-                , resultMap1.get(Constants.STATUS));
-
-        // pageSize <= 0
-        pageNo = 1;
-        pageSize = -1;
-        Map<String, Object> resultMap2 = processDefinitionVersionService.queryProcessDefinitionVersions(
-                loginUser
-                , projectName
-                , pageNo
-                , pageSize
-                , processDefinitionId);
-        Assert.assertEquals(Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
-                , resultMap2.get(Constants.STATUS));
 
         Map<String, Object> res = new HashMap<>();
         putMsg(res, Status.PROJECT_NOT_FOUNT);

+ 2 - 0
pom.xml

@@ -795,6 +795,8 @@
                 <version>${maven-surefire-plugin.version}</version>
                 <configuration>
                     <includes>
+                        <include>**/api/controller/ProjectControllerTest.java</include>
+                        <include>**/api/controller/QueueControllerTest.java</include>
                         <include>**/api/configuration/TrafficConfigurationTest.java</include>
                         <include>**/api/controller/ProcessDefinitionControllerTest.java</include>
                         <include>**/api/controller/TenantControllerTest.java</include>