refactor(任务中心): 优化测试用例mock调用
This commit is contained in:
parent
fe8f215fe5
commit
2abb563b65
|
@ -4,25 +4,37 @@ import io.metersphere.sdk.constants.ExecTaskType;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.base.BaseTest;
|
import io.metersphere.system.base.BaseTest;
|
||||||
import io.metersphere.system.controller.handler.ResultHolder;
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
|
import io.metersphere.system.domain.ExecTaskItem;
|
||||||
|
import io.metersphere.system.domain.ExecTaskItemExample;
|
||||||
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
|
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
|
||||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||||
import io.metersphere.system.dto.taskhub.request.ScheduleRequest;
|
import io.metersphere.system.dto.taskhub.request.ScheduleRequest;
|
||||||
import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest;
|
import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest;
|
||||||
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
|
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
|
||||||
|
import io.metersphere.system.mapper.ExecTaskItemMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.test.context.jdbc.Sql;
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
import org.springframework.test.context.jdbc.SqlConfig;
|
import org.springframework.test.context.jdbc.SqlConfig;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ProjectTaskHubControllerTests extends BaseTest {
|
public class ProjectTaskHubControllerTests extends BaseTest {
|
||||||
|
|
||||||
|
@Value("${embedded.mockserver.host}")
|
||||||
|
private String host;
|
||||||
|
@Value("${embedded.mockserver.port}")
|
||||||
|
private int port;
|
||||||
|
@Resource
|
||||||
|
private ExecTaskItemMapper execTaskItemMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目任务中心测试用例
|
* 项目任务中心测试用例
|
||||||
*/
|
*/
|
||||||
|
@ -196,14 +208,13 @@ public class ProjectTaskHubControllerTests extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void projectTaskItemStop() throws Exception {
|
public void projectTaskItemStop() throws Exception {
|
||||||
|
ExecTaskItem execTaskItem = new ExecTaskItem();
|
||||||
|
execTaskItem.setResourcePoolNode(host + ":" + port);
|
||||||
|
ExecTaskItemExample itemExample = new ExecTaskItemExample();
|
||||||
|
itemExample.createCriteria().andIdIn(List.of("pro_1", "pro_2"));
|
||||||
|
execTaskItemMapper.updateByExampleSelective(execTaskItem, itemExample);
|
||||||
mockPost("/api/task/item/stop", "");
|
mockPost("/api/task/item/stop", "");
|
||||||
this.requestGet(PROJECT_TASK_ITEM_STOP + "pro_1");
|
this.requestGet(PROJECT_TASK_ITEM_STOP + "pro_1");
|
||||||
MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_TASK_ITEM_STOP + "pro_2");
|
|
||||||
// 获取返回值
|
|
||||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
|
||||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
|
||||||
// 返回请求正常
|
|
||||||
Assertions.assertNotNull(resultHolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,35 @@
|
||||||
package io.metersphere.system.controller;
|
package io.metersphere.system.controller;
|
||||||
|
|
||||||
import io.metersphere.sdk.constants.ExecTaskType;
|
import io.metersphere.sdk.constants.ExecTaskType;
|
||||||
import io.metersphere.sdk.constants.SessionConstants;
|
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.base.BaseTest;
|
import io.metersphere.system.base.BaseTest;
|
||||||
import io.metersphere.system.controller.handler.ResultHolder;
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
import io.metersphere.system.domain.ExecTask;
|
import io.metersphere.system.domain.ExecTask;
|
||||||
import io.metersphere.system.domain.ExecTaskItem;
|
import io.metersphere.system.domain.ExecTaskItem;
|
||||||
|
import io.metersphere.system.domain.ExecTaskItemExample;
|
||||||
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
|
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
|
||||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||||
import io.metersphere.system.dto.taskhub.request.ScheduleRequest;
|
import io.metersphere.system.dto.taskhub.request.ScheduleRequest;
|
||||||
import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest;
|
import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest;
|
||||||
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
|
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
|
||||||
|
import io.metersphere.system.mapper.ExecTaskItemMapper;
|
||||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||||
import io.metersphere.system.service.BaseTaskHubService;
|
import io.metersphere.system.service.BaseTaskHubService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.test.context.jdbc.Sql;
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
import org.springframework.test.context.jdbc.SqlConfig;
|
import org.springframework.test.context.jdbc.SqlConfig;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
|
@ -42,6 +39,12 @@ public class BaseTaskHubControllerTests extends BaseTest {
|
||||||
private BaseTaskHubService baseTaskHubService;
|
private BaseTaskHubService baseTaskHubService;
|
||||||
@Resource
|
@Resource
|
||||||
private TestResourcePoolMapper testResourcePoolMapper;
|
private TestResourcePoolMapper testResourcePoolMapper;
|
||||||
|
@Value("${embedded.mockserver.host}")
|
||||||
|
private String host;
|
||||||
|
@Value("${embedded.mockserver.port}")
|
||||||
|
private int port;
|
||||||
|
@Resource
|
||||||
|
private ExecTaskItemMapper execTaskItemMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统任务中心测试用例
|
* 系统任务中心测试用例
|
||||||
|
@ -173,6 +176,11 @@ public class BaseTaskHubControllerTests extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void systemTaskStop() throws Exception {
|
public void systemTaskStop() throws Exception {
|
||||||
|
ExecTaskItem execTaskItem = new ExecTaskItem();
|
||||||
|
execTaskItem.setResourcePoolNode(host + ":" + port);
|
||||||
|
ExecTaskItemExample itemExample = new ExecTaskItemExample();
|
||||||
|
itemExample.createCriteria().andIdIn(List.of("1", "2"));
|
||||||
|
execTaskItemMapper.updateByExampleSelective(execTaskItem, itemExample);
|
||||||
mockPost("/api/task/item/stop", "");
|
mockPost("/api/task/item/stop", "");
|
||||||
this.requestGet(SYSTEM_TASK_STOP + "1");
|
this.requestGet(SYSTEM_TASK_STOP + "1");
|
||||||
mockPost("/api/task/stop", "");
|
mockPost("/api/task/stop", "");
|
||||||
|
|
Loading…
Reference in New Issue