fix(接口测试): 修改导入接口对ref的检查

--user=郭雨琦
This commit is contained in:
guoyuqi 2022-07-04 15:55:02 +08:00 committed by xiaomeinvG
parent 2888fb2775
commit 08f768ab01
4 changed files with 62 additions and 52 deletions

View File

@ -1335,6 +1335,10 @@ public class ApiDefinitionService {
MSException.throwException(Translator.get("connection_timeout")); MSException.throwException(Translator.get("connection_timeout"));
} }
} }
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
if (StringUtils.equals(request.getType(), "schedule")) {
request.setProtocol("HTTP");
}
try { try {
apiImport = (ApiDefinitionImport) Objects.requireNonNull(runService).parse(file == null ? null : file.getInputStream(), request); apiImport = (ApiDefinitionImport) Objects.requireNonNull(runService).parse(file == null ? null : file.getInputStream(), request);
if (apiImport.getMocks() == null) { if (apiImport.getMocks() == null) {
@ -1356,7 +1360,7 @@ public class ApiDefinitionService {
paramMap.put("url", request.getSwaggerUrl()); paramMap.put("url", request.getSwaggerUrl());
paramMap.put("projectId", request.getProjectId()); paramMap.put("projectId", request.getProjectId());
NoticeModel noticeModel = NoticeModel.builder() NoticeModel noticeModel = NoticeModel.builder()
.operator(SessionUtils.getUserId()) .operator(project.getCreateUser())
.context(context) .context(context)
.testId(scheduleId) .testId(scheduleId)
.subject(Translator.get("swagger_url_scheduled_import_notification")) .subject(Translator.get("swagger_url_scheduled_import_notification"))
@ -1381,7 +1385,7 @@ public class ApiDefinitionService {
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
paramMap.put("url", request.getSwaggerUrl()); paramMap.put("url", request.getSwaggerUrl());
NoticeModel noticeModel = NoticeModel.builder() NoticeModel noticeModel = NoticeModel.builder()
.operator(SessionUtils.getUserId()) .operator(project.getCreateUser())
.context(context) .context(context)
.testId(scheduleId) .testId(scheduleId)
.subject(Translator.get("swagger_url_scheduled_import_notification")) .subject(Translator.get("swagger_url_scheduled_import_notification"))

View File

@ -1018,7 +1018,7 @@
<update id="clearLatestVersion"> <update id="clearLatestVersion">
UPDATE api_definition UPDATE api_definition
SET latest = 0 SET latest = 0
and ref_id = #{refId} where ref_id = #{refId}
</update> </update>
<update id="addLatestVersion"> <update id="addLatestVersion">

View File

@ -109,9 +109,10 @@
parameterType="io.metersphere.performance.request.QueryTestPlanRequest"> parameterType="io.metersphere.performance.request.QueryTestPlanRequest">
SELECT load_test.*, project.name AS project_name, user.name AS user_name, project_version.name as version_name SELECT load_test.*, project.name AS project_name, user.name AS user_name, project_version.name as version_name
FROM load_test FROM load_test
LEFT JOIN project ON load_test.project_id = project.id LEFT JOIN project ON load_test.project_id = project.id
LEFT JOIN user ON load_test.user_id = user.id LEFT JOIN user ON load_test.user_id = user.id
LEFT JOIN project_version on project.id = project_version.project_id AND project_version.id = load_test.version_id LEFT JOIN project_version on project.id = project_version.project_id AND project_version.id =
load_test.version_id
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
<include refid="combine"> <include refid="combine">
@ -197,7 +198,7 @@
<select id="checkLoadTestOwner" resultType="int"> <select id="checkLoadTestOwner" resultType="int">
SELECT COUNT(1) SELECT COUNT(1)
FROM load_test FROM load_test
LEFT JOIN project ON load_test.project_id = project.id LEFT JOIN project ON load_test.project_id = project.id
<where> <where>
<if test="testId != null"> <if test="testId != null">
and load_test.id = #{testId} and load_test.id = #{testId}
@ -211,7 +212,10 @@
</where> </where>
</select> </select>
<select id="getNextNum" resultType="io.metersphere.base.domain.LoadTest"> <select id="getNextNum" resultType="io.metersphere.base.domain.LoadTest">
select * from load_test lt where lt.project_id = #{projectId} ORDER BY num DESC LIMIT 1; select *
from load_test lt
where lt.project_id = #{projectId}
ORDER BY num DESC LIMIT 1;
</select> </select>
<select id="moduleCount" resultType="java.lang.Integer"> <select id="moduleCount" resultType="java.lang.Integer">
@ -277,7 +281,7 @@
</foreach> </foreach>
</if> </if>
</sql> </sql>
<sql id="queryWhereCondition"> <sql id="queryWhereCondition">
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
@ -322,7 +326,6 @@
</sql> </sql>
<select id="getProjectFiles" resultType="io.metersphere.base.domain.FileMetadata"> <select id="getProjectFiles" resultType="io.metersphere.base.domain.FileMetadata">
SELECT file_metadata.* SELECT file_metadata.*
FROM file_metadata FROM file_metadata
@ -338,10 +341,14 @@
</select> </select>
<select id="selectProjectIds" resultType="java.lang.String"> <select id="selectProjectIds" resultType="java.lang.String">
select DISTINCT project_id from load_test; select DISTINCT project_id
from load_test;
</select> </select>
<select id="getIdsOrderByUpdateTime" resultType="java.lang.String"> <select id="getIdsOrderByUpdateTime" resultType="java.lang.String">
select id from load_test where project_id = #{projectId} order by update_time ASC; select id
from load_test
where project_id = #{projectId}
order by update_time ASC;
</select> </select>
<select id="getLastOrder" resultType="java.lang.Long"> <select id="getLastOrder" resultType="java.lang.Long">
@ -374,62 +381,61 @@
<update id="addLatestVersion"> <update id="addLatestVersion">
UPDATE load_test UPDATE load_test
INNER JOIN (( INNER JOIN ((
SELECT tmp.id SELECT tmp.id
FROM load_test tmp FROM load_test tmp
JOIN project_version JOIN project_version
ON tmp.project_id = project_version.project_id AND ON tmp.project_id = project_version.project_id AND
tmp.version_id = project_version.id AND project_version.latest = TRUE tmp.version_id = project_version.id AND project_version.latest = TRUE
WHERE ref_id = #{refId,jdbcType=VARCHAR} WHERE ref_id = #{refId,jdbcType=VARCHAR}
LIMIT 1 LIMIT 1
) )
UNION ALL UNION ALL
( (
SELECT tmp.id SELECT tmp.id
FROM load_test tmp FROM load_test tmp
JOIN project_version JOIN project_version
ON tmp.project_id = project_version.project_id AND ON tmp.project_id = project_version.project_id AND
tmp.version_id = project_version.id tmp.version_id = project_version.id
AND NOT EXISTS(SELECT ref_id AND NOT EXISTS (SELECT ref_id
FROM load_test tmp2 FROM load_test tmp2
JOIN project_version JOIN project_version
ON tmp2.project_id = ON tmp2.project_id =
project_version.project_id AND project_version.project_id AND
version_id = version_id =
project_version.id AND project_version.id AND
project_version.latest = TRUE project_version.latest = TRUE
WHERE tmp.ref_id = tmp2.ref_id) WHERE tmp.ref_id = tmp2.ref_id)
WHERE tmp.ref_id = #{refId,jdbcType=VARCHAR} WHERE tmp.ref_id = #{refId,jdbcType=VARCHAR}
ORDER BY tmp.update_time DESC ORDER BY tmp.update_time DESC
LIMIT 1)) AS t ON load_test.id = t.id LIMIT 1)) AS t
SET load_test.latest = TRUE ON load_test.id = t.id
SET load_test.latest = TRUE
WHERE ref_id = #{refId,jdbcType=VARCHAR} WHERE ref_id = #{refId,jdbcType=VARCHAR}
</update> </update>
<update id="clearLatestVersion"> <update id="clearLatestVersion">
UPDATE load_test UPDATE load_test
SET latest = 0 SET latest = 0
<where> where ref_id = #{refId}
<if test="refId != null">
and ref_id = #{refId}
</if>
</where>
</update> </update>
<select id="selectRefIdsForVersionChange" resultType="java.lang.String"> <select id="selectRefIdsForVersionChange" resultType="java.lang.String">
SELECT DISTINCT ref_id SELECT DISTINCT ref_id
FROM load_test FROM load_test
WHERE ref_id NOT IN ( WHERE ref_id NOT IN (
SELECT DISTINCT ref_id SELECT DISTINCT ref_id
FROM load_test FROM load_test
WHERE version_id = #{versionId} AND project_id = #{projectId} WHERE version_id = #{versionId}
) AND project_id = #{projectId} AND project_id = #{projectId}
)
AND project_id = #{projectId}
</select> </select>
<select id="getFileMetadataByIds" resultType="io.metersphere.base.domain.FileMetadata"> <select id="getFileMetadataByIds" resultType="io.metersphere.base.domain.FileMetadata">
SELECT file_metadata.* SELECT file_metadata.*
FROM load_test_file FROM load_test_file
JOIN file_metadata ON file_id = file_metadata.id JOIN file_metadata ON file_id = file_metadata.id
WHERE test_id = #{testId} WHERE test_id = #{testId}
ORDER BY sort ORDER BY sort
</select> </select>

View File

@ -12,7 +12,7 @@
sup.config, sup.config,
sch.value as rule, sch.value as rule,
sch.enable, sch.enable,
sch.id as taskId sch.id as taskId
FROM swagger_url_project sup FROM swagger_url_project sup
INNER JOIN schedule sch ON sup.id = sch.resource_id INNER JOIN schedule sch ON sup.id = sch.resource_id
WHERE sup.project_id = #{projectId} WHERE sup.project_id = #{projectId}