refactor(功能用例): 删除模块

This commit is contained in:
guoyuqi 2023-11-02 14:38:53 +08:00 committed by Craftsman
parent 8630778df6
commit 7c2c196a2f
11 changed files with 81 additions and 162 deletions

View File

@ -34,10 +34,6 @@ public class FunctionalCaseModule implements Serializable {
@NotNull(message = "{functional_case_module.pos.not_blank}", groups = {Created.class}) @NotNull(message = "{functional_case_module.pos.not_blank}", groups = {Created.class})
private Long pos; private Long pos;
@Schema(description = "是否在回收站0-否1-是", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "{functional_case_module.deleted.not_blank}", groups = {Created.class})
private Boolean deleted;
@Schema(description = "创建时间") @Schema(description = "创建时间")
private Long createTime; private Long createTime;
@ -58,7 +54,6 @@ public class FunctionalCaseModule implements Serializable {
name("name", "name", "VARCHAR", true), name("name", "name", "VARCHAR", true),
parentId("parent_id", "parentId", "VARCHAR", false), parentId("parent_id", "parentId", "VARCHAR", false),
pos("pos", "pos", "BIGINT", false), pos("pos", "pos", "BIGINT", false),
deleted("deleted", "deleted", "BIT", false),
createTime("create_time", "createTime", "BIGINT", false), createTime("create_time", "createTime", "BIGINT", false),
updateTime("update_time", "updateTime", "BIGINT", false), updateTime("update_time", "updateTime", "BIGINT", false),
createUser("create_user", "createUser", "VARCHAR", false), createUser("create_user", "createUser", "VARCHAR", false),

View File

@ -444,66 +444,6 @@ public class FunctionalCaseModuleExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andDeletedIsNull() {
addCriterion("deleted is null");
return (Criteria) this;
}
public Criteria andDeletedIsNotNull() {
addCriterion("deleted is not null");
return (Criteria) this;
}
public Criteria andDeletedEqualTo(Boolean value) {
addCriterion("deleted =", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotEqualTo(Boolean value) {
addCriterion("deleted <>", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedGreaterThan(Boolean value) {
addCriterion("deleted >", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedGreaterThanOrEqualTo(Boolean value) {
addCriterion("deleted >=", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedLessThan(Boolean value) {
addCriterion("deleted <", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedLessThanOrEqualTo(Boolean value) {
addCriterion("deleted <=", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedIn(List<Boolean> values) {
addCriterion("deleted in", values, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotIn(List<Boolean> values) {
addCriterion("deleted not in", values, "deleted");
return (Criteria) this;
}
public Criteria andDeletedBetween(Boolean value1, Boolean value2) {
addCriterion("deleted between", value1, value2, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotBetween(Boolean value1, Boolean value2) {
addCriterion("deleted not between", value1, value2, "deleted");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() { public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null"); addCriterion("create_time is null");
return (Criteria) this; return (Criteria) this;

View File

@ -7,7 +7,6 @@
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="parent_id" jdbcType="VARCHAR" property="parentId" /> <result column="parent_id" jdbcType="VARCHAR" property="parentId" />
<result column="pos" jdbcType="BIGINT" property="pos" /> <result column="pos" jdbcType="BIGINT" property="pos" />
<result column="deleted" jdbcType="BIT" property="deleted" />
<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" jdbcType="VARCHAR" property="createUser" /> <result column="create_user" jdbcType="VARCHAR" property="createUser" />
@ -72,8 +71,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, project_id, `name`, parent_id, pos, deleted, create_time, update_time, create_user, id, project_id, `name`, parent_id, pos, create_time, update_time, create_user, update_user
update_user
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.functional.domain.FunctionalCaseModuleExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.functional.domain.FunctionalCaseModuleExample" resultMap="BaseResultMap">
select select
@ -107,13 +105,13 @@
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.functional.domain.FunctionalCaseModule"> <insert id="insert" parameterType="io.metersphere.functional.domain.FunctionalCaseModule">
insert into functional_case_module (id, project_id, `name`, insert into functional_case_module (id, project_id, `name`,
parent_id, pos, deleted, parent_id, pos, create_time,
create_time, update_time, create_user, update_time, create_user, update_user
update_user) )
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{parentId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{deleted,jdbcType=BIT}, #{parentId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{updateUser,jdbcType=VARCHAR}
#{updateUser,jdbcType=VARCHAR}) )
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.functional.domain.FunctionalCaseModule"> <insert id="insertSelective" parameterType="io.metersphere.functional.domain.FunctionalCaseModule">
insert into functional_case_module insert into functional_case_module
@ -133,9 +131,6 @@
<if test="pos != null"> <if test="pos != null">
pos, pos,
</if> </if>
<if test="deleted != null">
deleted,
</if>
<if test="createTime != null"> <if test="createTime != null">
create_time, create_time,
</if> </if>
@ -165,9 +160,6 @@
<if test="pos != null"> <if test="pos != null">
#{pos,jdbcType=BIGINT}, #{pos,jdbcType=BIGINT},
</if> </if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
<if test="createTime != null"> <if test="createTime != null">
#{createTime,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
</if> </if>
@ -206,9 +198,6 @@
<if test="record.pos != null"> <if test="record.pos != null">
pos = #{record.pos,jdbcType=BIGINT}, pos = #{record.pos,jdbcType=BIGINT},
</if> </if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</if>
<if test="record.createTime != null"> <if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
</if> </if>
@ -233,7 +222,6 @@
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
parent_id = #{record.parentId,jdbcType=VARCHAR}, parent_id = #{record.parentId,jdbcType=VARCHAR},
pos = #{record.pos,jdbcType=BIGINT}, pos = #{record.pos,jdbcType=BIGINT},
deleted = #{record.deleted,jdbcType=BIT},
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 = #{record.createUser,jdbcType=VARCHAR}, create_user = #{record.createUser,jdbcType=VARCHAR},
@ -257,9 +245,6 @@
<if test="pos != null"> <if test="pos != null">
pos = #{pos,jdbcType=BIGINT}, pos = #{pos,jdbcType=BIGINT},
</if> </if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
<if test="createTime != null"> <if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
</if> </if>
@ -281,7 +266,6 @@
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=VARCHAR}, parent_id = #{parentId,jdbcType=VARCHAR},
pos = #{pos,jdbcType=BIGINT}, pos = #{pos,jdbcType=BIGINT},
deleted = #{deleted,jdbcType=BIT},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
create_user = #{createUser,jdbcType=VARCHAR}, create_user = #{createUser,jdbcType=VARCHAR},
@ -290,14 +274,14 @@
</update> </update>
<insert id="batchInsert" parameterType="map"> <insert id="batchInsert" parameterType="map">
insert into functional_case_module insert into functional_case_module
(id, project_id, `name`, parent_id, pos, deleted, create_time, update_time, create_user, (id, project_id, `name`, parent_id, pos, create_time, update_time, create_user, update_user
update_user) )
values values
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, (#{item.id,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
#{item.parentId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.deleted,jdbcType=BIT}, #{item.parentId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.createTime,jdbcType=BIGINT},
#{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.updateUser,jdbcType=VARCHAR}
#{item.updateUser,jdbcType=VARCHAR}) )
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertSelective" parameterType="map"> <insert id="batchInsertSelective" parameterType="map">
@ -325,9 +309,6 @@
<if test="'pos'.toString() == column.value"> <if test="'pos'.toString() == column.value">
#{item.pos,jdbcType=BIGINT} #{item.pos,jdbcType=BIGINT}
</if> </if>
<if test="'deleted'.toString() == column.value">
#{item.deleted,jdbcType=BIT}
</if>
<if test="'create_time'.toString() == column.value"> <if test="'create_time'.toString() == column.value">
#{item.createTime,jdbcType=BIGINT} #{item.createTime,jdbcType=BIGINT}
</if> </if>

View File

@ -78,15 +78,12 @@ CREATE INDEX idx_status ON functional_case_comment(status);
CREATE INDEX idx_type ON functional_case_comment(type); CREATE INDEX idx_type ON functional_case_comment(type);
CREATE INDEX idx_resource_id ON functional_case_comment(resource_id); CREATE INDEX idx_resource_id ON functional_case_comment(resource_id);
CREATE TABLE IF NOT EXISTS functional_case_module( CREATE TABLE IF NOT EXISTS functional_case_module(
`id` VARCHAR(50) NOT NULL COMMENT 'ID' , `id` VARCHAR(50) NOT NULL COMMENT 'ID' ,
`project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' , `project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' ,
`name` VARCHAR(100) NOT NULL COMMENT '名称' , `name` VARCHAR(100) NOT NULL COMMENT '名称' ,
`parent_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父节点ID' , `parent_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父节点ID' ,
`pos` BIGINT NOT NULL DEFAULT 0 COMMENT '同一节点下的顺序' , `pos` BIGINT NOT NULL DEFAULT 0 COMMENT '同一节点下的顺序' ,
`deleted` BIT NOT NULL DEFAULT 0 COMMENT '是否在回收站0-否1-是' ,
`create_time` BIGINT NOT NULL COMMENT '创建时间' , `create_time` BIGINT NOT NULL COMMENT '创建时间' ,
`update_time` BIGINT NOT NULL COMMENT '更新时间' , `update_time` BIGINT NOT NULL COMMENT '更新时间' ,
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人' , `create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
@ -103,7 +100,6 @@ CREATE INDEX idx_create_user ON functional_case_module(create_user);
CREATE INDEX idx_update_user ON functional_case_module(update_user); CREATE INDEX idx_update_user ON functional_case_module(update_user);
CREATE INDEX idx_create_time ON functional_case_module(create_time); CREATE INDEX idx_create_time ON functional_case_module(create_time);
CREATE INDEX idx_update_time ON functional_case_module(update_time); CREATE INDEX idx_update_time ON functional_case_module(update_time);
CREATE INDEX idx_delete ON functional_case_module(deleted);
CREATE TABLE IF NOT EXISTS functional_case_attachment( CREATE TABLE IF NOT EXISTS functional_case_attachment(

View File

@ -56,6 +56,6 @@ public class FunctionalCaseModuleController {
@Operation(summary = "用例管理-功能用例-模块-删除模块") @Operation(summary = "用例管理-功能用例-模块-删除模块")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE) @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_DELETE)
public void deleteNode(@PathVariable String moduleId) { public void deleteNode(@PathVariable String moduleId) {
functionalCaseModuleService.deleteModule(moduleId, SessionUtils.getUserId()); functionalCaseModuleService.deleteModule(moduleId);
} }
} }

View File

@ -21,4 +21,7 @@ public interface ExtFunctionalCaseMapper {
List<String> getFunctionalCaseIds(@Param("projectId") String projectId); List<String> getFunctionalCaseIds(@Param("projectId") String projectId);
void removeToTrashByModuleIds(@Param("moduleIds") List<String> deleteIds); void removeToTrashByModuleIds(@Param("moduleIds") List<String> deleteIds);
List<FunctionalCase> checkCaseByModuleIds(@Param("moduleIds") List<String> deleteIds);
} }

View File

@ -58,9 +58,23 @@
</select> </select>
<update id="removeToTrashByModuleIds" parameterType="java.lang.String"> <update id="removeToTrashByModuleIds" parameterType="java.lang.String">
UPDATE functional_case SET deleted = true WHERE module_id IN UPDATE functional_case SET deleted = true, module_id = 'root' WHERE module_id IN
<foreach collection="moduleIds" item="id" open="(" separator="," close=")"> <foreach collection="moduleIds" item="id" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
</update> </update>
<select id="checkCaseByModuleIds" resultType="io.metersphere.functional.domain.FunctionalCase">
SELECT
id, module_id
FROM
functional_case
WHERE
deleted = false
AND
module_id IN
<foreach collection="moduleIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper> </mapper>

View File

@ -8,14 +8,12 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
public interface ExtFunctionalCaseModuleMapper { public interface ExtFunctionalCaseModuleMapper {
List<BaseTreeNode> selectBaseByProjectId(String projectId); List<BaseTreeNode> selectBaseByProjectId(@Param("projectId")String projectId);
List<String> selectChildrenIdsByParentIds(@Param("ids") List<String> deleteIds); List<String> selectChildrenIdsByParentIds(@Param("ids") List<String> deleteIds);
List<String> selectChildrenIdsSortByPos(String parentId); List<String> selectChildrenIdsSortByPos(String parentId);
void removeToTrashByIds(@Param("ids") List<String> deleteIds);
Long getMaxPosByParentId(String parentId); Long getMaxPosByParentId(String parentId);
BaseModule selectBaseModuleById(String dragNodeId); BaseModule selectBaseModuleById(String dragNodeId);

View File

@ -4,14 +4,9 @@
<select id="selectBaseByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode"> <select id="selectBaseByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
SELECT id, name, parent_id AS parentId, 'module' AS type SELECT id, name, parent_id AS parentId, 'module' AS type
FROM functional_case_module FROM functional_case_module
WHERE project_id = #{0} WHERE project_id = #{projectId}
ORDER BY pos ORDER BY pos
</select> </select>
<select id="selectIdAndParentIdByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
SELECT id, parent_id AS parentId
FROM functional_case_module
WHERE project_id = #{0}
</select>
<select id="selectModuleByParentIdAndPosOperator" <select id="selectModuleByParentIdAndPosOperator"
parameterType="io.metersphere.project.dto.NodeSortQueryParam" parameterType="io.metersphere.project.dto.NodeSortQueryParam"
resultType="io.metersphere.system.dto.sdk.BaseModule"> resultType="io.metersphere.system.dto.sdk.BaseModule">
@ -30,60 +25,22 @@
</if> </if>
LIMIT 1 LIMIT 1
</select> </select>
<select id="selectIdsByProjectId" resultType="java.lang.String">
SELECT id
FROM functional_case_module
WHERE project_id = #{0}
</select>
<select id="selectChildrenIdsByParentIds" resultType="java.lang.String"> <select id="selectChildrenIdsByParentIds" resultType="java.lang.String">
SELECT id FROM functional_case_module WHERE parent_id IN SELECT id FROM functional_case_module WHERE parent_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
</select> </select>
<update id="removeToTrashByIds" parameterType="java.lang.String">
UPDATE functional_case_module SET deleted = true WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<select id="getMaxPosByParentId" resultType="java.lang.Long"> <select id="getMaxPosByParentId" resultType="java.lang.Long">
SELECT max(pos) FROM functional_case_module SELECT max(pos)
WHERE parent_id = #{0} FROM functional_case_module
WHERE parent_id = #{0}
</select> </select>
<select id="selectChildrenIdsSortByPos" resultType="java.lang.String"> <select id="selectChildrenIdsSortByPos" resultType="java.lang.String">
SELECT id FROM functional_case_module WHERE parent_id = #{0} SELECT id FROM functional_case_module WHERE parent_id = #{0}
ORDER BY pos ASC ORDER BY pos ASC
</select> </select>
<select id="getLastModuleByParentId" resultType="io.metersphere.functional.domain.FunctionalCaseModule">
SELECT *
FROM functional_case_module
WHERE parent_id = #{0}
ORDER BY pos DESC
LIMIT 1
</select>
<select id="getNextModuleInParentId" resultType="io.metersphere.functional.domain.FunctionalCaseModule">
SELECT *
from functional_case_module
WHERE parent_id = #{parentId}
AND pos &gt; #{pos}
order by pos asc
limit 1
</select>
<select id="getPreviousModuleInParentId" resultType="io.metersphere.functional.domain.FunctionalCaseModule">
SELECT *
from functional_case_module
WHERE parent_id = #{parentId}
AND pos &lt; #{pos}
order by pos
desc
limit 1
</select>
<select id="selectNameById" resultType="java.lang.String">
SELECT name
FROM functional_case_module
WHERE id = #{0}
</select>
<select id="selectBaseModuleById" resultType="io.metersphere.system.dto.sdk.BaseModule"> <select id="selectBaseModuleById" resultType="io.metersphere.system.dto.sdk.BaseModule">
SELECT id, name, pos, project_Id, parent_id SELECT id, name, pos, project_Id, parent_id
FROM functional_case_module FROM functional_case_module

View File

@ -60,7 +60,6 @@ public class FunctionalCaseModuleService extends ModuleTreeService {
functionalCaseModule.setParentId(request.getParentId()); functionalCaseModule.setParentId(request.getParentId());
functionalCaseModule.setProjectId(request.getProjectId()); functionalCaseModule.setProjectId(request.getProjectId());
this.checkDataValidity(functionalCaseModule); this.checkDataValidity(functionalCaseModule);
functionalCaseModule.setDeleted(false);
functionalCaseModule.setCreateTime(System.currentTimeMillis()); functionalCaseModule.setCreateTime(System.currentTimeMillis());
functionalCaseModule.setUpdateTime(functionalCaseModule.getCreateTime()); functionalCaseModule.setUpdateTime(functionalCaseModule.getCreateTime());
functionalCaseModule.setPos(this.countPos(request.getParentId())); functionalCaseModule.setPos(this.countPos(request.getParentId()));
@ -102,7 +101,7 @@ public class FunctionalCaseModuleService extends ModuleTreeService {
super.sort(nodeSortDTO); super.sort(nodeSortDTO);
} }
public void deleteModule(String moduleId, String userId) { public void deleteModule(String moduleId) {
FunctionalCaseModule deleteModule = functionalCaseModuleMapper.selectByPrimaryKey(moduleId); FunctionalCaseModule deleteModule = functionalCaseModuleMapper.selectByPrimaryKey(moduleId);
if (deleteModule != null) { if (deleteModule != null) {
this.deleteModuleByIds(Collections.singletonList(moduleId)); this.deleteModuleByIds(Collections.singletonList(moduleId));
@ -113,8 +112,10 @@ public class FunctionalCaseModuleService extends ModuleTreeService {
if (CollectionUtils.isEmpty(deleteIds)) { if (CollectionUtils.isEmpty(deleteIds)) {
return; return;
} }
FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample();
functionalCaseModuleExample.createCriteria().andIdIn(deleteIds);
functionalCaseModuleMapper.deleteByExample(functionalCaseModuleExample);
extFunctionalCaseMapper.removeToTrashByModuleIds(deleteIds); extFunctionalCaseMapper.removeToTrashByModuleIds(deleteIds);
extFunctionalCaseModuleMapper.removeToTrashByIds(deleteIds);
List<String> childrenIds = extFunctionalCaseModuleMapper.selectChildrenIdsByParentIds(deleteIds); List<String> childrenIds = extFunctionalCaseModuleMapper.selectChildrenIdsByParentIds(deleteIds);
if (CollectionUtils.isNotEmpty(childrenIds)) { if (CollectionUtils.isNotEmpty(childrenIds)) {
deleteModuleByIds(childrenIds); deleteModuleByIds(childrenIds);

View File

@ -1,13 +1,17 @@
package io.metersphere.functional.controller; package io.metersphere.functional.controller;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseModule; import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.domain.FunctionalCaseModuleExample; import io.metersphere.functional.domain.FunctionalCaseModuleExample;
import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.functional.mapper.FunctionalCaseModuleMapper; import io.metersphere.functional.mapper.FunctionalCaseModuleMapper;
import io.metersphere.functional.request.FunctionalCaseModuleCreateRequest; import io.metersphere.functional.request.FunctionalCaseModuleCreateRequest;
import io.metersphere.functional.request.FunctionalCaseModuleUpdateRequest; import io.metersphere.functional.request.FunctionalCaseModuleUpdateRequest;
import io.metersphere.functional.service.FunctionalCaseModuleService; import io.metersphere.functional.service.FunctionalCaseModuleService;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.FunctionalCaseExecuteResult;
import io.metersphere.sdk.constants.FunctionalCaseReviewStatus;
import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
@ -53,7 +57,8 @@ public class FunctionalCaseModuleControllerTests extends BaseTest {
private FunctionalCaseModuleService functionalCaseModuleService; private FunctionalCaseModuleService functionalCaseModuleService;
@Resource @Resource
private FunctionalCaseModuleMapper functionalCaseModuleMapper; private FunctionalCaseModuleMapper functionalCaseModuleMapper;
@Resource
private FunctionalCaseMapper functionalCaseMapper;
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@ -648,16 +653,23 @@ public class FunctionalCaseModuleControllerTests extends BaseTest {
public void deleteModuleTestSuccess() throws Exception { public void deleteModuleTestSuccess() throws Exception {
this.preliminaryData(); this.preliminaryData();
// 删除没有文件的节点a1-b1-c1 检查是否级联删除根节点 // 删除没有用例的节点a1-b1-c1 检查是否级联删除根节点
BaseTreeNode a1b1Node = getNodeByName(this.getFunctionalCaseModuleTreeNode(), "a1-b1"); BaseTreeNode a1b1Node = getNodeByName(this.getFunctionalCaseModuleTreeNode(), "a1-b1");
assert a1b1Node != null; assert a1b1Node != null;
this.requestGetWithOk(URL_MODULE_TREE_DELETE+a1b1Node.getId()); this.requestGetWithOk(URL_MODULE_TREE_DELETE+a1b1Node.getId());
this.checkModuleIsEmpty(a1b1Node.getId()); this.checkModuleIsEmpty(a1b1Node.getId());
// 删除有文件的节点 a1-a1 检查是否级联删除根节点 // 删除有用例的节点 a1-a1 检查是否级联删除根节点
//创建数据
BaseTreeNode a1a1Node = getNodeByName(this.getFunctionalCaseModuleTreeNode(), "a1-a1"); BaseTreeNode a1a1Node = getNodeByName(this.getFunctionalCaseModuleTreeNode(), "a1-a1");
createCase(a1a1Node);
FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey("gyqTestCaseId");
Assertions.assertNotNull(functionalCase);
this.requestGetWithOk(URL_MODULE_TREE_DELETE+a1a1Node.getId()); this.requestGetWithOk(URL_MODULE_TREE_DELETE+a1a1Node.getId());
this.checkModuleIsEmpty(a1a1Node.getId()); this.checkModuleIsEmpty(a1a1Node.getId());
FunctionalCase functionalCaseDel = functionalCaseMapper.selectByPrimaryKey("gyqTestCaseId");
Assertions.assertTrue(functionalCaseDel.getDeleted());
Assertions.assertTrue(StringUtils.equals(functionalCaseDel.getModuleId(), "root"));
//删除不存在的节点 //删除不存在的节点
this.requestGetWithOk(URL_MODULE_TREE_DELETE+IDGenerator.nextNum()); this.requestGetWithOk(URL_MODULE_TREE_DELETE+IDGenerator.nextNum());
@ -669,12 +681,34 @@ public class FunctionalCaseModuleControllerTests extends BaseTest {
} }
private void createCase(BaseTreeNode a1a1Node) {
FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setName("gyqTest");
functionalCase.setNum(100001);
functionalCase.setModuleId(a1a1Node.getId());
functionalCase.setProjectId(project.getId());
functionalCase.setDeleted(false);
functionalCase.setTemplateId("default_template");
functionalCase.setId("gyqTestCaseId");
functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name());
functionalCase.setCaseEditType("Text");
functionalCase.setPos(500L);
functionalCase.setVersionId("12335");
functionalCase.setRefId("gyqTestCaseId");
functionalCase.setLastExecuteResult(FunctionalCaseExecuteResult.UN_EXECUTED.name());
functionalCase.setPublicCase(false);
functionalCase.setLatest(true);
functionalCase.setCreateUser("gyq");
functionalCase.setCreateTime(System.currentTimeMillis());
functionalCase.setUpdateUser("gyq");
functionalCase.setUpdateTime(System.currentTimeMillis());
functionalCaseMapper.insertSelective(functionalCase);
}
private void checkModuleIsEmpty(String id) { private void checkModuleIsEmpty(String id) {
FunctionalCaseModuleExample example = new FunctionalCaseModuleExample(); FunctionalCaseModuleExample example = new FunctionalCaseModuleExample();
example.createCriteria().andParentIdEqualTo(id).andDeletedEqualTo(false); example.createCriteria().andParentIdEqualTo(id);
Assertions.assertEquals(functionalCaseModuleMapper.countByExample(example), 0); Assertions.assertEquals(functionalCaseModuleMapper.countByExample(example), 0);
} }
private List<BaseTreeNode> getFunctionalCaseModuleTreeNode() throws Exception { private List<BaseTreeNode> getFunctionalCaseModuleTreeNode() throws Exception {