fix(接口自动化): 接口用例执行修改

This commit is contained in:
fit2-zhao 2020-12-31 16:12:22 +08:00
parent 221f0e2048
commit 6dd2f72c05
1 changed files with 24 additions and 3 deletions

View File

@ -8,6 +8,9 @@ import io.metersphere.api.dto.ApiCaseBatchRequest;
import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.MsTestElement;
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.jmeter.JMeterService; import io.metersphere.api.jmeter.JMeterService;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiDefinitionMapper;
@ -30,6 +33,7 @@ import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.ListedHashTree;
import org.aspectj.util.FileUtil; import org.aspectj.util.FileUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -400,11 +404,28 @@ public class ApiTestCaseService {
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MsTestElement elements = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference<MsTestElement>() { }); MsTestElement element = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference<MsTestElement>() {
HashTree hashTree = elements.generateHashTree(); });
// 测试计划
MsTestPlan testPlan = new MsTestPlan();
testPlan.setHashTree(new LinkedList<>());
HashTree jmeterHashTree = new ListedHashTree();
// 线程组
MsThreadGroup group = new MsThreadGroup();
group.setLabel(testCaseWithBLOBs.getName());
group.setName(testCaseWithBLOBs.getId());
LinkedList<MsTestElement> hashTrees = new LinkedList<>();
hashTrees.add(element);
group.setHashTree(hashTrees);
testPlan.getHashTree().add(group);
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig());
String runMode = ApiRunMode.DELIMIT.name(); String runMode = ApiRunMode.DELIMIT.name();
// 调用执行方法 // 调用执行方法
jMeterService.runDefinition(request.getReportId(), hashTree, request.getReportId(), runMode); jMeterService.runDefinition(request.getReportId(), jmeterHashTree, request.getReportId(), runMode);
} catch (Exception ex) { } catch (Exception ex) {
LogUtil.error(ex.getMessage()); LogUtil.error(ex.getMessage());