feat(接口自动化): 增加URL唯一性校验开关,控制URL校验规则

This commit is contained in:
fit2-zhao 2021-01-06 13:38:17 +08:00
parent e975dcbc18
commit 09fd2c2ab6
13 changed files with 301 additions and 208 deletions

View File

@ -316,9 +316,12 @@ public class ApiAutomationService {
boolean isFirst = true;
for (ApiScenarioWithBLOBs item : apiScenarios) {
if (item.getStepTotal() == 0) {
if (apiScenarios.size() == 1) {
MSException.throwException(item.getName() + "" + Translator.get("automation_exec_info"));
break;
}
continue;
}
MsThreadGroup group = new MsThreadGroup();
group.setLabel(item.getName());
group.setName(UUID.randomUUID().toString());

View File

@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.api.dto.ApiTestImportRequest;
import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.automation.ReferenceDTO;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
@ -18,6 +17,7 @@ import io.metersphere.api.parse.ApiImportParserFactory;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiDefinitionMapper;
import io.metersphere.base.mapper.ApiTestFileMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper;
import io.metersphere.base.mapper.ext.ExtApiScenarioMapper;
@ -71,6 +71,8 @@ public class ApiDefinitionService {
private ExtApiScenarioMapper extApiScenarioMapper;
@Resource
private ExtTestPlanMapper extTestPlanMapper;
@Resource
private ProjectMapper projectMapper;
private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24);
@ -168,7 +170,8 @@ public class ApiDefinitionService {
example.createCriteria().andMethodEqualTo(request.getMethod()).andStatusNotEqualTo("Trash")
.andProtocolEqualTo(request.getProtocol()).andPathEqualTo(request.getPath())
.andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
if (apiDefinitionMapper.countByExample(example) > 0) {
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
if (apiDefinitionMapper.countByExample(example) > 0 && !project.getRepeatable()) {
MSException.throwException(Translator.get("api_definition_url_not_repeating"));
}
} else {

View File

@ -1,8 +1,9 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import java.io.Serializable;
@Data
public class Project implements Serializable {
private String id;
@ -23,5 +24,7 @@ public class Project implements Serializable {
private String zentaoId;
private Boolean repeatable;
private static final long serialVersionUID = 1L;
}

View File

@ -713,6 +713,66 @@ public class ProjectExample {
addCriterion("zentao_id not between", value1, value2, "zentaoId");
return (Criteria) this;
}
public Criteria andRepeatableIsNull() {
addCriterion("`repeatable` is null");
return (Criteria) this;
}
public Criteria andRepeatableIsNotNull() {
addCriterion("`repeatable` is not null");
return (Criteria) this;
}
public Criteria andRepeatableEqualTo(Boolean value) {
addCriterion("`repeatable` =", value, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableNotEqualTo(Boolean value) {
addCriterion("`repeatable` <>", value, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableGreaterThan(Boolean value) {
addCriterion("`repeatable` >", value, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableGreaterThanOrEqualTo(Boolean value) {
addCriterion("`repeatable` >=", value, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableLessThan(Boolean value) {
addCriterion("`repeatable` <", value, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableLessThanOrEqualTo(Boolean value) {
addCriterion("`repeatable` <=", value, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableIn(List<Boolean> values) {
addCriterion("`repeatable` in", values, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableNotIn(List<Boolean> values) {
addCriterion("`repeatable` not in", values, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableBetween(Boolean value1, Boolean value2) {
addCriterion("`repeatable` between", value1, value2, "repeatable");
return (Criteria) this;
}
public Criteria andRepeatableNotBetween(Boolean value1, Boolean value2) {
addCriterion("`repeatable` not between", value1, value2, "repeatable");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -11,6 +11,7 @@
<result column="tapd_id" jdbcType="VARCHAR" property="tapdId" />
<result column="jira_key" jdbcType="VARCHAR" property="jiraKey" />
<result column="zentao_id" jdbcType="VARCHAR" property="zentaoId" />
<result column="repeatable" jdbcType="BIT" property="repeatable" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -72,7 +73,7 @@
</sql>
<sql id="Base_Column_List">
id, workspace_id, `name`, description, create_time, update_time, tapd_id, jira_key,
zentao_id
zentao_id, `repeatable`
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.ProjectExample" resultMap="BaseResultMap">
select
@ -107,12 +108,12 @@
<insert id="insert" parameterType="io.metersphere.base.domain.Project">
insert into project (id, workspace_id, `name`,
description, create_time, update_time,
tapd_id, jira_key, zentao_id
)
tapd_id, jira_key, zentao_id,
`repeatable`)
values (#{id,jdbcType=VARCHAR}, #{workspaceId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{tapdId,jdbcType=VARCHAR}, #{jiraKey,jdbcType=VARCHAR}, #{zentaoId,jdbcType=VARCHAR}
)
#{tapdId,jdbcType=VARCHAR}, #{jiraKey,jdbcType=VARCHAR}, #{zentaoId,jdbcType=VARCHAR},
#{repeatable,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.Project">
insert into project
@ -144,6 +145,9 @@
<if test="zentaoId != null">
zentao_id,
</if>
<if test="repeatable != null">
`repeatable`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -173,6 +177,9 @@
<if test="zentaoId != null">
#{zentaoId,jdbcType=VARCHAR},
</if>
<if test="repeatable != null">
#{repeatable,jdbcType=BIT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.ProjectExample" resultType="java.lang.Long">
@ -211,6 +218,9 @@
<if test="record.zentaoId != null">
zentao_id = #{record.zentaoId,jdbcType=VARCHAR},
</if>
<if test="record.repeatable != null">
`repeatable` = #{record.repeatable,jdbcType=BIT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -226,7 +236,8 @@
update_time = #{record.updateTime,jdbcType=BIGINT},
tapd_id = #{record.tapdId,jdbcType=VARCHAR},
jira_key = #{record.jiraKey,jdbcType=VARCHAR},
zentao_id = #{record.zentaoId,jdbcType=VARCHAR}
zentao_id = #{record.zentaoId,jdbcType=VARCHAR},
`repeatable` = #{record.repeatable,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -258,6 +269,9 @@
<if test="zentaoId != null">
zentao_id = #{zentaoId,jdbcType=VARCHAR},
</if>
<if test="repeatable != null">
`repeatable` = #{repeatable,jdbcType=BIT},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -270,7 +284,8 @@
update_time = #{updateTime,jdbcType=BIGINT},
tapd_id = #{tapdId,jdbcType=VARCHAR},
jira_key = #{jiraKey,jdbcType=VARCHAR},
zentao_id = #{zentaoId,jdbcType=VARCHAR}
zentao_id = #{zentaoId,jdbcType=VARCHAR},
`repeatable` = #{repeatable,jdbcType=BIT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -4,7 +4,7 @@
<select id="getProjectWithWorkspace" resultType="io.metersphere.dto.ProjectDTO">
select p.id, p.workspace_id, p.name, p.description, p.update_time,
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key, p.zentao_id
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key, p.zentao_id,p.repeatable
from project p
join workspace w on p.workspace_id = w.id
<where>

View File

@ -17,4 +17,6 @@ public class ProjectDTO {
private String tapdId;
private String jiraKey;
private String zentaoId;
private boolean repeatable;
}

View File

@ -0,0 +1 @@
ALTER TABLE project ADD repeatable tinyint(1) DEFAULT null;

View File

@ -64,7 +64,7 @@
<!--要生成的数据库表 -->
<table tableName="api_scenario"/>
<table tableName="project"/>
<!--<table tableName="test_plan_api_scenario"/>-->
<!--<table tableName="test_plan"/>-->
<!--<table tableName="api_scenario_report"/>-->

View File

@ -48,7 +48,7 @@
</el-card>
<el-dialog :close-on-click-modal="false" :title="title" :visible.sync="createVisible" destroy-on-close @close="handleClose">
<el-form :model="form" :rules="rules" ref="form" label-position="right" label-width="100px" size="small">
<el-form :model="form" :rules="rules" ref="form" label-position="right" label-width="140px" size="small">
<el-form-item :label="$t('commons.name')" prop="name">
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
@ -64,6 +64,9 @@
<el-form-item :label="$t('project.zentao_id')" v-if="zentao">
<el-input v-model="form.zentaoId" autocomplete="off"></el-input>
</el-form-item>
<el-form-item :label="$t('project.repeatable')" prop="repeatable">
<el-switch v-model="form.repeatable"></el-switch>
</el-form-item>
</el-form>
<template v-slot:footer>
<div class="dialog-footer">

View File

@ -308,7 +308,8 @@ export default {
zentao_id: 'Zentao Project ID',
manager: 'Manager',
no_data: 'No Data',
select: 'Select'
select: 'Select',
repeatable: 'Interface definition URL repeatable'
},
member: {
create: 'Create',

View File

@ -305,7 +305,8 @@ export default {
zentao_id: 'Zentao项目ID',
manager: '项目管理',
no_data: '无数据',
select: '选择项目'
select: '选择项目',
repeatable: '接口定义URL可重复'
},
member: {
create: '添加成员',

View File

@ -305,7 +305,8 @@ export default {
zentao_id: 'Zentao項目ID',
manager: '項目管理',
no_data: '無數據',
select: '選擇項目'
select: '選擇項目',
repeatable: '接口定义URL可重复'
},
member: {
create: '添加成員',