refactor(接口测试): 优化mock,增加版本id

This commit is contained in:
wxg0103 2024-05-10 15:50:13 +08:00 committed by wxg0103
parent 75cb2b66ed
commit 74e3110ac9
9 changed files with 208 additions and 16 deletions

View File

@ -57,6 +57,9 @@ public class ApiDefinitionMock implements Serializable {
@Schema(description = "更新人")
private String updateUser;
@Schema(description = "版本id")
private String versionId;
private static final long serialVersionUID = 1L;
public enum Column {
@ -71,7 +74,8 @@ public class ApiDefinitionMock implements Serializable {
projectId("project_id", "projectId", "VARCHAR", false),
apiDefinitionId("api_definition_id", "apiDefinitionId", "VARCHAR", false),
statusCode("status_code", "statusCode", "INTEGER", false),
updateUser("update_user", "updateUser", "VARCHAR", false);
updateUser("update_user", "updateUser", "VARCHAR", false),
versionId("version_id", "versionId", "VARCHAR", false);
private static final String BEGINNING_DELIMITER = "`";

View File

@ -937,6 +937,76 @@ public class ApiDefinitionMockExample {
addCriterion("update_user not between", value1, value2, "updateUser");
return (Criteria) this;
}
public Criteria andVersionIdIsNull() {
addCriterion("version_id is null");
return (Criteria) this;
}
public Criteria andVersionIdIsNotNull() {
addCriterion("version_id is not null");
return (Criteria) this;
}
public Criteria andVersionIdEqualTo(String value) {
addCriterion("version_id =", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotEqualTo(String value) {
addCriterion("version_id <>", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdGreaterThan(String value) {
addCriterion("version_id >", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdGreaterThanOrEqualTo(String value) {
addCriterion("version_id >=", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdLessThan(String value) {
addCriterion("version_id <", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdLessThanOrEqualTo(String value) {
addCriterion("version_id <=", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdLike(String value) {
addCriterion("version_id like", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotLike(String value) {
addCriterion("version_id not like", value, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdIn(List<String> values) {
addCriterion("version_id in", values, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotIn(List<String> values) {
addCriterion("version_id not in", values, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdBetween(String value1, String value2) {
addCriterion("version_id between", value1, value2, "versionId");
return (Criteria) this;
}
public Criteria andVersionIdNotBetween(String value1, String value2) {
addCriterion("version_id not between", value1, value2, "versionId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -14,6 +14,7 @@
<result column="api_definition_id" jdbcType="VARCHAR" property="apiDefinitionId" />
<result column="status_code" jdbcType="INTEGER" property="statusCode" />
<result column="update_user" jdbcType="VARCHAR" property="updateUser" />
<result column="version_id" jdbcType="VARCHAR" property="versionId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -113,7 +114,7 @@
</sql>
<sql id="Base_Column_List">
id, create_time, update_time, create_user, `name`, tags, `enable`, expect_num, project_id,
api_definition_id, status_code, update_user
api_definition_id, status_code, update_user, version_id
</sql>
<select id="selectByExample" parameterType="io.metersphere.api.domain.ApiDefinitionMockExample" resultMap="BaseResultMap">
select
@ -149,13 +150,13 @@
insert into api_definition_mock (id, create_time, update_time,
create_user, `name`, tags,
`enable`, expect_num, project_id,
api_definition_id, status_code, update_user
)
api_definition_id, status_code, update_user,
version_id)
values (#{id,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{createUser,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{enable,jdbcType=BIT}, #{expectNum,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR},
#{apiDefinitionId,jdbcType=VARCHAR}, #{statusCode,jdbcType=INTEGER}, #{updateUser,jdbcType=VARCHAR}
)
#{apiDefinitionId,jdbcType=VARCHAR}, #{statusCode,jdbcType=INTEGER}, #{updateUser,jdbcType=VARCHAR},
#{versionId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.api.domain.ApiDefinitionMock">
insert into api_definition_mock
@ -196,6 +197,9 @@
<if test="updateUser != null">
update_user,
</if>
<if test="versionId != null">
version_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -234,6 +238,9 @@
<if test="updateUser != null">
#{updateUser,jdbcType=VARCHAR},
</if>
<if test="versionId != null">
#{versionId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.api.domain.ApiDefinitionMockExample" resultType="java.lang.Long">
@ -281,6 +288,9 @@
<if test="record.updateUser != null">
update_user = #{record.updateUser,jdbcType=VARCHAR},
</if>
<if test="record.versionId != null">
version_id = #{record.versionId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -299,7 +309,8 @@
project_id = #{record.projectId,jdbcType=VARCHAR},
api_definition_id = #{record.apiDefinitionId,jdbcType=VARCHAR},
status_code = #{record.statusCode,jdbcType=INTEGER},
update_user = #{record.updateUser,jdbcType=VARCHAR}
update_user = #{record.updateUser,jdbcType=VARCHAR},
version_id = #{record.versionId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -340,6 +351,9 @@
<if test="updateUser != null">
update_user = #{updateUser,jdbcType=VARCHAR},
</if>
<if test="versionId != null">
version_id = #{versionId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -355,20 +369,21 @@
project_id = #{projectId,jdbcType=VARCHAR},
api_definition_id = #{apiDefinitionId,jdbcType=VARCHAR},
status_code = #{statusCode,jdbcType=INTEGER},
update_user = #{updateUser,jdbcType=VARCHAR}
update_user = #{updateUser,jdbcType=VARCHAR},
version_id = #{versionId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<insert id="batchInsert" parameterType="map">
insert into api_definition_mock
(id, create_time, update_time, create_user, `name`, tags, `enable`, expect_num, project_id,
api_definition_id, status_code, update_user)
api_definition_id, status_code, update_user, version_id)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT},
#{item.createUser,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR,typeHandler=io.metersphere.handler.ListTypeHandler},
#{item.enable,jdbcType=BIT}, #{item.expectNum,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR},
#{item.apiDefinitionId,jdbcType=VARCHAR}, #{item.statusCode,jdbcType=INTEGER},
#{item.updateUser,jdbcType=VARCHAR})
#{item.updateUser,jdbcType=VARCHAR}, #{item.versionId,jdbcType=VARCHAR})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -417,6 +432,9 @@
<if test="'update_user'.toString() == column.value">
#{item.updateUser,jdbcType=VARCHAR}
</if>
<if test="'version_id'.toString() == column.value">
#{item.versionId,jdbcType=VARCHAR}
</if>
</foreach>
)
</foreach>

View File

@ -14,6 +14,7 @@ ALTER TABLE test_plan_config DROP COLUMN run_mode_config;
ALTER TABLE test_plan_config ADD COLUMN test_planning BIT NOT NULL DEFAULT 0 COMMENT '是否开启测试规划';
ALTER TABLE api_definition_mock ADD COLUMN update_user VARCHAR(50) COMMENT '更新人';
ALTER TABLE api_definition_mock ADD COLUMN version_id VARCHAR(50) COMMENT '版本id';
ALTER TABLE operation_history MODIFY COLUMN module VARCHAR(100);

View File

@ -1,6 +1,7 @@
package io.metersphere.api.controller.definition;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.page.PageMethod;
import io.metersphere.api.constants.ApiResource;
import io.metersphere.api.constants.ApiResourceType;
@ -20,6 +21,8 @@ import io.metersphere.api.service.definition.ApiDefinitionMockNoticeService;
import io.metersphere.api.service.definition.ApiDefinitionMockService;
import io.metersphere.project.service.FileModuleService;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.OperationHistoryDTO;
import io.metersphere.system.dto.request.OperationHistoryRequest;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
@ -181,5 +184,15 @@ public class ApiDefinitionMockController {
apiDefinitionMockService.batchEdit(request, SessionUtils.getUserId());
}
@PostMapping("/operation-history/page")
@Operation(summary = "接口测试-接口管理-mock-变更历史")
@RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_MOCK_READ, PermissionConstants.PROJECT_API_DEFINITION_MOCK_UPDATE})
@CheckOwner(resourceId = "#request.getSourceId()", resourceType = "api_definition_mock")
public Pager<List<OperationHistoryDTO>> operationHistoryList(@Validated @RequestBody OperationHistoryRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc");
return PageUtils.setPageInfo(page, apiDefinitionMockService.operationHistoryList(request));
}
}

View File

@ -29,8 +29,11 @@ import io.metersphere.sdk.domain.EnvironmentExample;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.mapper.EnvironmentMapper;
import io.metersphere.sdk.util.*;
import io.metersphere.system.dto.OperationHistoryDTO;
import io.metersphere.system.dto.request.OperationHistoryRequest;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.service.OperationHistoryService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
import io.metersphere.system.utils.ServiceUtils;
@ -87,8 +90,11 @@ public class ApiDefinitionMockService {
private ApiDefinitionMockLogService apiDefinitionMockLogService;
@Resource
private ApiDefinitionMockNoticeService apiDefinitionMockNoticeService;
@Resource
private OperationHistoryService operationHistoryService;
public static final String STATUS = "Status";
public static final String TAGS = "Tags";
private static final String MOCK_TABLE = "api_definition_mock";
public List<ApiDefinitionMockDTO> getPage(ApiDefinitionMockPageRequest request) {
return extApiDefinitionMockMapper.list(request);
@ -153,7 +159,7 @@ public class ApiDefinitionMockService {
apiDefinitionMock.setEnable(true);
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionMock.getApiDefinitionId());
apiDefinitionMock.setExpectNum(String.valueOf(NumGenerator.nextNum(request.getProjectId() + "_" + apiDefinition.getNum(), ApplicationNumScope.API_MOCK)));
apiDefinition.setVersionId(apiDefinition.getVersionId());
apiDefinitionMockMapper.insertSelective(apiDefinitionMock);
ApiDefinitionMockConfig apiDefinitionMockConfig = new ApiDefinitionMockConfig();
apiDefinitionMockConfig.setId(apiDefinitionMock.getId());
@ -426,4 +432,8 @@ public class ApiDefinitionMockService {
return request.getSelectIds();
}
}
public List<OperationHistoryDTO> operationHistoryList(OperationHistoryRequest request) {
return operationHistoryService.listWidthTable(request, MOCK_TABLE);
}
}

View File

@ -40,6 +40,7 @@ import io.metersphere.sdk.util.TempFileUtils;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.controller.handler.result.MsHttpResultCode;
import io.metersphere.system.dto.request.OperationHistoryRequest;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource;
@ -434,6 +435,14 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
checkLog(apiDefinitionMock.getId(), OperationLogType.UPDATE, ENABLE + apiDefinitionMock.getId());
assertErrorCode(this.requestGet(ENABLE + "111"), MsHttpResultCode.FAILED);
OperationHistoryRequest request = new OperationHistoryRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSourceId(apiDefinitionMock.getId());
request.setPageSize(10);
request.setCurrent(1);
requestPostWithOkAndReturn(BASE_PATH + "operation-history/page", request);
// @@校验权限
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_MOCK_UPDATE, ENABLE + apiDefinitionMock.getId());
}

View File

@ -51,11 +51,11 @@ INSERT INTO template (id, name, remark, internal, update_time, create_time, crea
DELETE FROM `api_definition_mock` WHERE `id` in ('mock_1', 'mock_2', 'mock_3', 'mock_4','mock_5');
INSERT INTO `api_definition_mock` VALUES
('mock_1', 1641120000000, 1641120000000, 'user1', 'Mock 1', '[\"tag1\",\"tag2\"]', 1, 'EXPECT001', '100001100001', '1001', 200, null),
('mock_2', 1641121000000, 1641121000000, 'user2', 'Mock 2', '[\"tag2\",\"tag3\"]', 1, 'EXPECT002', '100001100001', '1002', 200, null),
('mock_3', 1641122000000, 1641122000000, 'user3', 'Mock 3', '[\"tag3\",\"tag4\"]', 1, 'EXPECT003', '100001100001', '1003', 200, null),
('mock_4', 1641123000000, 1641123000000, 'user1', 'Mock 4', '[\"tag4\",\"tag5\"]', 1, 'EXPECT004', '100001100001', '1005', 400, null),
('mock_5', 1641124000000, 1641124000000, 'user2', 'Mock 5', '[\"tag5\",\"tag1\"]', 1, 'EXPECT005', '100001100001', '1005', 400, null);
('mock_1', 1641120000000, 1641120000000, 'user1', 'Mock 1', '[\"tag1\",\"tag2\"]', 1, 'EXPECT001', '100001100001', '1001', 200, null,'1'),
('mock_2', 1641121000000, 1641121000000, 'user2', 'Mock 2', '[\"tag2\",\"tag3\"]', 1, 'EXPECT002', '100001100001', '1002', 200, null,'1'),
('mock_3', 1641122000000, 1641122000000, 'user3', 'Mock 3', '[\"tag3\",\"tag4\"]', 1, 'EXPECT003', '100001100001', '1003', 200, null,'1'),
('mock_4', 1641123000000, 1641123000000, 'user1', 'Mock 4', '[\"tag4\",\"tag5\"]', 1, 'EXPECT004', '100001100001', '1005', 400, null,'1'),
('mock_5', 1641124000000, 1641124000000, 'user2', 'Mock 5', '[\"tag5\",\"tag1\"]', 1, 'EXPECT005', '100001100001', '1005', 400, null,'1');
DELETE FROM `api_definition_mock_config` WHERE `id` in ('mock_1', 'mock_2', 'mock_3', 'mock_4','mock_5');
INSERT INTO `api_definition_mock_config` VALUES

View File

@ -585,8 +585,75 @@
"useDefaultSubject":true
}
]
},
{
"event":"MOCK_CREATE",
"eventName":"",
"receivers":[
{
"id": "",
"name": ""
}
],
"projectRobotConfigList":[
{
"robotId":"",
"enable":"",
"template":"",
"defaultTemplate":"",
"useDefaultTemplate":true,
"subject":"",
"defaultSubject":"",
"useDefaultSubject":true
}
]
},
{
"event":"MOCK_UPDATE",
"eventName":"",
"receivers":[
{
"id": "CREATE_USER",
"name": ""
}
],
"projectRobotConfigList":[
{
"robotId":"",
"enable":"",
"template":"",
"defaultTemplate":"",
"useDefaultTemplate":true,
"subject":"",
"defaultSubject":"",
"useDefaultSubject":true
}
]
},
{
"event":"MOCK_DELETE",
"eventName":"",
"receivers":[
{
"id": "CREATE_USER",
"name": ""
}
],
"projectRobotConfigList":[
{
"robotId":"",
"enable":"",
"template":"",
"defaultTemplate":"",
"useDefaultTemplate":true,
"subject":"",
"defaultSubject":"",
"useDefaultSubject":true
}
]
}
]
},
{
"taskType":"API_SCENARIO_TASK",