fix: 添加测试环境,查询测试计划下性能测试
This commit is contained in:
parent
e451248e25
commit
7d33f66a26
|
@ -10,4 +10,10 @@ public class RunCaseRequest {
|
|||
private String caseId;
|
||||
|
||||
private String reportId;
|
||||
|
||||
private String runMode;
|
||||
|
||||
private String environmentId;
|
||||
|
||||
private String testPlanId;
|
||||
}
|
||||
|
|
|
@ -109,8 +109,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
sampler.setFollowRedirects(this.isFollowRedirects());
|
||||
sampler.setUseKeepAlive(true);
|
||||
sampler.setDoMultipart(this.isDoMultipartPost());
|
||||
|
||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
if(config != null && config.getConfig() != null){
|
||||
config.setConfig(config.getConfig());
|
||||
}else{
|
||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
}
|
||||
|
||||
// 添加环境中的公共变量
|
||||
Arguments arguments = this.addArguments(config);
|
||||
|
|
|
@ -165,7 +165,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
apiReportService.complete(testResult, report);
|
||||
} else if (StringUtils.equals(this.runMode, ApiRunMode.DELIMIT.name())) {
|
||||
// 调试操作,不需要存储结果
|
||||
if (StringUtils.isBlank(debugReportId)) {
|
||||
if (!StringUtils.isBlank(debugReportId)) {
|
||||
apiDefinitionService.addResult(testResult);
|
||||
} else {
|
||||
apiDefinitionService.addResult(testResult);
|
||||
|
|
|
@ -395,6 +395,9 @@ public class ApiAutomationService {
|
|||
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name())) {
|
||||
runMode = ApiRunMode.SCENARIO_PLAN.name();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.DELIMIT.name())) {
|
||||
runMode = ApiRunMode.DELIMIT.name();
|
||||
}
|
||||
// 调用执行方法
|
||||
jMeterService.runDefinition(request.getId(), jmeterHashTree, request.getReportId(), runMode);
|
||||
return request.getId();
|
||||
|
|
|
@ -13,13 +13,11 @@ import io.metersphere.api.dto.definition.request.MsTestPlan;
|
|||
import io.metersphere.api.dto.definition.request.MsThreadGroup;
|
||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.jmeter.JMeterService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ApiTestFileMapper;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
||||
|
@ -73,7 +71,9 @@ public class ApiTestCaseService {
|
|||
@Resource
|
||||
private JMeterService jMeterService;
|
||||
@Resource
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
TestPlanApiCaseMapper testPlanApiCaseMapper;
|
||||
|
||||
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
|
||||
|
||||
|
@ -84,10 +84,10 @@ public class ApiTestCaseService {
|
|||
|
||||
public List<ApiTestCaseDTO> listSimple(ApiTestCaseRequest request) {
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
if(request.isSelectThisWeedData()){
|
||||
if (request.isSelectThisWeedData()) {
|
||||
Map<String, Date> weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date());
|
||||
Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime");
|
||||
if(weekFirstTime!=null){
|
||||
if (weekFirstTime != null) {
|
||||
request.setCreateTime(weekFirstTime.getTime());
|
||||
}
|
||||
}
|
||||
|
@ -434,6 +434,7 @@ public class ApiTestCaseService {
|
|||
|
||||
public String run(RunCaseRequest request) {
|
||||
ApiTestCaseWithBLOBs testCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getCaseId());
|
||||
|
||||
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
||||
if (testCaseWithBLOBs != null && StringUtils.isNotEmpty(testCaseWithBLOBs.getRequest())) {
|
||||
try {
|
||||
|
@ -441,7 +442,16 @@ public class ApiTestCaseService {
|
|||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
MsTestElement element = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference<MsTestElement>() {
|
||||
});
|
||||
element.setName(request.getCaseId());
|
||||
if(StringUtils.isBlank(request.getEnvironmentId())){
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria().andTestPlanIdEqualTo(request.getTestPlanId()).andApiCaseIdEqualTo(request.getCaseId());
|
||||
List<TestPlanApiCase> list=testPlanApiCaseMapper.selectByExample(example);
|
||||
request.setEnvironmentId(list.get(0).getEnvironmentId());
|
||||
element.setName(list.get(0).getId());
|
||||
}else{
|
||||
element.setName(request.getCaseId());
|
||||
}
|
||||
|
||||
// 测试计划
|
||||
MsTestPlan testPlan = new MsTestPlan();
|
||||
testPlan.setHashTree(new LinkedList<>());
|
||||
|
@ -456,10 +466,14 @@ public class ApiTestCaseService {
|
|||
hashTrees.add(element);
|
||||
group.setHashTree(hashTrees);
|
||||
testPlan.getHashTree().add(group);
|
||||
|
||||
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig());
|
||||
|
||||
String runMode = ApiRunMode.DELIMIT.name();
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(request.getEnvironmentId());
|
||||
ParameterConfig parameterConfig=new ParameterConfig();
|
||||
if (environment != null && environment.getConfig() != null) {
|
||||
parameterConfig.setConfig( JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class));
|
||||
}
|
||||
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), parameterConfig);
|
||||
String runMode = request.getRunMode();
|
||||
// 调用执行方法
|
||||
jMeterService.runDefinition(request.getReportId(), jmeterHashTree, request.getReportId(), runMode);
|
||||
|
||||
|
|
|
@ -105,7 +105,8 @@
|
|||
</sql>
|
||||
|
||||
<select id="getTestCaseByNotInReview" resultType="io.metersphere.base.domain.TestCase">
|
||||
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status from test_case as test_case
|
||||
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status from test_case
|
||||
as test_case
|
||||
left join test_case_review_test_case as T2 on test_case.id=T2.case_id and T2.review_id =#{request.reviewId}
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
|
@ -159,7 +160,8 @@
|
|||
</select>
|
||||
|
||||
<select id="getTestCaseByNotInPlan" resultType="io.metersphere.base.domain.TestCase">
|
||||
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status from test_case as test_case
|
||||
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status from test_case
|
||||
as test_case
|
||||
left join test_plan_test_case as T2 on test_case.id=T2.case_id and T2.plan_id =#{request.planId}
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
|
@ -265,7 +267,8 @@
|
|||
</select>
|
||||
|
||||
<select id="list" resultType="io.metersphere.track.dto.TestCaseDTO">
|
||||
select <include refid="io.metersphere.base.mapper.TestCaseMapper.Base_Column_List"/>
|
||||
select
|
||||
<include refid="io.metersphere.base.mapper.TestCaseMapper.Base_Column_List"/>
|
||||
from test_case
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
|
@ -275,7 +278,8 @@
|
|||
</include>
|
||||
</if>
|
||||
<if test="request.name != null">
|
||||
and (test_case.name like CONCAT('%', #{request.name},'%') or test_case.num like CONCAT('%', #{request.name},'%'))
|
||||
and (test_case.name like CONCAT('%', #{request.name},'%') or test_case.num like CONCAT('%',
|
||||
#{request.name},'%'))
|
||||
</if>
|
||||
<if test="request.nodeIds != null and request.nodeIds.size() > 0">
|
||||
and test_case.node_id in
|
||||
|
@ -342,16 +346,23 @@
|
|||
</where>
|
||||
UNION ALL
|
||||
select id,name,project_id,"scenario" as type from api_scenario
|
||||
|
||||
<where>
|
||||
<if test="request.projectId!=null">
|
||||
and project_id= #{request.projectId}
|
||||
</if>
|
||||
</where>
|
||||
and api_scenario.status!='Trash'
|
||||
UNION ALL
|
||||
select id,name,project_id,"definition" as type from api_test_case
|
||||
select b.id,b.name,b.project_id,"definition" as type from api_test_case b
|
||||
inner join
|
||||
api_definition a
|
||||
on
|
||||
b.api_definition_id = a.id
|
||||
and a.status != 'Trash'
|
||||
<where>
|
||||
<if test="request.projectId!=null">
|
||||
and project_id= #{request.projectId}
|
||||
and b.project_id= #{request.projectId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
@ -378,7 +389,11 @@
|
|||
</select>
|
||||
|
||||
<select id="getMaxNumByProjectId" resultType="io.metersphere.base.domain.TestCase">
|
||||
SELECT * FROM test_case WHERE test_case.project_id = #{projectId} ORDER BY num DESC LIMIT 1;
|
||||
SELECT *
|
||||
FROM test_case
|
||||
WHERE test_case.project_id = #{projectId}
|
||||
ORDER BY num DESC
|
||||
LIMIT 1;
|
||||
</select>
|
||||
|
||||
<select id="checkIsHave" resultType="int">
|
||||
|
|
|
@ -366,6 +366,15 @@
|
|||
</if>
|
||||
</where>
|
||||
UNION ALL
|
||||
select load_test.id as id,"perform" as type,load_test.name as name,test_plan_load_case.status from test_plan_load_case inner join
|
||||
load_test on
|
||||
test_plan_load_case.load_case_id =load_test.id
|
||||
<where>
|
||||
<if test="request.planId != null">
|
||||
and test_plan_load_case.test_plan_id = #{request.planId}
|
||||
</if>
|
||||
</where>
|
||||
UNION ALL
|
||||
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
|
||||
<where>
|
||||
|
|
Loading…
Reference in New Issue