fix(测试计划): 解决Jenkins调用测试计划始终Running的问题、接口定义无法使用设置环境变量脚本的问题

--bug=1005573 --user=宋天阳 【github#5036】1.11 接口测试,前后置脚本失效
https://www.tapd.cn/55049933/s/1031465;--bug=1005282 --user=宋天阳
【jenkins插件】执行方式选测试计划,问题汇总 https://www.tapd.cn/55049933/s/1031467
This commit is contained in:
song-tianyang 2021-08-02 18:07:23 +08:00 committed by 刘瑞斌
parent bb108a1f43
commit 7dfe2a6266
16 changed files with 1365 additions and 320 deletions

View File

@ -253,9 +253,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) {
if(this.getEnvironmentId() == null){
if(this.getEnvironmentId() == null || el.getEnvironmentId() == null){
el.setEnvironmentId(useEnvironment);
}
el.toHashTree(httpSamplerTree, el.getHashTree(), config);
}
}

View File

@ -0,0 +1,19 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class TestPlanReportResource implements Serializable {
private String id;
private String testPlanReportId;
private String resourceId;
private String resourceType;
private String executeResult;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,550 @@
package io.metersphere.base.domain;
import java.util.ArrayList;
import java.util.List;
public class TestPlanReportResourceExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public TestPlanReportResourceExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(String value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(String value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(String value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(String value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(String value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(String value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdLike(String value) {
addCriterion("id like", value, "id");
return (Criteria) this;
}
public Criteria andIdNotLike(String value) {
addCriterion("id not like", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(String value1, String value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(String value1, String value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andTestPlanReportIdIsNull() {
addCriterion("test_plan_report_id is null");
return (Criteria) this;
}
public Criteria andTestPlanReportIdIsNotNull() {
addCriterion("test_plan_report_id is not null");
return (Criteria) this;
}
public Criteria andTestPlanReportIdEqualTo(String value) {
addCriterion("test_plan_report_id =", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdNotEqualTo(String value) {
addCriterion("test_plan_report_id <>", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdGreaterThan(String value) {
addCriterion("test_plan_report_id >", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdGreaterThanOrEqualTo(String value) {
addCriterion("test_plan_report_id >=", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdLessThan(String value) {
addCriterion("test_plan_report_id <", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdLessThanOrEqualTo(String value) {
addCriterion("test_plan_report_id <=", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdLike(String value) {
addCriterion("test_plan_report_id like", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdNotLike(String value) {
addCriterion("test_plan_report_id not like", value, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdIn(List<String> values) {
addCriterion("test_plan_report_id in", values, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdNotIn(List<String> values) {
addCriterion("test_plan_report_id not in", values, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdBetween(String value1, String value2) {
addCriterion("test_plan_report_id between", value1, value2, "testPlanReportId");
return (Criteria) this;
}
public Criteria andTestPlanReportIdNotBetween(String value1, String value2) {
addCriterion("test_plan_report_id not between", value1, value2, "testPlanReportId");
return (Criteria) this;
}
public Criteria andResourceIdIsNull() {
addCriterion("resource_id is null");
return (Criteria) this;
}
public Criteria andResourceIdIsNotNull() {
addCriterion("resource_id is not null");
return (Criteria) this;
}
public Criteria andResourceIdEqualTo(String value) {
addCriterion("resource_id =", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotEqualTo(String value) {
addCriterion("resource_id <>", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThan(String value) {
addCriterion("resource_id >", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThanOrEqualTo(String value) {
addCriterion("resource_id >=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThan(String value) {
addCriterion("resource_id <", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThanOrEqualTo(String value) {
addCriterion("resource_id <=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLike(String value) {
addCriterion("resource_id like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotLike(String value) {
addCriterion("resource_id not like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdIn(List<String> values) {
addCriterion("resource_id in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotIn(List<String> values) {
addCriterion("resource_id not in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdBetween(String value1, String value2) {
addCriterion("resource_id between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotBetween(String value1, String value2) {
addCriterion("resource_id not between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andResourceTypeIsNull() {
addCriterion("resource_type is null");
return (Criteria) this;
}
public Criteria andResourceTypeIsNotNull() {
addCriterion("resource_type is not null");
return (Criteria) this;
}
public Criteria andResourceTypeEqualTo(String value) {
addCriterion("resource_type =", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeNotEqualTo(String value) {
addCriterion("resource_type <>", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeGreaterThan(String value) {
addCriterion("resource_type >", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeGreaterThanOrEqualTo(String value) {
addCriterion("resource_type >=", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeLessThan(String value) {
addCriterion("resource_type <", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeLessThanOrEqualTo(String value) {
addCriterion("resource_type <=", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeLike(String value) {
addCriterion("resource_type like", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeNotLike(String value) {
addCriterion("resource_type not like", value, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeIn(List<String> values) {
addCriterion("resource_type in", values, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeNotIn(List<String> values) {
addCriterion("resource_type not in", values, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeBetween(String value1, String value2) {
addCriterion("resource_type between", value1, value2, "resourceType");
return (Criteria) this;
}
public Criteria andResourceTypeNotBetween(String value1, String value2) {
addCriterion("resource_type not between", value1, value2, "resourceType");
return (Criteria) this;
}
public Criteria andExecuteResultIsNull() {
addCriterion("execute_result is null");
return (Criteria) this;
}
public Criteria andExecuteResultIsNotNull() {
addCriterion("execute_result is not null");
return (Criteria) this;
}
public Criteria andExecuteResultEqualTo(String value) {
addCriterion("execute_result =", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultNotEqualTo(String value) {
addCriterion("execute_result <>", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultGreaterThan(String value) {
addCriterion("execute_result >", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultGreaterThanOrEqualTo(String value) {
addCriterion("execute_result >=", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultLessThan(String value) {
addCriterion("execute_result <", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultLessThanOrEqualTo(String value) {
addCriterion("execute_result <=", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultLike(String value) {
addCriterion("execute_result like", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultNotLike(String value) {
addCriterion("execute_result not like", value, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultIn(List<String> values) {
addCriterion("execute_result in", values, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultNotIn(List<String> values) {
addCriterion("execute_result not in", values, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultBetween(String value1, String value2) {
addCriterion("execute_result between", value1, value2, "executeResult");
return (Criteria) this;
}
public Criteria andExecuteResultNotBetween(String value1, String value2) {
addCriterion("execute_result not between", value1, value2, "executeResult");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -11,8 +11,6 @@ public class TestPlanTestCase implements Serializable {
private String caseId;
private String reportId;
private String executor;
private String status;
@ -23,9 +21,11 @@ public class TestPlanTestCase implements Serializable {
private Long updateTime;
private String reportId;
private String createUser;
private Integer issuesCount;
private static final long serialVersionUID = 1L;
}
}

View File

@ -314,76 +314,6 @@ public class TestPlanTestCaseExample {
return (Criteria) this;
}
public Criteria andReportIdIsNull() {
addCriterion("report_id is null");
return (Criteria) this;
}
public Criteria andReportIdIsNotNull() {
addCriterion("report_id is not null");
return (Criteria) this;
}
public Criteria andReportIdEqualTo(String value) {
addCriterion("report_id =", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotEqualTo(String value) {
addCriterion("report_id <>", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdGreaterThan(String value) {
addCriterion("report_id >", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdGreaterThanOrEqualTo(String value) {
addCriterion("report_id >=", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLessThan(String value) {
addCriterion("report_id <", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLessThanOrEqualTo(String value) {
addCriterion("report_id <=", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLike(String value) {
addCriterion("report_id like", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotLike(String value) {
addCriterion("report_id not like", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdIn(List<String> values) {
addCriterion("report_id in", values, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotIn(List<String> values) {
addCriterion("report_id not in", values, "reportId");
return (Criteria) this;
}
public Criteria andReportIdBetween(String value1, String value2) {
addCriterion("report_id between", value1, value2, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotBetween(String value1, String value2) {
addCriterion("report_id not between", value1, value2, "reportId");
return (Criteria) this;
}
public Criteria andExecutorIsNull() {
addCriterion("executor is null");
return (Criteria) this;
@ -714,6 +644,76 @@ public class TestPlanTestCaseExample {
return (Criteria) this;
}
public Criteria andReportIdIsNull() {
addCriterion("report_id is null");
return (Criteria) this;
}
public Criteria andReportIdIsNotNull() {
addCriterion("report_id is not null");
return (Criteria) this;
}
public Criteria andReportIdEqualTo(String value) {
addCriterion("report_id =", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotEqualTo(String value) {
addCriterion("report_id <>", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdGreaterThan(String value) {
addCriterion("report_id >", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdGreaterThanOrEqualTo(String value) {
addCriterion("report_id >=", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLessThan(String value) {
addCriterion("report_id <", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLessThanOrEqualTo(String value) {
addCriterion("report_id <=", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLike(String value) {
addCriterion("report_id like", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotLike(String value) {
addCriterion("report_id not like", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdIn(List<String> values) {
addCriterion("report_id in", values, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotIn(List<String> values) {
addCriterion("report_id not in", values, "reportId");
return (Criteria) this;
}
public Criteria andReportIdBetween(String value1, String value2) {
addCriterion("report_id between", value1, value2, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotBetween(String value1, String value2) {
addCriterion("report_id not between", value1, value2, "reportId");
return (Criteria) this;
}
public Criteria andCreateUserIsNull() {
addCriterion("create_user is null");
return (Criteria) this;
@ -937,4 +937,4 @@ public class TestPlanTestCaseExample {
this(condition, value, secondValue, null);
}
}
}
}

View File

@ -0,0 +1,30 @@
package io.metersphere.base.mapper;
import io.metersphere.base.domain.TestPlanReportResource;
import io.metersphere.base.domain.TestPlanReportResourceExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TestPlanReportResourceMapper {
long countByExample(TestPlanReportResourceExample example);
int deleteByExample(TestPlanReportResourceExample example);
int deleteByPrimaryKey(String id);
int insert(TestPlanReportResource record);
int insertSelective(TestPlanReportResource record);
List<TestPlanReportResource> selectByExample(TestPlanReportResourceExample example);
TestPlanReportResource selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") TestPlanReportResource record, @Param("example") TestPlanReportResourceExample example);
int updateByExample(@Param("record") TestPlanReportResource record, @Param("example") TestPlanReportResourceExample example);
int updateByPrimaryKeySelective(TestPlanReportResource record);
int updateByPrimaryKey(TestPlanReportResource record);
}

View File

@ -0,0 +1,211 @@
<?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">
<mapper namespace="io.metersphere.base.mapper.TestPlanReportResourceMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.TestPlanReportResource">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="test_plan_report_id" jdbcType="VARCHAR" property="testPlanReportId" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="resource_type" jdbcType="VARCHAR" property="resourceType" />
<result column="execute_result" jdbcType="VARCHAR" property="executeResult" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, test_plan_report_id, resource_id, resource_type, execute_result
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.TestPlanReportResourceExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from test_plan_report_resource
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from test_plan_report_resource
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from test_plan_report_resource
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.TestPlanReportResourceExample">
delete from test_plan_report_resource
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.TestPlanReportResource">
insert into test_plan_report_resource (id, test_plan_report_id, resource_id,
resource_type, execute_result)
values (#{id,jdbcType=VARCHAR}, #{testPlanReportId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
#{resourceType,jdbcType=VARCHAR}, #{executeResult,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestPlanReportResource">
insert into test_plan_report_resource
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="testPlanReportId != null">
test_plan_report_id,
</if>
<if test="resourceId != null">
resource_id,
</if>
<if test="resourceType != null">
resource_type,
</if>
<if test="executeResult != null">
execute_result,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="testPlanReportId != null">
#{testPlanReportId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
</if>
<if test="resourceType != null">
#{resourceType,jdbcType=VARCHAR},
</if>
<if test="executeResult != null">
#{executeResult,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.TestPlanReportResourceExample" resultType="java.lang.Long">
select count(*) from test_plan_report_resource
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update test_plan_report_resource
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.testPlanReportId != null">
test_plan_report_id = #{record.testPlanReportId,jdbcType=VARCHAR},
</if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
</if>
<if test="record.resourceType != null">
resource_type = #{record.resourceType,jdbcType=VARCHAR},
</if>
<if test="record.executeResult != null">
execute_result = #{record.executeResult,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update test_plan_report_resource
set id = #{record.id,jdbcType=VARCHAR},
test_plan_report_id = #{record.testPlanReportId,jdbcType=VARCHAR},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
resource_type = #{record.resourceType,jdbcType=VARCHAR},
execute_result = #{record.executeResult,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.TestPlanReportResource">
update test_plan_report_resource
<set>
<if test="testPlanReportId != null">
test_plan_report_id = #{testPlanReportId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="resourceType != null">
resource_type = #{resourceType,jdbcType=VARCHAR},
</if>
<if test="executeResult != null">
execute_result = #{executeResult,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.TestPlanReportResource">
update test_plan_report_resource
set test_plan_report_id = #{testPlanReportId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
resource_type = #{resourceType,jdbcType=VARCHAR},
execute_result = #{executeResult,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -5,12 +5,12 @@
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="plan_id" jdbcType="VARCHAR" property="planId" />
<result column="case_id" jdbcType="VARCHAR" property="caseId" />
<result column="report_id" jdbcType="VARCHAR" property="reportId" />
<result column="executor" jdbcType="VARCHAR" property="executor" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="report_id" jdbcType="VARCHAR" property="reportId" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
<result column="issues_count" jdbcType="INTEGER" property="issuesCount" />
</resultMap>
@ -78,7 +78,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, plan_id, case_id, report_id, executor, `status`, remark, create_time, update_time,
id, plan_id, case_id, executor, `status`, remark, create_time, update_time, report_id,
create_user, issues_count
</sql>
<sql id="Blob_Column_List">
@ -115,7 +115,7 @@
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
select
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
@ -133,15 +133,15 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.TestPlanTestCaseWithBLOBs">
insert into test_plan_test_case (id, plan_id, case_id,
report_id, executor, `status`,
remark, create_time, update_time,
create_user, issues_count, results,
insert into test_plan_test_case (id, plan_id, case_id,
executor, `status`, remark,
create_time, update_time, report_id,
create_user, issues_count, results,
issues, actual_result)
values (#{id,jdbcType=VARCHAR}, #{planId,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR},
#{reportId,jdbcType=VARCHAR}, #{executor,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{createUser,jdbcType=VARCHAR}, #{issuesCount,jdbcType=INTEGER}, #{results,jdbcType=LONGVARCHAR},
values (#{id,jdbcType=VARCHAR}, #{planId,jdbcType=VARCHAR}, #{caseId,jdbcType=VARCHAR},
#{executor,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{reportId,jdbcType=VARCHAR},
#{createUser,jdbcType=VARCHAR}, #{issuesCount,jdbcType=INTEGER}, #{results,jdbcType=LONGVARCHAR},
#{issues,jdbcType=LONGVARCHAR}, #{actualResult,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestPlanTestCaseWithBLOBs">
@ -156,9 +156,6 @@
<if test="caseId != null">
case_id,
</if>
<if test="reportId != null">
report_id,
</if>
<if test="executor != null">
executor,
</if>
@ -174,6 +171,9 @@
<if test="updateTime != null">
update_time,
</if>
<if test="reportId != null">
report_id,
</if>
<if test="createUser != null">
create_user,
</if>
@ -200,9 +200,6 @@
<if test="caseId != null">
#{caseId,jdbcType=VARCHAR},
</if>
<if test="reportId != null">
#{reportId,jdbcType=VARCHAR},
</if>
<if test="executor != null">
#{executor,jdbcType=VARCHAR},
</if>
@ -218,6 +215,9 @@
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="reportId != null">
#{reportId,jdbcType=VARCHAR},
</if>
<if test="createUser != null">
#{createUser,jdbcType=VARCHAR},
</if>
@ -253,9 +253,6 @@
<if test="record.caseId != null">
case_id = #{record.caseId,jdbcType=VARCHAR},
</if>
<if test="record.reportId != null">
report_id = #{record.reportId,jdbcType=VARCHAR},
</if>
<if test="record.executor != null">
executor = #{record.executor,jdbcType=VARCHAR},
</if>
@ -271,6 +268,9 @@
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.reportId != null">
report_id = #{record.reportId,jdbcType=VARCHAR},
</if>
<if test="record.createUser != null">
create_user = #{record.createUser,jdbcType=VARCHAR},
</if>
@ -296,12 +296,12 @@
set id = #{record.id,jdbcType=VARCHAR},
plan_id = #{record.planId,jdbcType=VARCHAR},
case_id = #{record.caseId,jdbcType=VARCHAR},
report_id = #{record.reportId,jdbcType=VARCHAR},
executor = #{record.executor,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=VARCHAR},
remark = #{record.remark,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
report_id = #{record.reportId,jdbcType=VARCHAR},
create_user = #{record.createUser,jdbcType=VARCHAR},
issues_count = #{record.issuesCount,jdbcType=INTEGER},
results = #{record.results,jdbcType=LONGVARCHAR},
@ -316,12 +316,12 @@
set id = #{record.id,jdbcType=VARCHAR},
plan_id = #{record.planId,jdbcType=VARCHAR},
case_id = #{record.caseId,jdbcType=VARCHAR},
report_id = #{record.reportId,jdbcType=VARCHAR},
executor = #{record.executor,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=VARCHAR},
remark = #{record.remark,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
report_id = #{record.reportId,jdbcType=VARCHAR},
create_user = #{record.createUser,jdbcType=VARCHAR},
issues_count = #{record.issuesCount,jdbcType=INTEGER}
<if test="_parameter != null">
@ -337,9 +337,6 @@
<if test="caseId != null">
case_id = #{caseId,jdbcType=VARCHAR},
</if>
<if test="reportId != null">
report_id = #{reportId,jdbcType=VARCHAR},
</if>
<if test="executor != null">
executor = #{executor,jdbcType=VARCHAR},
</if>
@ -355,6 +352,9 @@
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="reportId != null">
report_id = #{reportId,jdbcType=VARCHAR},
</if>
<if test="createUser != null">
create_user = #{createUser,jdbcType=VARCHAR},
</if>
@ -377,12 +377,12 @@
update test_plan_test_case
set plan_id = #{planId,jdbcType=VARCHAR},
case_id = #{caseId,jdbcType=VARCHAR},
report_id = #{reportId,jdbcType=VARCHAR},
executor = #{executor,jdbcType=VARCHAR},
`status` = #{status,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
report_id = #{reportId,jdbcType=VARCHAR},
create_user = #{createUser,jdbcType=VARCHAR},
issues_count = #{issuesCount,jdbcType=INTEGER},
results = #{results,jdbcType=LONGVARCHAR},
@ -394,14 +394,14 @@
update test_plan_test_case
set plan_id = #{planId,jdbcType=VARCHAR},
case_id = #{caseId,jdbcType=VARCHAR},
report_id = #{reportId,jdbcType=VARCHAR},
executor = #{executor,jdbcType=VARCHAR},
`status` = #{status,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
report_id = #{reportId,jdbcType=VARCHAR},
create_user = #{createUser,jdbcType=VARCHAR},
issues_count = #{issuesCount,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
</mapper>

View File

@ -0,0 +1,9 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.TestPlanReportResource;
import java.util.List;
public interface ExtTestPlanReportResourceMapper {
List<TestPlanReportResource> selectResourceIdAndResourceTypeAndExecuteResultByTestPlanReportId(String testPlanReportId);
}

View File

@ -0,0 +1,11 @@
<?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">
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestPlanReportResourceMapper">
<select id="selectResourceIdAndResourceTypeAndExecuteResultByTestPlanReportId" resultType="io.metersphere.base.domain.TestPlanReportResource">
select resource_id,resource_type,execute_result from test_plan_report_resource
where test_plan_report_id = #{0}
</select>
</mapper>

View File

@ -0,0 +1,5 @@
package io.metersphere.commons.constants;
public enum TestPlanResourceType {
API_CASE,SCENARIO_CASE,PERFORMANCE_CASE
}

View File

@ -3,6 +3,8 @@ package io.metersphere.track.request.report;
import lombok.Getter;
import lombok.Setter;
import java.util.Map;
/**
* @author song.tianyang
* @Date 2021/1/8 4:36 下午
@ -21,9 +23,12 @@ public class TestPlanReportSaveRequest {
private boolean scenarioIsExecuting;
private boolean performanceIsExecuting;
private String apiCaseIdListJSON;
private String scenarioIdListJSON;
private String performanceIdListJSON;
// private String apiCaseIdListJSON;
// private String scenarioIdListJSON;
// private String performanceIdListJSON;
Map<String,String> apiCaseIdMap;
Map<String,String> scenarioIdMap;
Map<String,String> performanceIdMap;
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode) {
this.reportID = reportID;
@ -34,7 +39,8 @@ public class TestPlanReportSaveRequest {
this.countResources = true;
}
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode, boolean apiCaseIsExecuting, boolean scenarioIsExecuting, boolean performanceIsExecuting, String apiCaseIdListJSON, String scenarioIdListJSON, String performanceIdListJSON) {
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode, boolean apiCaseIsExecuting, boolean scenarioIsExecuting, boolean performanceIsExecuting,
Map<String,String> apiCaseIdMap, Map<String,String> scenarioIdMap, Map<String,String> performanceIdMap) {
this.reportID = reportID;
this.planId = planId;
this.userId = userId;
@ -46,8 +52,8 @@ public class TestPlanReportSaveRequest {
this.scenarioIsExecuting = scenarioIsExecuting;
this.performanceIsExecuting = performanceIsExecuting;
this.apiCaseIdListJSON = apiCaseIdListJSON;
this.scenarioIdListJSON = scenarioIdListJSON;
this.performanceIdListJSON = performanceIdListJSON;
this.apiCaseIdMap = apiCaseIdMap;
this.scenarioIdMap = scenarioIdMap;
this.performanceIdMap = performanceIdMap;
}
}

View File

@ -0,0 +1,73 @@
package io.metersphere.track.service;
import io.metersphere.base.domain.TestPlanReportResource;
import io.metersphere.base.domain.TestPlanReportResourceExample;
import io.metersphere.base.mapper.TestPlanReportResourceMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanReportResourceMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author song.tianyang
* @Date 2021/8/2 1:57 下午
*/
@Service
public class TestPlanReportResourceService {
@Resource
private TestPlanReportResourceMapper testPlanReportResourceMapper;
@Resource
private ExtTestPlanReportResourceMapper extTestPlanReportResourceMapper;
public int updateExecuteResultByReportIdAndResourceIds(String executeResult, String planReportId, List<String> ids) {
if(CollectionUtils.isEmpty(ids)){
return 0;
}else {
TestPlanReportResourceExample example = new TestPlanReportResourceExample();
example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceIdIn(ids);
TestPlanReportResource updateModel = new TestPlanReportResource();
updateModel.setExecuteResult(executeResult);
return testPlanReportResourceMapper.updateByExampleSelective(updateModel,example);
}
}
public long countByReportIdAndResourceTypeAndExecuteResultNotEquals(String planReportId, String resourceType, String executeResult) {
TestPlanReportResourceExample example = new TestPlanReportResourceExample();
example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceTypeEqualTo(resourceType).andExecuteResultNotEqualTo(executeResult);
return this.testPlanReportResourceMapper.countByExample(example);
}
public long countByReportIdAndResourceTypeAndExecuteResultEquals(String planReportId, String resourceType, String executeResult) {
TestPlanReportResourceExample example = new TestPlanReportResourceExample();
example.createCriteria().andTestPlanReportIdEqualTo(planReportId).andResourceTypeEqualTo(resourceType).andExecuteResultEqualTo(executeResult);
return this.testPlanReportResourceMapper.countByExample(example);
}
public Map<String, Map<String, String>> selectExecuteResultByTestPlanReportId(String testPlanReportId) {
Map<String,Map<String,String>> resourceTypeMap = new HashMap<>();
List<TestPlanReportResource> testPlanReportResourceList = extTestPlanReportResourceMapper.selectResourceIdAndResourceTypeAndExecuteResultByTestPlanReportId(testPlanReportId);
for (TestPlanReportResource model : testPlanReportResourceList) {
String resourceType = model.getResourceType();
String resourceId = model.getResourceId();
String executeResult = model.getExecuteResult();
if(resourceTypeMap.containsKey(resourceType)){
resourceTypeMap.get(resourceType).put(resourceId,executeResult);
}else {
Map<String ,String> map = new HashMap<>();
map.put(resourceId,executeResult);
resourceTypeMap.put(resourceType,map);
}
}
return resourceTypeMap;
}
public void deleteByExample(TestPlanReportResourceExample resourceExample) {
testPlanReportResourceMapper.deleteByExample(resourceExample);
}
}

View File

@ -72,6 +72,8 @@ public class TestPlanReportService {
ExtTestPlanMapper extTestPlanMapper;
@Resource
ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@Resource
TestPlanReportResourceService testPlanReportResourceService;
// @Resource
// TestPlanLoadCaseService testPlanLoadCaseService;
// @Resource
@ -90,7 +92,25 @@ public class TestPlanReportService {
if (StringUtils.isNotBlank(projectId)) {
request.setProjectId(projectId);
}
return extTestPlanReportMapper.list(request);
List<TestPlanReportDTO> list = extTestPlanReportMapper.list(request);
// this.checkReport(list);
return list;
}
// private void checkReport(List<TestPlanReportDTO> list) {
// if(CollectionUtils.isNotEmpty(list)){
// for (TestPlanReportDTO dto : list){
// if(StringUtils.equalsIgnoreCase(dto.getStatus(),TestPlanApiExecuteStatus.RUNNING.name())){
// TestPlanReport model = this.updateTestPlanReportById(dto.getId());
// if(model != null && model.getStatus() != null){
// dto.setStatus(model.getStatus());
// }
// }
// }
// }
// }
private TestPlanReport updateTestPlanReportById(String id) {
return this.updateExecuteApis(id,null,null,null);
}
public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) {
@ -122,30 +142,21 @@ public class TestPlanReportService {
String planReportId = UUID.randomUUID().toString();
List<Map<String, String>> apiCaseInfoList = new ArrayList<>();
Map<String, String> apiCaseInfoMap = new HashMap<>();
for (String id : apiTestCaseIdMap.keySet()) {
Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("status", TestPlanApiExecuteStatus.PREPARE.name());
apiCaseInfoList.add(map);
apiCaseInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name());
}
List<Map<String, String>> scenarioInfoList = new ArrayList<>();
Map<String, String> scenarioInfoMap = new HashMap<>();
for (String id : planScenarioIdMap.keySet()) {
Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("status", TestPlanApiExecuteStatus.PREPARE.name());
scenarioInfoList.add(map);
scenarioInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name());
}
List<Map<String, String>> performanceInfoList = new ArrayList<>();
Map<String, String> performanceInfoMap = new HashMap<>();
for (String id : performanceIdMap.values()) {
Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("status", TestPlanApiExecuteStatus.PREPARE.name());
performanceInfoList.add(map);
performanceInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name());
}
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId, planId, userId, triggerMode,
apiTestCaseIdMap.size() > 0, planScenarioIdMap.size() > 0, performanceIdMap.size() > 0,
JSONArray.toJSONString(apiCaseInfoList), JSONArray.toJSONString(scenarioInfoList), JSONArray.toJSONString(performanceInfoList));
apiCaseInfoMap, scenarioInfoMap, performanceInfoMap);
TestPlanReport report = this.genTestPlanReport(saveRequest);
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
@ -187,6 +198,10 @@ public class TestPlanReportService {
testPlanReportData.setId(UUID.randomUUID().toString());
testPlanReportData.setTestPlanReportId(testPlanReportID);
Map<String, String> apiCaseInfoMap = new HashMap<>();
Map<String, String> scenarioInfoMap = new HashMap<>();
Map<String, String> performanceInfoMap = new HashMap<>();
if (saveRequest.isCountResources()) {
TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample();
apiExample.createCriteria().andTestPlanIdEqualTo(saveRequest.getPlanId());
@ -207,38 +222,70 @@ public class TestPlanReportService {
.stream().map(TestPlanLoadCaseDTO::getLoadCaseId).collect(Collectors.toList());
testPlanReport.setIsPerformanceExecuting(!performanceIdList.isEmpty());
List<Map<String, String>> apiCaseInfoList = new ArrayList<>();
for (String id : apiCaseIdList) {
Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("status", TestPlanApiExecuteStatus.PREPARE.name());
apiCaseInfoList.add(map);
apiCaseInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name());
}
List<Map<String, String>> scenarioInfoList = new ArrayList<>();
for (String id : scenarioIdList) {
Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("status", TestPlanApiExecuteStatus.PREPARE.name());
scenarioInfoList.add(map);
scenarioInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name());
}
List<Map<String, String>> performanceInfoList = new ArrayList<>();
for (String id : performanceIdList) {
Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("status", TestPlanApiExecuteStatus.PREPARE.name());
performanceInfoList.add(map);
performanceInfoMap.put(id,TestPlanApiExecuteStatus.PREPARE.name());
}
testPlanReportData.setApiCaseInfo(JSONArray.toJSONString(apiCaseInfoList));
testPlanReportData.setScenarioInfo(JSONArray.toJSONString(scenarioInfoList));
testPlanReportData.setPerformanceInfo(JSONArray.toJSONString(performanceInfoList));
} else {
testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting());
testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting());
testPlanReport.setIsPerformanceExecuting(saveRequest.isPerformanceIsExecuting());
testPlanReportData.setApiCaseInfo(saveRequest.getApiCaseIdListJSON());
testPlanReportData.setScenarioInfo(saveRequest.getScenarioIdListJSON());
testPlanReportData.setPerformanceInfo(saveRequest.getPerformanceIdListJSON());
apiCaseInfoMap = saveRequest.getApiCaseIdMap();
scenarioInfoMap = saveRequest.getScenarioIdMap();
performanceInfoMap = saveRequest.getPerformanceIdMap();
}
List<TestPlanReportResource> resourceList = new ArrayList<>();
if(MapUtils.isNotEmpty(apiCaseInfoMap)){
for (Map.Entry<String, String> entry : apiCaseInfoMap.entrySet()){
String id = entry.getKey();
String status = entry.getValue();
String type = TestPlanResourceType.API_CASE.name();
TestPlanReportResource apiCaseResource = new TestPlanReportResource();
apiCaseResource.setResourceId(id);
apiCaseResource.setTestPlanReportId(testPlanReportID);
apiCaseResource.setResourceType(type);
apiCaseResource.setExecuteResult(status);
apiCaseResource.setId(UUID.randomUUID().toString());
resourceList.add(apiCaseResource);
}
}
if(MapUtils.isNotEmpty(scenarioInfoMap)){
for (Map.Entry<String, String> entry : scenarioInfoMap.entrySet()){
String id = entry.getKey();
String status = entry.getValue();
String type = TestPlanResourceType.SCENARIO_CASE.name();
TestPlanReportResource scenarioResource = new TestPlanReportResource();
scenarioResource.setResourceId(id);
scenarioResource.setTestPlanReportId(testPlanReportID);
scenarioResource.setResourceType(type);
scenarioResource.setExecuteResult(status);
scenarioResource.setId(UUID.randomUUID().toString());
resourceList.add(scenarioResource);
}
}
if(MapUtils.isNotEmpty(performanceInfoMap)){
for (Map.Entry<String, String> entry : performanceInfoMap.entrySet()){
String id = entry.getKey();
String status = entry.getValue();
String type = TestPlanResourceType.PERFORMANCE_CASE.name();
TestPlanReportResource performanceResource = new TestPlanReportResource();
performanceResource.setResourceId(id);
performanceResource.setTestPlanReportId(testPlanReportID);
performanceResource.setResourceType(type);
performanceResource.setExecuteResult(status);
performanceResource.setId(UUID.randomUUID().toString());
resourceList.add(performanceResource);
}
}
testPlanReport.setPrincipal(testPlan.getPrincipal());
@ -251,8 +298,12 @@ public class TestPlanReportService {
SqlSession sqlSession = sqlSessionFactory.openSession(false);
TestPlanReportMapper insertReportMapper = sqlSession.getMapper(TestPlanReportMapper.class);
TestPlanReportDataMapper insertReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class);
TestPlanReportResourceMapper insertResourceMapper = sqlSession.getMapper(TestPlanReportResourceMapper.class);
insertReportMapper.insert(testPlanReport);
insertReportDataMapper.insert(testPlanReportData);
for (TestPlanReportResource resource : resourceList) {
insertResourceMapper.insert(resource);
}
sqlSession.commit();
sqlSession.flushStatements();
@ -266,6 +317,9 @@ public class TestPlanReportService {
TestPlanReportDTO returnDTO = new TestPlanReportDTO();
TestPlanReport report = testPlanReportMapper.selectByPrimaryKey(reportId);
if (report != null) {
if(StringUtils.equalsIgnoreCase(report.getStatus(),TestPlanApiExecuteStatus.RUNNING.name())){
report = this.updateExecuteApis(reportId,null,null,null);
}
TestPlanReportDataExample example = new TestPlanReportDataExample();
example.createCriteria().andTestPlanReportIdEqualTo(reportId);
List<TestPlanReportDataWithBLOBs> reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example);
@ -317,15 +371,15 @@ public class TestPlanReportService {
}
}
public TestCaseReportMetricDTO countReportData(TestPlanDTO testPlan, TestPlanReportDataWithBLOBs testPlanReportData) {
public TestCaseReportMetricDTO countReportData(TestPlanDTO testPlan, Map<String,Map<String, String>> executeResult) {
TestCaseReportMetricDTO returnDTO = new TestCaseReportMetricDTO();
ReportResultComponent reportResultComponent = new ReportResultComponent(testPlan);
reportResultComponent.afterBuild(returnDTO);
TestCaseReportAdvanceStatusResultDTO statusDTO = new TestCaseReportAdvanceStatusResultDTO();
String apiCaseExecuteMapJson = testPlanReportData.getApiCaseInfo();
String scenarioExecuteMapJson = testPlanReportData.getScenarioInfo();
String loadExecuteMapJson = testPlanReportData.getPerformanceInfo();
Map<String,String> apiCaseExecuteMap = executeResult.get(TestPlanResourceType.API_CASE.name());
Map<String,String> scenarioExecuteMap = executeResult.get(TestPlanResourceType.SCENARIO_CASE.name());
Map<String,String> performanceCaseExecuteMap = executeResult.get(TestPlanResourceType.PERFORMANCE_CASE.name());
List<TestCaseReportStatusResultDTO> apiResult = new ArrayList<>();
List<TestCaseReportStatusResultDTO> scenarioResult = new ArrayList<>();
@ -335,55 +389,26 @@ public class TestPlanReportService {
List<String> faliureScenarioCaseIdList = new ArrayList<>();
List<String> faliureLoadCaseIdList = new ArrayList<>();
JSONArray apiCaseExecuteArr = new JSONArray();
JSONArray scenarioExecuteArr = new JSONArray();
JSONArray loadExecuteArr = new JSONArray();
if (StringUtils.isNotEmpty(apiCaseExecuteMapJson)) {
try {
apiCaseExecuteArr = JSONArray.parseArray(apiCaseExecuteMapJson);
} catch (Exception e) {
}
}
if (StringUtils.isNotEmpty(scenarioExecuteMapJson)) {
try {
scenarioExecuteArr = JSONArray.parseArray(scenarioExecuteMapJson);
} catch (Exception e) {
}
}
if (StringUtils.isNotEmpty(loadExecuteMapJson)) {
try {
loadExecuteArr = JSONArray.parseArray(loadExecuteMapJson);
} catch (Exception e) {
}
}
for (int i = 0; i < apiCaseExecuteArr.size(); i++) {
JSONObject jsonObj = apiCaseExecuteArr.getJSONObject(i);
if(MapUtils.isNotEmpty(apiCaseExecuteMap)){
Map<String, Integer> countMap = new HashMap<>();
if (jsonObj.containsKey("status")) {
String status = jsonObj.getString("status");
if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) {
for (Map.Entry<String, String> executeEntry: apiCaseExecuteMap.entrySet()){
String caseResult = executeEntry.getValue();
String id = executeEntry.getKey();
if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.SUCCESS.name())) {
if (countMap.containsKey("Pass")) {
countMap.put("Pass", countMap.get("Pass") + 1);
} else {
countMap.put("Pass", 1);
}
} else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) {
if (jsonObj.containsKey("id")) {
faliureApiCaseIdList.add(jsonObj.getString("id"));
}
} else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.FAILD.name())) {
faliureApiCaseIdList.add(id);
if (countMap.containsKey("Failure")) {
countMap.put("Failure", countMap.get("Failure") + 1);
} else {
countMap.put("Failure", 1);
}
} else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) {
if (jsonObj.containsKey("id")) {
faliureApiCaseIdList.add(jsonObj.getString("id"));
}
} else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.PREPARE.name())) {
faliureApiCaseIdList.add(id);
if (countMap.containsKey("Skip")) {
countMap.put("Skip", countMap.get("Skip") + 1);
} else {
@ -407,30 +432,26 @@ public class TestPlanReportService {
}
}
for (int i = 0; i < scenarioExecuteArr.size(); i++) {
JSONObject jsonObj = scenarioExecuteArr.getJSONObject(i);
if(MapUtils.isNotEmpty(scenarioExecuteMap)){
Map<String, Integer> countMap = new HashMap<>();
if (jsonObj.containsKey("status")) {
String status = jsonObj.getString("status");
if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) {
for (Map.Entry<String, String> executeEntry: scenarioExecuteMap.entrySet()){
String caseResult = executeEntry.getValue();
String id = executeEntry.getKey();
if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.SUCCESS.name())) {
if (countMap.containsKey("Pass")) {
countMap.put("Pass", countMap.get("Pass") + 1);
} else {
countMap.put("Pass", 1);
}
} else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) {
if (jsonObj.containsKey("id")) {
faliureScenarioCaseIdList.add(jsonObj.getString("id"));
}
} else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.FAILD.name())) {
faliureApiCaseIdList.add(id);
if (countMap.containsKey("Failure")) {
countMap.put("Failure", countMap.get("Failure") + 1);
} else {
countMap.put("Failure", 1);
}
} else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) {
if (jsonObj.containsKey("id")) {
faliureScenarioCaseIdList.add(jsonObj.getString("id"));
}
} else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.PREPARE.name())) {
faliureApiCaseIdList.add(id);
if (countMap.containsKey("Skip")) {
countMap.put("Skip", countMap.get("Skip") + 1);
} else {
@ -444,7 +465,6 @@ public class TestPlanReportService {
}
}
}
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
String status = entry.getKey();
Integer value = entry.getValue();
@ -455,30 +475,26 @@ public class TestPlanReportService {
}
}
for (int i = 0; i < loadExecuteArr.size(); i++) {
JSONObject jsonObj = loadExecuteArr.getJSONObject(i);
if(MapUtils.isNotEmpty(performanceCaseExecuteMap)){
Map<String, Integer> countMap = new HashMap<>();
if (jsonObj.containsKey("status")) {
String status = jsonObj.getString("status");
if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) {
for (Map.Entry<String, String> executeEntry: performanceCaseExecuteMap.entrySet()){
String caseResult = executeEntry.getValue();
String id = executeEntry.getKey();
if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.SUCCESS.name())) {
if (countMap.containsKey("Pass")) {
countMap.put("Pass", countMap.get("Pass") + 1);
} else {
countMap.put("Pass", 1);
}
} else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) {
if (jsonObj.containsKey("id")) {
faliureLoadCaseIdList.add(jsonObj.getString("id"));
}
} else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.FAILD.name())) {
faliureApiCaseIdList.add(id);
if (countMap.containsKey("Failure")) {
countMap.put("Failure", countMap.get("Failure") + 1);
} else {
countMap.put("Failure", 1);
}
} else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) {
if (jsonObj.containsKey("id")) {
faliureLoadCaseIdList.add(jsonObj.getString("id"));
}
} else if (StringUtils.equalsAnyIgnoreCase(caseResult, TestPlanApiExecuteStatus.PREPARE.name())) {
faliureApiCaseIdList.add(id);
if (countMap.containsKey("Skip")) {
countMap.put("Skip", countMap.get("Skip") + 1);
} else {
@ -492,7 +508,6 @@ public class TestPlanReportService {
}
}
}
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
String status = entry.getKey();
Integer value = entry.getValue();
@ -502,6 +517,113 @@ public class TestPlanReportService {
loadResult.add(dto);
}
}
// for (int i = 0; i < apiCaseExecuteArr.size(); i++) {
// JSONObject jsonObj = apiCaseExecuteArr.getJSONObject(i);
//
// Map<String, Integer> countMap = new HashMap<>();
// if (jsonObj.containsKey("status")) {
// String status = jsonObj.getString("status");
//
// }
//
// }
//
// for (int i = 0; i < scenarioExecuteArr.size(); i++) {
// JSONObject jsonObj = scenarioExecuteArr.getJSONObject(i);
// Map<String, Integer> countMap = new HashMap<>();
// if (jsonObj.containsKey("status")) {
// String status = jsonObj.getString("status");
// if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) {
// if (countMap.containsKey("Pass")) {
// countMap.put("Pass", countMap.get("Pass") + 1);
// } else {
// countMap.put("Pass", 1);
// }
// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) {
// if (jsonObj.containsKey("id")) {
// faliureScenarioCaseIdList.add(jsonObj.getString("id"));
// }
// if (countMap.containsKey("Failure")) {
// countMap.put("Failure", countMap.get("Failure") + 1);
// } else {
// countMap.put("Failure", 1);
// }
// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) {
// if (jsonObj.containsKey("id")) {
// faliureScenarioCaseIdList.add(jsonObj.getString("id"));
// }
// if (countMap.containsKey("Skip")) {
// countMap.put("Skip", countMap.get("Skip") + 1);
// } else {
// countMap.put("Skip", 1);
// }
// } else {
// if (countMap.containsKey("Underway")) {
// countMap.put("Underway", countMap.get("Underway") + 1);
// } else {
// countMap.put("Underway", 1);
// }
// }
// }
//
// for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
// String status = entry.getKey();
// Integer value = entry.getValue();
// TestCaseReportStatusResultDTO dto = new TestCaseReportStatusResultDTO();
// dto.setStatus(status);
// dto.setCount(value);
// scenarioResult.add(dto);
// }
// }
//
// for (int i = 0; i < loadExecuteArr.size(); i++) {
// JSONObject jsonObj = loadExecuteArr.getJSONObject(i);
// Map<String, Integer> countMap = new HashMap<>();
// if (jsonObj.containsKey("status")) {
// String status = jsonObj.getString("status");
// if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name())) {
// if (countMap.containsKey("Pass")) {
// countMap.put("Pass", countMap.get("Pass") + 1);
// } else {
// countMap.put("Pass", 1);
// }
// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.FAILD.name())) {
// if (jsonObj.containsKey("id")) {
// faliureLoadCaseIdList.add(jsonObj.getString("id"));
// }
// if (countMap.containsKey("Failure")) {
// countMap.put("Failure", countMap.get("Failure") + 1);
// } else {
// countMap.put("Failure", 1);
// }
// } else if (StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.PREPARE.name())) {
// if (jsonObj.containsKey("id")) {
// faliureLoadCaseIdList.add(jsonObj.getString("id"));
// }
// if (countMap.containsKey("Skip")) {
// countMap.put("Skip", countMap.get("Skip") + 1);
// } else {
// countMap.put("Skip", 1);
// }
// } else {
// if (countMap.containsKey("Underway")) {
// countMap.put("Underway", countMap.get("Underway") + 1);
// } else {
// countMap.put("Underway", 1);
// }
// }
// }
//
// for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
// String status = entry.getKey();
// Integer value = entry.getValue();
// TestCaseReportStatusResultDTO dto = new TestCaseReportStatusResultDTO();
// dto.setStatus(status);
// dto.setCount(value);
// loadResult.add(dto);
// }
// }
statusDTO.setApiResult(apiResult);
statusDTO.setScenarioResult(scenarioResult);
statusDTO.setLoadResult(loadResult);
@ -547,14 +669,17 @@ public class TestPlanReportService {
return returnDTO;
}
public void updateReport(TestPlanReportDataWithBLOBs testPlanReportData, boolean apiCaseIsOk, boolean scenarioIsOk, boolean performanceIsOk) {
public TestPlanReport updateReport(TestPlanReportDataWithBLOBs testPlanReportData, boolean apiCaseIsOk, boolean scenarioIsOk, boolean performanceIsOk,boolean updateTime) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportData.getTestPlanReportId());
if (testPlanReport == null) {
return;
return null;
}
if(updateTime){
testPlanReport.setEndTime(System.currentTimeMillis());
testPlanReport.setUpdateTime(System.currentTimeMillis());
}
testPlanReport.setEndTime(System.currentTimeMillis());
testPlanReport.setUpdateTime(System.currentTimeMillis());
if (apiCaseIsOk) {
testPlanReport.setIsApiCaseExecuting(false);
}
@ -581,8 +706,11 @@ public class TestPlanReportService {
testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components);
testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components);
Map<String,Map<String, String>> testPlanExecuteResult = testPlanReportResourceService.selectExecuteResultByTestPlanReportId(testPlanReportData.getTestPlanReportId());
TestCaseReportMetricDTO testCaseReportMetricDTO = this.countReportData(testPlan, testPlanReportData);
testPlanLog.info("ReportId["+testPlanReportData.getTestPlanReportId()+"] COUNT OVER. COUNT RESULT :"+JSONObject.toJSONString(testPlanExecuteResult));
TestCaseReportMetricDTO testCaseReportMetricDTO = this.countReportData(testPlan, testPlanExecuteResult);
//统计执行的场景ID
testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult()));
@ -593,7 +721,8 @@ public class TestPlanReportService {
String testPlanStatus = this.getTestPlanReportStatus(testPlanReport, testPlanReportData);
testPlanReport.setStatus(testPlanStatus);
this.update(testPlanReport);
testPlanReport = this.update(testPlanReport);
return testPlanReport;
}
public void checkTestPlanStatus(String planReportId) {
@ -792,7 +921,7 @@ public class TestPlanReportService {
return status;
}
public void update(TestPlanReport report) {
public TestPlanReport update(TestPlanReport report) {
if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting()) {
try {
//更新TestPlan状态为完成
@ -812,6 +941,7 @@ public class TestPlanReportService {
}
testPlanReportMapper.updateByPrimaryKey(report);
return report;
}
public void sendMessage(TestPlanReport testPlanReport) {
@ -961,6 +1091,9 @@ public class TestPlanReportService {
TestPlanReportDataExample example = new TestPlanReportDataExample();
example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
testPlanReportDataMapper.deleteByExample(example);
TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample();
resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
testPlanReportResourceService.deleteByExample(resourceExample);
}
}
@ -969,13 +1102,20 @@ public class TestPlanReportService {
if (request.isSelectAllDate()) {
deleteReportIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getProjectId(), request.getUnSelectIds());
}
TestPlanReportExample deleteReportExample = new TestPlanReportExample();
deleteReportExample.createCriteria().andIdIn(deleteReportIds);
testPlanReportMapper.deleteByExample(deleteReportExample);
if(CollectionUtils.isNotEmpty(deleteReportIds)){
TestPlanReportExample deleteReportExample = new TestPlanReportExample();
deleteReportExample.createCriteria().andIdIn(deleteReportIds);
testPlanReportMapper.deleteByExample(deleteReportExample);
TestPlanReportDataExample example = new TestPlanReportDataExample();
example.createCriteria().andTestPlanReportIdIn(deleteReportIds);
testPlanReportDataMapper.deleteByExample(example);
TestPlanReportDataExample example = new TestPlanReportDataExample();
example.createCriteria().andTestPlanReportIdIn(deleteReportIds);
testPlanReportDataMapper.deleteByExample(example);
TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample();
resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds);
testPlanReportResourceService.deleteByExample(resourceExample);
}
}
private List<String> getAllApiIdsByFontedSelect(Map<String, List<String>> filters, String name, String projectId, List<String> unSelectIds) {
@ -1005,8 +1145,9 @@ public class TestPlanReportService {
return null;
}
public synchronized void updateExecuteApis(String planReportId, Map<String, String> executeApiCaseIdMap, Map<String, String> executeScenarioCaseIdMap, Map<String, String> executePerformanceIdMap) {
public synchronized TestPlanReport updateExecuteApis(String planReportId, Map<String, String> executeApiCaseIdMap, Map<String, String> executeScenarioCaseIdMap, Map<String, String> executePerformanceIdMap) {
TestPlanReportDataExample example = new TestPlanReportDataExample();
List<String> resourceIdList = new ArrayList<>();
if(executeApiCaseIdMap == null){
executeApiCaseIdMap = new HashMap<>();
}
@ -1016,104 +1157,78 @@ public class TestPlanReportService {
if(executePerformanceIdMap == null){
executePerformanceIdMap = new HashMap<>();
}
boolean updateTime = MapUtils.isNotEmpty(executeApiCaseIdMap)||MapUtils.isNotEmpty(executeScenarioCaseIdMap)||MapUtils.isNotEmpty(executePerformanceIdMap);
testPlanLog.info("ReportId["+planReportId+"] Executed. api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; performance:"+JSONObject.toJSONString(executePerformanceIdMap));
example.createCriteria().andTestPlanReportIdEqualTo(planReportId);
List<TestPlanReportDataWithBLOBs> reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example);
TestPlanReport report = null;
if (!reportDataList.isEmpty()) {
Map<String,List<String>> batchUpdateMap = new HashMap<>();
for (Map.Entry<String, String> entry:executeApiCaseIdMap.entrySet()){
String id = entry.getKey();
String result = entry.getValue();
if(batchUpdateMap.containsKey(result)){
batchUpdateMap.get(result).add(id);
}else {
List<String> idList = new ArrayList<>();
idList.add(id);
batchUpdateMap.put(result,idList);
}
}
for (Map.Entry<String, String> entry:executeScenarioCaseIdMap.entrySet()){
String id = entry.getKey();
String result = entry.getValue();
if(batchUpdateMap.containsKey(result)){
batchUpdateMap.get(result).add(id);
}else {
List<String> idList = new ArrayList<>();
idList.add(id);
batchUpdateMap.put(result,idList);
}
}
for (Map.Entry<String, String> entry:executePerformanceIdMap.entrySet()){
String id = entry.getKey();
String result = entry.getValue();
if(batchUpdateMap.containsKey(result)){
batchUpdateMap.get(result).add(id);
}else {
List<String> idList = new ArrayList<>();
idList.add(id);
batchUpdateMap.put(result,idList);
}
}
for(Map.Entry<String,List<String>> entry : batchUpdateMap.entrySet()){
String status = entry.getKey();
List<String> ids = entry.getValue();
if(CollectionUtils.isEmpty(ids)){
continue;
}
int updateCount = this.testPlanReportResourceService.updateExecuteResultByReportIdAndResourceIds(status,planReportId,ids);
testPlanLog.info("ReportId["+planReportId+"] Update Execute Result. Update datas count is :["+updateCount+"]; Update Status:["+status+"],Update ids :["+JSONArray.toJSONString(ids)+"] ");
}
boolean apiCaseExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId,TestPlanResourceType.API_CASE.name(),TestPlanApiExecuteStatus.RUNNING.name()) == 0;
boolean scenarioExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId,TestPlanResourceType.SCENARIO_CASE.name(),TestPlanApiExecuteStatus.RUNNING.name()) == 0;
boolean performanceExecuteOk = testPlanReportResourceService.countByReportIdAndResourceTypeAndExecuteResultEquals(planReportId,TestPlanResourceType.PERFORMANCE_CASE.name(),TestPlanApiExecuteStatus.RUNNING.name()) == 0;;
testPlanLog.info("ReportId["+planReportId+"] count over. Testplan Execute Result: Api is over ->"+apiCaseExecuteOk+"; scenario is over ->"+scenarioExecuteOk+"; performance is over ->"+performanceExecuteOk);
TestPlanReportDataWithBLOBs reportData = reportDataList.get(0);
boolean apiCaseExecuteOk = true;
try {
JSONArray executeArr = JSONArray.parseArray(reportData.getApiCaseInfo());
JSONArray newArr = new JSONArray();
for (int i = 0; i < executeArr.size(); i++) {
JSONObject caseInfo = executeArr.getJSONObject(i);
if (caseInfo.containsKey("id") && caseInfo.containsKey("status")) {
if (MapUtils.isNotEmpty(executeApiCaseIdMap)) {
String id = caseInfo.getString("id");
String status = caseInfo.getString("status");
String updateStatus = executeApiCaseIdMap.get(id);
if (StringUtils.isNotEmpty(updateStatus)
&& !StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name(), TestPlanApiExecuteStatus.FAILD.name())) {
caseInfo.put("status", updateStatus);
}
}
if (StringUtils.equals(TestPlanApiExecuteStatus.RUNNING.name(), caseInfo.getString("status"))) {
apiCaseExecuteOk = false;
}
newArr.add(caseInfo);
}
}
reportData.setApiCaseInfo(newArr.toJSONString());
} catch (Exception e) {
}
boolean scenarioExecuteOk = true;
try {
JSONArray executeArr = JSONArray.parseArray(reportData.getScenarioInfo());
JSONArray newArr = new JSONArray();
for (int i = 0; i < executeArr.size(); i++) {
JSONObject caseInfo = executeArr.getJSONObject(i);
if (caseInfo.containsKey("id") && caseInfo.containsKey("status")) {
if (MapUtils.isNotEmpty(executeScenarioCaseIdMap)) {
String id = caseInfo.getString("id");
String status = caseInfo.getString("status");
String updateStatus = executeScenarioCaseIdMap.get(id);
if (StringUtils.isNotEmpty(updateStatus)
&& !StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name(), TestPlanApiExecuteStatus.FAILD.name())) {
caseInfo.put("status", updateStatus);
}
}
if (StringUtils.equals(TestPlanApiExecuteStatus.RUNNING.name(), caseInfo.getString("status"))) {
scenarioExecuteOk = false;
}
newArr.add(caseInfo);
}
}
reportData.setScenarioInfo(newArr.toJSONString());
} catch (Exception e) {
}
boolean performanceExecuteOk = true;
try {
JSONArray executeArr = JSONArray.parseArray(reportData.getPerformanceInfo());
JSONArray newArr = new JSONArray();
for (int i = 0; i < executeArr.size(); i++) {
JSONObject caseInfo = executeArr.getJSONObject(i);
if (caseInfo.containsKey("id") && caseInfo.containsKey("status")) {
if (MapUtils.isNotEmpty(executePerformanceIdMap)) {
String id = caseInfo.getString("id");
String status = caseInfo.getString("status");
String updateStatus = executePerformanceIdMap.get(id);
if (StringUtils.isNotEmpty(updateStatus)
&& !StringUtils.equalsAnyIgnoreCase(status, TestPlanApiExecuteStatus.SUCCESS.name(), TestPlanApiExecuteStatus.FAILD.name())) {
caseInfo.put("status", updateStatus);
}
}
if (StringUtils.equals(TestPlanApiExecuteStatus.RUNNING.name(), caseInfo.getString("status"))) {
performanceExecuteOk = false;
}
newArr.add(caseInfo);
}
}
reportData.setPerformanceInfo(newArr.toJSONString());
} catch (Exception e) {
}
testPlanLog.info("ReportId["+planReportId+"] count over. Execute result: Api ->"+reportData.getApiCaseInfo()+"; scenario->"+reportData.getScenarioInfo()+"; performance->"+reportData.getPerformanceInfo());
SqlSession sqlSession = sqlSessionFactory.openSession(false);
TestPlanReportDataMapper updateReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class);
updateReportDataMapper.updateByPrimaryKeySelective(reportData);
sqlSession.commit();
sqlSession.flushStatements();
// SqlSession sqlSession = sqlSessionFactory.openSession(false);
// TestPlanReportDataMapper updateReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class);
// updateReportDataMapper.updateByPrimaryKeySelective(reportData);
// sqlSession.commit();
// sqlSession.flushStatements();
this.updateReport(reportData, apiCaseExecuteOk, scenarioExecuteOk, performanceExecuteOk);
report = this.updateReport(reportData, apiCaseExecuteOk, scenarioExecuteOk, performanceExecuteOk,updateTime);
}else {
testPlanLog.info("ReportId["+planReportId+"] CANNOT FIND REPORT! Execited result. api :"+JSONObject.toJSONString(executeApiCaseIdMap)+"; scenario:"+JSONObject.toJSONString(executeScenarioCaseIdMap)+"; performance:"+JSONObject.toJSONString(executePerformanceIdMap));
}
return report;
}
}

View File

@ -43,3 +43,18 @@ CREATE TABLE IF NOT EXISTS `api_load_test` (
-- 添加版本号
ALTER TABLE api_test_case
ADD version INT(10) DEFAULT 0 NULL COMMENT '版本号';
-- 测试计划资源表
CREATE TABLE IF NOT EXISTS test_plan_report_resource (
`id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`test_plan_report_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`resource_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`resource_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`execute_result` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `test_plan_report_id`(`test_plan_report_id`) USING BTREE,
INDEX `resource_id`(`resource_id`) USING BTREE,
INDEX `resource_type`(`resource_type`) USING BTREE,
INDEX `report_resource_id`(`test_plan_report_id`,`resource_id`) USING BTREE,
INDEX `report_resource_type_id`(`test_plan_report_id`,`resource_id`,`resource_type`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

View File

@ -84,7 +84,7 @@
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->
<table tableName="api_scenario_reference_id"></table>
<table tableName="test_plan_report_resource"></table>
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="api_test_case"></table>-->
<!-- <table tableName="api_definition"></table>-->