fix(Mock期望): #1007531 【接口测试】mock期望列表增加序号列

--bug=1007531 --user=宋天阳 【接口测试】mock期望列表增加序号列
https://www.tapd.cn/55049933/s/1062529
This commit is contained in:
song-tianyang 2021-11-01 18:54:12 +08:00 committed by song-tianyang
parent 04b1e49b0c
commit 213e9d0d01
12 changed files with 529 additions and 347 deletions

View File

@ -19,6 +19,8 @@ public class MockExpectConfigResponse {
private String id; private String id;
private String expectNum;
private String mockConfigId; private String mockConfigId;
private String name; private String name;
@ -40,6 +42,7 @@ public class MockExpectConfigResponse {
public MockExpectConfigResponse(MockExpectConfigWithBLOBs expectConfig) { public MockExpectConfigResponse(MockExpectConfigWithBLOBs expectConfig) {
this.id = expectConfig.getId(); this.id = expectConfig.getId();
this.mockConfigId = expectConfig.getMockConfigId(); this.mockConfigId = expectConfig.getMockConfigId();
this.expectNum = expectConfig.getExpectNum();
this.name = expectConfig.getName(); this.name = expectConfig.getName();
this.status = Boolean.parseBoolean(expectConfig.getStatus()); this.status = Boolean.parseBoolean(expectConfig.getStatus());
this.createTime = expectConfig.getCreateTime(); this.createTime = expectConfig.getCreateTime();

View File

@ -657,7 +657,7 @@ public class ApiDefinitionService {
apiDefinition.setId(UUID.randomUUID().toString()); apiDefinition.setId(UUID.randomUUID().toString());
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
reSetImportCasesApiId(cases, originId, apiDefinition.getId()); reSetImportCasesApiId(cases, originId, apiDefinition.getId());
reSetImportMocksApiId(mocks, originId, apiDefinition.getId()); reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) { if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
batchMapper.insert(apiDefinition); batchMapper.insert(apiDefinition);
String request = setImportHashTree(apiDefinition); String request = setImportHashTree(apiDefinition);
@ -716,13 +716,16 @@ public class ApiDefinitionService {
} }
} }
private void reSetImportMocksApiId(List<MockConfigImportDTO> mocks, String originId, String newId) { private void reSetImportMocksApiId(List<MockConfigImportDTO> mocks, String originId, String newId, int apiNum) {
if (CollectionUtils.isNotEmpty(mocks)) { if (CollectionUtils.isNotEmpty(mocks)) {
mocks.forEach(item -> { int index = 1;
for(MockConfigImportDTO item : mocks){
if (StringUtils.equals(item.getApiId(), originId)) { if (StringUtils.equals(item.getApiId(), originId)) {
item.setApiId(newId); item.setApiId(newId);
} }
}); item.setExpectNum(apiNum+"_"+index);
index++;
}
} }
} }

View File

@ -14,7 +14,6 @@ import io.metersphere.api.dto.mock.RequestMockParams;
import io.metersphere.api.dto.mockconfig.MockConfigImportDTO; import io.metersphere.api.dto.mockconfig.MockConfigImportDTO;
import io.metersphere.api.dto.mockconfig.MockConfigRequest; import io.metersphere.api.dto.mockconfig.MockConfigRequest;
import io.metersphere.api.dto.mockconfig.MockExpectConfigRequest; import io.metersphere.api.dto.mockconfig.MockExpectConfigRequest;
import io.metersphere.api.dto.mockconfig.response.JsonSchemaReturnObj;
import io.metersphere.api.dto.mockconfig.response.MockConfigResponse; import io.metersphere.api.dto.mockconfig.response.MockConfigResponse;
import io.metersphere.api.dto.mockconfig.response.MockExpectConfigResponse; import io.metersphere.api.dto.mockconfig.response.MockExpectConfigResponse;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
@ -44,6 +43,7 @@ import java.io.*;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -109,15 +109,38 @@ public class MockConfigService {
expectConfigResponseList.add(response); expectConfigResponseList.add(response);
} }
MockConfigResponse returnRsp = new MockConfigResponse(config, expectConfigResponseList); return new MockConfigResponse(config, expectConfigResponseList);
return returnRsp;
} else { } else {
return new MockConfigResponse(null, new ArrayList<>()); return new MockConfigResponse(null, new ArrayList<>());
} }
} }
public void initExpectNum(){
MockExpectConfigExample example = new MockExpectConfigExample();
example.createCriteria().andExpectNumIsNull();
List<MockExpectConfigWithBLOBs> mockExpectConfigList = mockExpectConfigMapper.selectByExampleWithBLOBs(example);
Map<String,List<MockExpectConfigWithBLOBs>> mockConfigIdMap = mockExpectConfigList.stream().collect(Collectors.groupingBy(MockExpectConfig::getMockConfigId));
for (Map.Entry<String, List<MockExpectConfigWithBLOBs>> entry :
mockConfigIdMap.entrySet()) {
String mockConfigId = entry.getKey();
List<MockExpectConfigWithBLOBs> list = entry.getValue();
String apiNum = extMockExpectConfigMapper.selectApiNumberByMockConfigId(mockConfigId);
if(StringUtils.isEmpty(apiNum) || StringUtils.equalsIgnoreCase(apiNum,"null")){
continue;
}
int expectNumIndex = this.getMockExpectNumIndex(mockConfigId,apiNum);
for (MockExpectConfigWithBLOBs config : list) {
config.setExpectNum(apiNum+"_"+expectNumIndex);
mockExpectConfigMapper.updateByPrimaryKeySelective(config);
expectNumIndex ++;
}
}
}
public MockConfigResponse genMockConfig(MockConfigRequest request) { public MockConfigResponse genMockConfig(MockConfigRequest request) {
MockConfigResponse returnRsp = null; MockConfigResponse returnRsp;
MockConfigExample example = new MockConfigExample(); MockConfigExample example = new MockConfigExample();
MockConfigExample.Criteria criteria = example.createCriteria(); MockConfigExample.Criteria criteria = example.createCriteria();
@ -193,8 +216,11 @@ public class MockConfigService {
this.checkNameIsExists(request); this.checkNameIsExists(request);
} }
long timeStmp = System.currentTimeMillis(); long timeStmp = System.currentTimeMillis();
String expectNum = this.getMockExpectId(request.getMockConfigId());
MockExpectConfigWithBLOBs model = new MockExpectConfigWithBLOBs(); MockExpectConfigWithBLOBs model = new MockExpectConfigWithBLOBs();
model.setId(request.getId()); model.setId(request.getId());
model.setExpectNum(expectNum);
model.setMockConfigId(request.getMockConfigId()); model.setMockConfigId(request.getMockConfigId());
model.setUpdateTime(timeStmp); model.setUpdateTime(timeStmp);
model.setStatus(request.getStatus()); model.setStatus(request.getStatus());
@ -223,6 +249,54 @@ public class MockConfigService {
return model; return model;
} }
private String getMockExpectId(String mockConfigId) {
List<String> savedExpectNumber = extMockExpectConfigMapper.selectExlectNumByMockConfigId(mockConfigId);
String apiNum = extMockExpectConfigMapper.selectApiNumberByMockConfigId(mockConfigId);
if(StringUtils.isEmpty(apiNum)){
apiNum = "";
}else {
apiNum = apiNum + "_";
}
int index = 1;
for(String expectNum : savedExpectNumber){
if(StringUtils.startsWith(expectNum,apiNum)){
String numStr = StringUtils.substringAfter(expectNum,apiNum);
try{
int savedIndex = Integer.parseInt(numStr);
if(index <= savedIndex){
index = savedIndex+1;
}
}catch (Exception ignored){}
}
}
return apiNum + index;
}
private int getMockExpectNumIndex(String mockConfigId,String apiNumber) {
List<String> savedExpectNumber = extMockExpectConfigMapper.selectExlectNumByMockConfigId(mockConfigId);
String apiNum = apiNumber;
if(StringUtils.isEmpty(apiNum)){
apiNum = "";
}else {
apiNum = apiNum + "_";
}
int index = 1;
for(String expectNum : savedExpectNumber){
if(StringUtils.startsWith(expectNum,apiNum)){
String numStr = StringUtils.substringAfter(expectNum,apiNum);
try{
int savedIndex = Integer.parseInt(numStr);
if(index <= savedIndex){
index = savedIndex+1;
}
}catch (Exception ignored ){}
}
}
return index;
}
private void checkNameIsExists(MockExpectConfigRequest request) { private void checkNameIsExists(MockExpectConfigRequest request) {
MockExpectConfigExample example = new MockExpectConfigExample(); MockExpectConfigExample example = new MockExpectConfigExample();
example.createCriteria().andMockConfigIdEqualTo(request.getMockConfigId()).andNameEqualTo(request.getName().trim()).andIdNotEqualTo(request.getId()); example.createCriteria().andMockConfigIdEqualTo(request.getMockConfigId()).andNameEqualTo(request.getName().trim()).andIdNotEqualTo(request.getId());
@ -259,14 +333,14 @@ public class MockConfigService {
continue; continue;
} }
JSONObject mockExpectRequestObj = model.getRequest(); JSONObject mockExpectRequestObj = model.getRequest();
boolean mathing = false; boolean isMatch;
if (mockExpectRequestObj.containsKey("params")) { if (mockExpectRequestObj.containsKey("params")) {
mathing = this.isRequestMockExpectMatchingByParams(requestHeaderMap, mockExpectRequestObj, requestMockParams); isMatch = this.isRequestMockExpectMatchingByParams(requestHeaderMap, mockExpectRequestObj, requestMockParams);
} else { } else {
mathing = this.isRequestMockExpectMatching(mockExpectRequestObj, requestMockParams.getQueryParamsObj()); isMatch = this.isRequestMockExpectMatching(mockExpectRequestObj, requestMockParams.getQueryParamsObj());
} }
if (mathing) { if (isMatch) {
returnModel = model; returnModel = model;
break; break;
} }

View File

@ -1,7 +1,6 @@
package io.metersphere.base.domain; package io.metersphere.base.domain;
import java.io.Serializable; import java.io.Serializable;
import lombok.Data; import lombok.Data;
@Data @Data
@ -22,5 +21,7 @@ public class MockExpectConfig implements Serializable {
private String createUserId; private String createUserId;
private String expectNum;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@ -643,6 +643,76 @@ public class MockExpectConfigExample {
addCriterion("create_user_id not between", value1, value2, "createUserId"); addCriterion("create_user_id not between", value1, value2, "createUserId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andExpectNumIsNull() {
addCriterion("expect_num is null");
return (Criteria) this;
}
public Criteria andExpectNumIsNotNull() {
addCriterion("expect_num is not null");
return (Criteria) this;
}
public Criteria andExpectNumEqualTo(String value) {
addCriterion("expect_num =", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumNotEqualTo(String value) {
addCriterion("expect_num <>", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumGreaterThan(String value) {
addCriterion("expect_num >", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumGreaterThanOrEqualTo(String value) {
addCriterion("expect_num >=", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumLessThan(String value) {
addCriterion("expect_num <", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumLessThanOrEqualTo(String value) {
addCriterion("expect_num <=", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumLike(String value) {
addCriterion("expect_num like", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumNotLike(String value) {
addCriterion("expect_num not like", value, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumIn(List<String> values) {
addCriterion("expect_num in", values, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumNotIn(List<String> values) {
addCriterion("expect_num not in", values, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumBetween(String value1, String value2) {
addCriterion("expect_num between", value1, value2, "expectNum");
return (Criteria) this;
}
public Criteria andExpectNumNotBetween(String value1, String value2) {
addCriterion("expect_num not between", value1, value2, "expectNum");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {

View File

@ -1,7 +1,6 @@
package io.metersphere.base.domain; package io.metersphere.base.domain;
import java.io.Serializable; import java.io.Serializable;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;

View File

@ -3,9 +3,7 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.MockExpectConfig; import io.metersphere.base.domain.MockExpectConfig;
import io.metersphere.base.domain.MockExpectConfigExample; import io.metersphere.base.domain.MockExpectConfigExample;
import io.metersphere.base.domain.MockExpectConfigWithBLOBs; import io.metersphere.base.domain.MockExpectConfigWithBLOBs;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
public interface MockExpectConfigMapper { public interface MockExpectConfigMapper {

View File

@ -1,345 +1,356 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.MockExpectConfigMapper"> <mapper namespace="io.metersphere.base.mapper.MockExpectConfigMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.MockExpectConfig"> <resultMap id="BaseResultMap" type="io.metersphere.base.domain.MockExpectConfig">
<id column="id" jdbcType="VARCHAR" property="id"/> <id column="id" jdbcType="VARCHAR" property="id" />
<result column="mock_config_id" jdbcType="VARCHAR" property="mockConfigId"/> <result column="mock_config_id" jdbcType="VARCHAR" property="mockConfigId" />
<result column="name" jdbcType="VARCHAR" property="name"/> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="tags" jdbcType="VARCHAR" property="tags"/> <result column="tags" jdbcType="VARCHAR" property="tags" />
<result column="STATUS" jdbcType="VARCHAR" property="status"/> <result column="STATUS" jdbcType="VARCHAR" property="status" />
<result column="create_time" jdbcType="BIGINT" property="createTime"/> <result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime"/> <result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/> <result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
</resultMap> <result column="expect_num" jdbcType="VARCHAR" property="expectNum" />
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" </resultMap>
type="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
<result column="request" jdbcType="LONGVARCHAR" property="request"/> <result column="request" jdbcType="LONGVARCHAR" property="request" />
<result column="response" jdbcType="LONGVARCHAR" property="response"/> <result column="response" jdbcType="LONGVARCHAR" property="response" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid"> <if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")"> <trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion"> <foreach collection="criteria.criteria" item="criterion">
<choose> <choose>
<when test="criterion.noValue"> <when test="criterion.noValue">
and ${criterion.condition} and ${criterion.condition}
</when> </when>
<when test="criterion.singleValue"> <when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.betweenValue"> <when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
separator=","> #{listItem}
#{listItem} </foreach>
</foreach> </when>
</when> </choose>
</choose>
</foreach>
</trim>
</if>
</foreach> </foreach>
</where> </trim>
</sql> </if>
<sql id="Update_By_Example_Where_Clause"> </foreach>
<where> </where>
<foreach collection="example.oredCriteria" item="criteria" separator="or"> </sql>
<if test="criteria.valid"> <sql id="Update_By_Example_Where_Clause">
<trim prefix="(" prefixOverrides="and" suffix=")"> <where>
<foreach collection="criteria.criteria" item="criterion"> <foreach collection="example.oredCriteria" item="criteria" separator="or">
<choose> <if test="criteria.valid">
<when test="criterion.noValue"> <trim prefix="(" prefixOverrides="and" suffix=")">
and ${criterion.condition} <foreach collection="criteria.criteria" item="criterion">
</when> <choose>
<when test="criterion.singleValue"> <when test="criterion.noValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition}
</when> </when>
<when test="criterion.betweenValue"> <when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.listValue"> <when test="criterion.betweenValue">
and ${criterion.condition} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
<foreach close=")" collection="criterion.value" item="listItem" open="(" </when>
separator=","> <when test="criterion.listValue">
#{listItem} and ${criterion.condition}
</foreach> <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
</when> #{listItem}
</choose> </foreach>
</foreach> </when>
</trim> </choose>
</if>
</foreach> </foreach>
</where> </trim>
</sql>
<sql id="Base_Column_List">
id, mock_config_id, `name`, tags, `STATUS`, create_time, update_time, create_user_id
</sql>
<sql id="Blob_Column_List">
request, response
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigExample"
resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if> </if>
<include refid="Base_Column_List"/> </foreach>
, </where>
<include refid="Blob_Column_List"/> </sql>
from mock_expect_config <sql id="Base_Column_List">
<if test="_parameter != null"> id, mock_config_id, `name`, tags, `STATUS`, create_time, update_time, create_user_id,
<include refid="Example_Where_Clause"/> expect_num
</if> </sql>
<if test="orderByClause != null"> <sql id="Blob_Column_List">
order by ${orderByClause} request, response
</if> </sql>
</select> <select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigExample" resultMap="ResultMapWithBLOBs">
<select id="selectByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" select
resultMap="BaseResultMap"> <if test="distinct">
select distinct
<if test="distinct"> </if>
distinct <include refid="Base_Column_List" />
</if> ,
<include refid="Base_Column_List"/> <include refid="Blob_Column_List" />
from mock_expect_config from mock_expect_config
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause" />
</if> </if>
<if test="orderByClause != null"> <if test="orderByClause != null">
order by ${orderByClause} order by ${orderByClause}
</if> </if>
</select> </select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs"> <select id="selectByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <if test="distinct">
, distinct
<include refid="Blob_Column_List"/> </if>
from mock_expect_config <include refid="Base_Column_List" />
where id = #{id,jdbcType=VARCHAR} from mock_expect_config
</select> <if test="_parameter != null">
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> <include refid="Example_Where_Clause" />
delete </if>
from mock_expect_config <if test="orderByClause != null">
where id = #{id,jdbcType=VARCHAR} order by ${orderByClause}
</delete> </if>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample"> </select>
delete from mock_expect_config <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
<if test="_parameter != null"> select
<include refid="Example_Where_Clause"/> <include refid="Base_Column_List" />
</if> ,
</delete> <include refid="Blob_Column_List" />
<insert id="insert" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> from mock_expect_config
insert into mock_expect_config (id, mock_config_id, `name`, where id = #{id,jdbcType=VARCHAR}
tags, `STATUS`, create_time, </select>
update_time, create_user_id, request, <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
response) delete from mock_expect_config
values (#{id,jdbcType=VARCHAR}, #{mockConfigId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, where id = #{id,jdbcType=VARCHAR}
#{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, </delete>
#{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, #{request,jdbcType=LONGVARCHAR}, <delete id="deleteByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample">
#{response,jdbcType=LONGVARCHAR}) delete from mock_expect_config
</insert> <if test="_parameter != null">
<insert id="insertSelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> <include refid="Example_Where_Clause" />
insert into mock_expect_config </if>
<trim prefix="(" suffix=")" suffixOverrides=","> </delete>
<if test="id != null"> <insert id="insert" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
id, insert into mock_expect_config (id, mock_config_id, `name`,
</if> tags, `STATUS`, create_time,
<if test="mockConfigId != null"> update_time, create_user_id, expect_num,
mock_config_id, request, response)
</if> values (#{id,jdbcType=VARCHAR}, #{mockConfigId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
<if test="name != null"> #{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
`name`, #{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, #{expectNum,jdbcType=VARCHAR},
</if> #{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR})
<if test="tags != null"> </insert>
tags, <insert id="insertSelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
</if> insert into mock_expect_config
<if test="status != null"> <trim prefix="(" suffix=")" suffixOverrides=",">
`STATUS`, <if test="id != null">
</if> id,
<if test="createTime != null"> </if>
create_time, <if test="mockConfigId != null">
</if> mock_config_id,
<if test="updateTime != null"> </if>
update_time, <if test="name != null">
</if> `name`,
<if test="createUserId != null"> </if>
create_user_id, <if test="tags != null">
</if> tags,
<if test="request != null"> </if>
request, <if test="status != null">
</if> `STATUS`,
<if test="response != null"> </if>
response, <if test="createTime != null">
</if> create_time,
</trim> </if>
<trim prefix="values (" suffix=")" suffixOverrides=","> <if test="updateTime != null">
<if test="id != null"> update_time,
#{id,jdbcType=VARCHAR}, </if>
</if> <if test="createUserId != null">
<if test="mockConfigId != null"> create_user_id,
#{mockConfigId,jdbcType=VARCHAR}, </if>
</if> <if test="expectNum != null">
<if test="name != null"> expect_num,
#{name,jdbcType=VARCHAR}, </if>
</if> <if test="request != null">
<if test="tags != null"> request,
#{tags,jdbcType=VARCHAR}, </if>
</if> <if test="response != null">
<if test="status != null"> response,
#{status,jdbcType=VARCHAR}, </if>
</if> </trim>
<if test="createTime != null"> <trim prefix="values (" suffix=")" suffixOverrides=",">
#{createTime,jdbcType=BIGINT}, <if test="id != null">
</if> #{id,jdbcType=VARCHAR},
<if test="updateTime != null"> </if>
#{updateTime,jdbcType=BIGINT}, <if test="mockConfigId != null">
</if> #{mockConfigId,jdbcType=VARCHAR},
<if test="createUserId != null"> </if>
#{createUserId,jdbcType=VARCHAR}, <if test="name != null">
</if> #{name,jdbcType=VARCHAR},
<if test="request != null"> </if>
#{request,jdbcType=LONGVARCHAR}, <if test="tags != null">
</if> #{tags,jdbcType=VARCHAR},
<if test="response != null"> </if>
#{response,jdbcType=LONGVARCHAR}, <if test="status != null">
</if> #{status,jdbcType=VARCHAR},
</trim> </if>
</insert> <if test="createTime != null">
<select id="countByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" #{createTime,jdbcType=BIGINT},
resultType="java.lang.Long"> </if>
select count(*) from mock_expect_config <if test="updateTime != null">
<if test="_parameter != null"> #{updateTime,jdbcType=BIGINT},
<include refid="Example_Where_Clause"/> </if>
</if> <if test="createUserId != null">
</select> #{createUserId,jdbcType=VARCHAR},
<update id="updateByExampleSelective" parameterType="map"> </if>
update mock_expect_config <if test="expectNum != null">
<set> #{expectNum,jdbcType=VARCHAR},
<if test="record.id != null"> </if>
id = #{record.id,jdbcType=VARCHAR}, <if test="request != null">
</if> #{request,jdbcType=LONGVARCHAR},
<if test="record.mockConfigId != null"> </if>
mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR}, <if test="response != null">
</if> #{response,jdbcType=LONGVARCHAR},
<if test="record.name != null"> </if>
`name` = #{record.name,jdbcType=VARCHAR}, </trim>
</if> </insert>
<if test="record.tags != null"> <select id="countByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" resultType="java.lang.Long">
tags = #{record.tags,jdbcType=VARCHAR}, select count(*) from mock_expect_config
</if> <if test="_parameter != null">
<if test="record.status != null"> <include refid="Example_Where_Clause" />
`STATUS` = #{record.status,jdbcType=VARCHAR}, </if>
</if> </select>
<if test="record.createTime != null"> <update id="updateByExampleSelective" parameterType="map">
create_time = #{record.createTime,jdbcType=BIGINT}, update mock_expect_config
</if> <set>
<if test="record.updateTime != null"> <if test="record.id != null">
update_time = #{record.updateTime,jdbcType=BIGINT}, id = #{record.id,jdbcType=VARCHAR},
</if> </if>
<if test="record.createUserId != null"> <if test="record.mockConfigId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if>
<if test="record.request != null">
request = #{record.request,jdbcType=LONGVARCHAR},
</if>
<if test="record.response != null">
response = #{record.response,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
update mock_expect_config
set id = #{record.id,jdbcType=VARCHAR},
mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR}, mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.tags != null">
tags = #{record.tags,jdbcType=VARCHAR}, tags = #{record.tags,jdbcType=VARCHAR},
</if>
<if test="record.status != null">
`STATUS` = #{record.status,jdbcType=VARCHAR}, `STATUS` = #{record.status,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR}, create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if>
<if test="record.expectNum != null">
expect_num = #{record.expectNum,jdbcType=VARCHAR},
</if>
<if test="record.request != null">
request = #{record.request,jdbcType=LONGVARCHAR}, request = #{record.request,jdbcType=LONGVARCHAR},
response = #{record.response,jdbcType=LONGVARCHAR} </if>
<if test="_parameter != null"> <if test="record.response != null">
<include refid="Update_By_Example_Where_Clause"/> response = #{record.response,jdbcType=LONGVARCHAR},
</if> </if>
</update> </set>
<update id="updateByExample" parameterType="map"> <if test="_parameter != null">
update mock_expect_config <include refid="Update_By_Example_Where_Clause" />
set id = #{record.id,jdbcType=VARCHAR}, </if>
mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR}, </update>
`name` = #{record.name,jdbcType=VARCHAR}, <update id="updateByExampleWithBLOBs" parameterType="map">
tags = #{record.tags,jdbcType=VARCHAR}, update mock_expect_config
`STATUS` = #{record.status,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT}, mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=BIGINT}, `name` = #{record.name,jdbcType=VARCHAR},
create_user_id = #{record.createUserId,jdbcType=VARCHAR} tags = #{record.tags,jdbcType=VARCHAR},
<if test="_parameter != null"> `STATUS` = #{record.status,jdbcType=VARCHAR},
<include refid="Update_By_Example_Where_Clause"/> create_time = #{record.createTime,jdbcType=BIGINT},
</if> update_time = #{record.updateTime,jdbcType=BIGINT},
</update> create_user_id = #{record.createUserId,jdbcType=VARCHAR},
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> expect_num = #{record.expectNum,jdbcType=VARCHAR},
update mock_expect_config request = #{record.request,jdbcType=LONGVARCHAR},
<set> response = #{record.response,jdbcType=LONGVARCHAR}
<if test="mockConfigId != null"> <if test="_parameter != null">
mock_config_id = #{mockConfigId,jdbcType=VARCHAR}, <include refid="Update_By_Example_Where_Clause" />
</if> </if>
<if test="name != null"> </update>
`name` = #{name,jdbcType=VARCHAR}, <update id="updateByExample" parameterType="map">
</if> update mock_expect_config
<if test="tags != null"> set id = #{record.id,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR}, mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR},
</if> `name` = #{record.name,jdbcType=VARCHAR},
<if test="status != null"> tags = #{record.tags,jdbcType=VARCHAR},
`STATUS` = #{status,jdbcType=VARCHAR}, `STATUS` = #{record.status,jdbcType=VARCHAR},
</if> create_time = #{record.createTime,jdbcType=BIGINT},
<if test="createTime != null"> update_time = #{record.updateTime,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=BIGINT}, create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if> expect_num = #{record.expectNum,jdbcType=VARCHAR}
<if test="updateTime != null"> <if test="_parameter != null">
update_time = #{updateTime,jdbcType=BIGINT}, <include refid="Update_By_Example_Where_Clause" />
</if> </if>
<if test="createUserId != null"> </update>
create_user_id = #{createUserId,jdbcType=VARCHAR}, <update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
</if> update mock_expect_config
<if test="request != null"> <set>
request = #{request,jdbcType=LONGVARCHAR}, <if test="mockConfigId != null">
</if> mock_config_id = #{mockConfigId,jdbcType=VARCHAR},
<if test="response != null"> </if>
response = #{response,jdbcType=LONGVARCHAR}, <if test="name != null">
</if> `name` = #{name,jdbcType=VARCHAR},
</set> </if>
where id = #{id,jdbcType=VARCHAR} <if test="tags != null">
</update> tags = #{tags,jdbcType=VARCHAR},
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> </if>
update mock_expect_config <if test="status != null">
set mock_config_id = #{mockConfigId,jdbcType=VARCHAR}, `STATUS` = #{status,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR}, </if>
tags = #{tags,jdbcType=VARCHAR}, <if test="createTime != null">
`STATUS` = #{status,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=BIGINT}, </if>
update_time = #{updateTime,jdbcType=BIGINT}, <if test="updateTime != null">
create_user_id = #{createUserId,jdbcType=VARCHAR}, update_time = #{updateTime,jdbcType=BIGINT},
request = #{request,jdbcType=LONGVARCHAR}, </if>
response = #{response,jdbcType=LONGVARCHAR} <if test="createUserId != null">
where id = #{id,jdbcType=VARCHAR} create_user_id = #{createUserId,jdbcType=VARCHAR},
</update> </if>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.MockExpectConfig"> <if test="expectNum != null">
update mock_expect_config expect_num = #{expectNum,jdbcType=VARCHAR},
set mock_config_id = #{mockConfigId,jdbcType=VARCHAR}, </if>
`name` = #{name,jdbcType=VARCHAR}, <if test="request != null">
tags = #{tags,jdbcType=VARCHAR}, request = #{request,jdbcType=LONGVARCHAR},
`STATUS` = #{status,jdbcType=VARCHAR}, </if>
create_time = #{createTime,jdbcType=BIGINT}, <if test="response != null">
update_time = #{updateTime,jdbcType=BIGINT}, response = #{response,jdbcType=LONGVARCHAR},
create_user_id = #{createUserId,jdbcType=VARCHAR} </if>
where id = #{id,jdbcType=VARCHAR} </set>
</update> where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
update mock_expect_config
set mock_config_id = #{mockConfigId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR},
`STATUS` = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR},
expect_num = #{expectNum,jdbcType=VARCHAR},
request = #{request,jdbcType=LONGVARCHAR},
response = #{response,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.MockExpectConfig">
update mock_expect_config
set mock_config_id = #{mockConfigId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR},
`STATUS` = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR},
expect_num = #{expectNum,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper> </mapper>

View File

@ -12,4 +12,8 @@ public interface ExtMockExpectConfigMapper {
List<MockExpectConfigWithBLOBs> selectByApiId(String apiId); List<MockExpectConfigWithBLOBs> selectByApiId(String apiId);
List<MockExpectConfigWithBLOBs> selectByApiIdIn(@Param("values") List<String> apiIds); List<MockExpectConfigWithBLOBs> selectByApiIdIn(@Param("values") List<String> apiIds);
List<String> selectExlectNumByMockConfigId(String mockConfigId);
String selectApiNumberByMockConfigId(String mockConfigId);
} }

View File

@ -21,4 +21,14 @@
</foreach> </foreach>
) )
</select> </select>
<select id="selectExlectNumByMockConfigId" resultType="java.lang.String">
SELECT expect_num FROM mock_expect_config WHERE mock_config_id = #{0}
</select>
<select id="selectApiNumberByMockConfigId" resultType="java.lang.String">
SELECT num FROM api_definition WHERE id IN (
select api_id from mock_config WHERE id = #{0}
)
</select>
</mapper> </mapper>

View File

@ -5,6 +5,7 @@ import io.metersphere.api.jmeter.NewDriverManager;
import io.metersphere.api.service.ApiAutomationService; import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.api.service.ApiDefinitionService; import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.api.service.MockConfigService;
import io.metersphere.base.domain.JarConfig; import io.metersphere.base.domain.JarConfig;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.RunInterface; import io.metersphere.commons.utils.RunInterface;
@ -63,6 +64,8 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
private ApiDefinitionService apiDefinitionService; private ApiDefinitionService apiDefinitionService;
@Resource @Resource
private TestReviewTestCaseService testReviewTestCaseService; private TestReviewTestCaseService testReviewTestCaseService;
@Resource
private MockConfigService mockConfigService;
@Value("${jmeter.home}") @Value("${jmeter.home}")
private String jmeterHome; private String jmeterHome;
@ -132,7 +135,7 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
initOnceOperate(testPlanLoadCaseService::initOrderField, "init.sort.plan.api.load"); initOnceOperate(testPlanLoadCaseService::initOrderField, "init.sort.plan.api.load");
initOnceOperate(testReviewTestCaseService::initOrderField, "init.sort.review.test.case"); initOnceOperate(testReviewTestCaseService::initOrderField, "init.sort.review.test.case");
initOnceOperate(apiDefinitionService::initDefaultModuleId, "init.default.module.id"); initOnceOperate(apiDefinitionService::initDefaultModuleId, "init.default.module.id");
initOnceOperate(mockConfigService::initExpectNum,"init.mock.expectNum");
} }
/** /**

View File

@ -21,6 +21,12 @@
ref="table" ref="table"
> >
<ms-table-column
prop="expectNum"
:label="$t('commons.id')"
min-width="120px">
</ms-table-column>
<ms-table-column <ms-table-column
prop="name" prop="name"
:label="$t('api_test.mock.table.name')" :label="$t('api_test.mock.table.name')"