This commit is contained in:
chenjianxing 2021-01-08 14:42:17 +08:00
commit c62adcfc32
8 changed files with 64 additions and 30 deletions

View File

@ -103,4 +103,8 @@ public class ApiTestCaseController {
public String jenkinsRun(@RequestBody RunCaseRequest request) { public String jenkinsRun(@RequestBody RunCaseRequest request) {
return apiTestCaseService.run(request); return apiTestCaseService.run(request);
} }
@GetMapping(value = "/jenkins/exec/result/{id}")
public String getExecResult(@PathVariable String id) {
return apiTestCaseService.getExecResult(id);
}
} }

View File

@ -13,6 +13,7 @@ import io.metersphere.api.dto.definition.request.MsThreadGroup;
import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.jmeter.JMeterService; import io.metersphere.api.jmeter.JMeterService;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiDefinitionMapper;
import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ApiTestCaseMapper;
import io.metersphere.base.mapper.ApiTestFileMapper; import io.metersphere.base.mapper.ApiTestFileMapper;
@ -68,6 +69,8 @@ public class ApiTestCaseService {
private ApiDefinitionMapper apiDefinitionMapper; private ApiDefinitionMapper apiDefinitionMapper;
@Resource @Resource
private JMeterService jMeterService; private JMeterService jMeterService;
@Resource
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
@ -406,6 +409,7 @@ public class ApiTestCaseService {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MsTestElement element = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference<MsTestElement>() { MsTestElement element = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference<MsTestElement>() {
}); });
element.setName(request.getCaseId());
// 测试计划 // 测试计划
MsTestPlan testPlan = new MsTestPlan(); MsTestPlan testPlan = new MsTestPlan();
testPlan.setHashTree(new LinkedList<>()); testPlan.setHashTree(new LinkedList<>());
@ -434,4 +438,11 @@ public class ApiTestCaseService {
return request.getReportId(); return request.getReportId();
} }
public String getExecResult(String id){
ApiDefinitionExecResultExample apidefinitionexecresultexample = new ApiDefinitionExecResultExample();
ApiDefinitionExecResultExample.Criteria criteria = apidefinitionexecresultexample.createCriteria();
criteria.andResourceIdEqualTo(id);
String status=apiDefinitionExecResultMapper.selectByExample(apidefinitionexecresultexample).get(0).getStatus();
return status;
}
} }

View File

@ -195,12 +195,6 @@
AND atc.api_definition_id = #{request.apiDefinitionId} AND atc.api_definition_id = #{request.apiDefinitionId}
</if> </if>
</where> </where>
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
atc.${order.name} ${order.type}
</foreach>
</if>
</select> </select>
<select id="listSimple" resultType="io.metersphere.api.dto.definition.ApiTestCaseDTO"> <select id="listSimple" resultType="io.metersphere.api.dto.definition.ApiTestCaseDTO">

View File

@ -320,21 +320,28 @@
</if> </if>
</select> </select>
<select id="listByMethod" resultType="io.metersphere.track.dto.TestCaseDTO"> <select id="listByMethod" resultType="io.metersphere.track.dto.TestCaseDTO">
SELECT id,name,status,project_id,"api" as type from api_test SELECT id,name,project_id,"api" as type from api_test
<where> <where>
<if test="request.projectId!=null"> <if test="request.projectId!=null">
and project_id=#{request.projectId} and project_id=#{request.projectId}
</if> </if>
</where> </where>
UNION ALL UNION ALL
select id,name,status,project_id,"perform" as type from load_test select id,name,project_id,"perform" as type from load_test
<where> <where>
<if test="request.projectId!=null"> <if test="request.projectId!=null">
and project_id= #{request.projectId} and project_id= #{request.projectId}
</if> </if>
</where> </where>
UNION ALL UNION ALL
select id,name,status,project_id,"scenario" as type from api_scenario select id,name,project_id,"scenario" as type from api_scenario
<where>
<if test="request.projectId!=null">
and project_id= #{request.projectId}
</if>
</where>
UNION ALL
select id,name,project_id,"definition" as type from api_test_case
<where> <where>
<if test="request.projectId!=null"> <if test="request.projectId!=null">
and project_id= #{request.projectId} and project_id= #{request.projectId}

View File

@ -23,7 +23,7 @@
from from
test_plan_api_case t test_plan_api_case t
inner join inner join
api_test_case c api_test_case c
on t.api_case_id = c.id on t.api_case_id = c.id
<if test="request.planId != null and request.planId!=''"> <if test="request.planId != null and request.planId!=''">
and t.test_plan_id = #{request.planId} and t.test_plan_id = #{request.planId}

View File

