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

@ -2,19 +2,19 @@
<!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" />
<result column="expect_num" jdbcType="VARCHAR" property="expectNum" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
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>
@ -34,8 +34,7 @@
</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>
@ -64,8 +63,7 @@
</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>
@ -77,38 +75,37 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, mock_config_id, `name`, tags, `STATUS`, create_time, update_time, create_user_id id, mock_config_id, `name`, tags, `STATUS`, create_time, update_time, create_user_id,
expect_num
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
request, response request, response
</sql> </sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigExample" <select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigExample" resultMap="ResultMapWithBLOBs">
resultMap="ResultMapWithBLOBs">
select select
<if test="distinct"> <if test="distinct">
distinct distinct
</if> </if>
<include refid="Base_Column_List"/> <include refid="Base_Column_List" />
, ,
<include refid="Blob_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="selectByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" <select id="selectByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" resultMap="BaseResultMap">
resultMap="BaseResultMap">
select select
<if test="distinct"> <if test="distinct">
distinct distinct
</if> </if>
<include refid="Base_Column_List"/> <include refid="Base_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}
@ -116,32 +113,31 @@
</select> </select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs"> <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List" />
, ,
<include refid="Blob_Column_List"/> <include refid="Blob_Column_List" />
from mock_expect_config from mock_expect_config
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete delete from mock_expect_config
from mock_expect_config
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</delete> </delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample"> <delete id="deleteByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample">
delete from mock_expect_config delete from mock_expect_config
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause" />
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> <insert id="insert" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
insert into mock_expect_config (id, mock_config_id, `name`, insert into mock_expect_config (id, mock_config_id, `name`,
tags, `STATUS`, create_time, tags, `STATUS`, create_time,
update_time, create_user_id, request, update_time, create_user_id, expect_num,
response) request, response)
values (#{id,jdbcType=VARCHAR}, #{mockConfigId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{mockConfigId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, #{request,jdbcType=LONGVARCHAR}, #{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, #{expectNum,jdbcType=VARCHAR},
#{response,jdbcType=LONGVARCHAR}) #{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
insert into mock_expect_config insert into mock_expect_config
@ -170,6 +166,9 @@
<if test="createUserId != null"> <if test="createUserId != null">
create_user_id, create_user_id,
</if> </if>
<if test="expectNum != null">
expect_num,
</if>
<if test="request != null"> <if test="request != null">
request, request,
</if> </if>
@ -202,6 +201,9 @@
<if test="createUserId != null"> <if test="createUserId != null">
#{createUserId,jdbcType=VARCHAR}, #{createUserId,jdbcType=VARCHAR},
</if> </if>
<if test="expectNum != null">
#{expectNum,jdbcType=VARCHAR},
</if>
<if test="request != null"> <if test="request != null">
#{request,jdbcType=LONGVARCHAR}, #{request,jdbcType=LONGVARCHAR},
</if> </if>
@ -210,11 +212,10 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" <select id="countByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample" resultType="java.lang.Long">
resultType="java.lang.Long">
select count(*) from mock_expect_config select count(*) from mock_expect_config
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause" />
</if> </if>
</select> </select>
<update id="updateByExampleSelective" parameterType="map"> <update id="updateByExampleSelective" parameterType="map">
@ -244,6 +245,9 @@
<if test="record.createUserId != null"> <if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR}, create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if> </if>
<if test="record.expectNum != null">
expect_num = #{record.expectNum,jdbcType=VARCHAR},
</if>
<if test="record.request != null"> <if test="record.request != null">
request = #{record.request,jdbcType=LONGVARCHAR}, request = #{record.request,jdbcType=LONGVARCHAR},
</if> </if>
@ -252,7 +256,7 @@
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByExampleWithBLOBs" parameterType="map"> <update id="updateByExampleWithBLOBs" parameterType="map">
@ -265,10 +269,11 @@
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
create_user_id = #{record.createUserId,jdbcType=VARCHAR}, create_user_id = #{record.createUserId,jdbcType=VARCHAR},
expect_num = #{record.expectNum,jdbcType=VARCHAR},
request = #{record.request,jdbcType=LONGVARCHAR}, request = #{record.request,jdbcType=LONGVARCHAR},
response = #{record.response,jdbcType=LONGVARCHAR} response = #{record.response,jdbcType=LONGVARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
@ -280,9 +285,10 @@
`STATUS` = #{record.status,jdbcType=VARCHAR}, `STATUS` = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
create_user_id = #{record.createUserId,jdbcType=VARCHAR} create_user_id = #{record.createUserId,jdbcType=VARCHAR},
expect_num = #{record.expectNum,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs"> <update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
@ -309,6 +315,9 @@
<if test="createUserId != null"> <if test="createUserId != null">
create_user_id = #{createUserId,jdbcType=VARCHAR}, create_user_id = #{createUserId,jdbcType=VARCHAR},
</if> </if>
<if test="expectNum != null">
expect_num = #{expectNum,jdbcType=VARCHAR},
</if>
<if test="request != null"> <if test="request != null">
request = #{request,jdbcType=LONGVARCHAR}, request = #{request,jdbcType=LONGVARCHAR},
</if> </if>
@ -327,6 +336,7 @@
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR}, create_user_id = #{createUserId,jdbcType=VARCHAR},
expect_num = #{expectNum,jdbcType=VARCHAR},
request = #{request,jdbcType=LONGVARCHAR}, request = #{request,jdbcType=LONGVARCHAR},
response = #{response,jdbcType=LONGVARCHAR} response = #{response,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
@ -339,7 +349,8 @@
`STATUS` = #{status,jdbcType=VARCHAR}, `STATUS` = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR} create_user_id = #{createUserId,jdbcType=VARCHAR},
expect_num = #{expectNum,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </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')"