@ -106,18 +106,18 @@
resultType="io.metersphere.track.dto.TestCaseReportStatusResultDTO"> resultType="io.metersphere.track.dto.TestCaseReportStatusResultDTO">
select count(t1.id) as `count`, t1.status select count(t1.id) as `count`, t1.status
from test_plan_test_case t1 from test_plan_test_case t1
inner join test_case t2 inner join test_case t2
where t1.case_id = t2.id where t1.case_id = t2.id
and plan_id = #{planId} and plan_id = #{planId}
group by t1.status; group by t1.status;
</select> </select>
<select id="getExecutors" resultType="java.lang.String" parameterType="java.lang.String"> <select id="getExecutors" resultType="java.lang.String" parameterType="java.lang.String">
select distinct t1.executor select distinct t1.executor
from test_plan_test_case t1 from test_plan_test_case t1
inner join test_case t2 inner join test_case t2
where t1.case_id = t2.id where t1.case_id = t2.id
and plan_id = #{planId}; and plan_id = #{planId};
</select> </select>
<select id="list" resultType="io.metersphere.track.dto.TestPlanCaseDTO"> <select id="list" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
@ -320,31 +320,46 @@
</select> </select>
<select id="get" resultType="io.metersphere.track.dto.TestPlanCaseDTO"> <select id="get" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
select test_case.remark, test_plan_test_case.id as id, test_plan_test_case.*,test_case.*,test_case_node.name as model, project.name as projectName select test_case.remark,
test_plan_test_case.id as id,
test_plan_test_case.*,
test_case.*,
test_case_node.name as model,
project.name as projectName
from test_plan_test_case from test_plan_test_case
inner join test_case on test_plan_test_case.case_id = test_case.id inner join test_case on test_plan_test_case.case_id = test_case.id
left join test_case_node on test_case_node.id=test_case.node_id left join test_case_node on test_case_node.id = test_case.node_id
inner join project on project.id = test_case.project_id inner join project on project.id = test_case.project_id
where test_plan_test_case.id = #{testPlanTestCaseId} where test_plan_test_case.id = #{testPlanTestCaseId}
</select> </select>
<select id="getExecResultByPlanId" resultType="java.lang.String"> <select id="getExecResultByPlanId" resultType="java.lang.String">
select status select status
from from test_plan_test_case
test_plan_test_case where plan_id = #{planId}
where plan_id = #{planId}
</select> </select>
<select id="listByPlanId" resultType="io.metersphere.track.dto.TestPlanCaseDTO"> <select id="listByPlanId" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
SELECT test_plan_api_case.api_case_id as id,"definition" as type,api_test_case.name,test_plan_api_case.status SELECT test_plan_api_case.api_case_id as id,"definition" as type,api_test_case.name,test_plan_api_case.status
from test_plan_api_case left join api_test_case on test_plan_api_case.api_case_id=api_test_case.id from test_plan_api_case left join api_test_case on test_plan_api_case.api_case_id=api_test_case.id
inner join
api_definition a
on
api_test_case.api_definition_id = a.id
and a.status != 'Trash'
<where> <where>
<if test="request.planId != null"> <if test="request.planId != null">
and test_plan_api_case.test_plan_id = #{request.planId} and test_plan_api_case.test_plan_id = #{request.planId}
</if> </if>
</where> </where>
UNION ALL UNION ALL
SELECT test_plan_api_scenario.api_scenario_id as id,"scenario" as type,api_scenario.name,test_plan_api_scenario.status SELECT test_plan_api_scenario.api_scenario_id as id,"scenario" as
from test_plan_api_scenario left join api_scenario on test_plan_api_scenario.api_scenario_id=api_scenario.id type,api_scenario.name,test_plan_api_scenario.status
from test_plan_api_scenario
left join
api_scenario
on
test_plan_api_scenario.api_scenario_id=api_scenario.id
and api_scenario.status != 'Trash'
<where> <where>
<if test="request.planId != null"> <if test="request.planId != null">
and test_plan_api_scenario.test_plan_id = #{request.planId} and test_plan_api_scenario.test_plan_id = #{request.planId}
@ -352,7 +367,7 @@
</where> </where>
UNION ALL UNION ALL
SELECT test_case.test_id as id,test_case.type as type,test_case.name,test_plan_test_case.status SELECT test_case.test_id as id,test_case.type as type,test_case.name,test_plan_test_case.status
from test_plan_test_case left join test_case on test_plan_test_case.case_id =test_case.id from test_plan_test_case left join test_case on test_plan_test_case.case_id =test_case.id
<where> <where>
<if test="request.planId != null"> <if test="request.planId != null">
and test_plan_test_case.plan_id = #{request.planId} and test_plan_test_case.plan_id = #{request.planId}
@ -377,6 +392,8 @@
</update> </update>
<delete id="deleteByTestCaseID" parameterType="java.lang.String"> <delete id="deleteByTestCaseID" parameterType="java.lang.String">
delete from test_plan_api_case where api_case_id = #{id,jdbcType=VARCHAR} delete
from test_plan_api_case
where api_case_id = #{id,jdbcType=VARCHAR}
</delete> </delete>
</mapper> </mapper>

View File

@ -46,7 +46,7 @@ public class TestPlanController {
/*jenkins测试计划*/ /*jenkins测试计划*/
@GetMapping("/list/all/{projectId}/{workspaceId}") @GetMapping("/list/all/{projectId}/{workspaceId}")
public List<TestPlanDTO> listByProjectId(@PathVariable String projectId, @PathVariable String workspaceId) { public List<TestPlanDTOWithMetric> listByProjectId(@PathVariable String projectId, @PathVariable String workspaceId) {
QueryTestPlanRequest request = new QueryTestPlanRequest(); QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setWorkspaceId(workspaceId); request.setWorkspaceId(workspaceId);
request.setProjectId(projectId); request.setProjectId(projectId);

View File

@ -379,8 +379,9 @@ public class TestPlanService {
return testPlans; return testPlans;
} }
public List<TestPlanDTO> listTestPlanByProject(QueryTestPlanRequest request) { public List<TestPlanDTOWithMetric> listTestPlanByProject(QueryTestPlanRequest request) {
return extTestPlanMapper.planList(request); List<TestPlanDTOWithMetric> testPlans=extTestPlanMapper.list(request);
return testPlans;
} }
public void testPlanRelevance(PlanCaseRelevanceRequest request) { public void testPlanRelevance(PlanCaseRelevanceRequest request) {