feat(测试跟踪): 测试计划支持禁用本地执行
--story=1009842 --user=赵勇 接口测试支持禁用本地执行 https://www.tapd.cn/55049933/s/1291450
This commit is contained in:
parent
209053d7ed
commit
3515df5519
|
@ -21,6 +21,8 @@ public class BatchRunDefinitionRequest {
|
|||
|
||||
private String userId;
|
||||
|
||||
private String projectId;
|
||||
|
||||
//测试计划报告ID。 测试计划执行时使用
|
||||
private String planReportId;
|
||||
// 失败重跑
|
||||
|
|
|
@ -2,23 +2,17 @@ package io.metersphere.service;
|
|||
|
||||
import io.metersphere.api.dto.plugin.PluginDTO;
|
||||
import io.metersphere.api.dto.plugin.PluginRequest;
|
||||
import io.metersphere.api.dto.plugin.PluginResourceDTO;
|
||||
import io.metersphere.base.domain.Plugin;
|
||||
import io.metersphere.base.domain.PluginExample;
|
||||
import io.metersphere.base.domain.PluginWithBLOBs;
|
||||
import io.metersphere.base.mapper.PluginMapper;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.FileUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.plugin.core.ui.PluginResource;
|
||||
import io.metersphere.commons.utils.CommonUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
|
@ -33,50 +27,6 @@ public class PluginService {
|
|||
@Resource
|
||||
private PluginMapper pluginMapper;
|
||||
|
||||
public String editPlugin(MultipartFile file) {
|
||||
String id = UUID.randomUUID().toString();
|
||||
String path = FileUtils.create(id, file);
|
||||
if (StringUtils.isNotEmpty(path)) {
|
||||
List<PluginResourceDTO> resources = this.getMethod(path, file.getOriginalFilename());
|
||||
if (CollectionUtils.isNotEmpty(resources)) {
|
||||
for (PluginResourceDTO resource : resources) {
|
||||
PluginExample example = new PluginExample();
|
||||
example.createCriteria().andPluginIdEqualTo(resource.getPluginId());
|
||||
List<Plugin> plugins = pluginMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(plugins)) {
|
||||
String delPath = plugins.get(0).getSourcePath();
|
||||
// this.closeJar(delPath);
|
||||
FileUtils.deleteFile(delPath);
|
||||
pluginMapper.deleteByExample(example);
|
||||
}
|
||||
this.create(resource, path, file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void create(PluginResourceDTO resource, String path, String name) {
|
||||
resource.getUiScripts().forEach(item -> {
|
||||
PluginWithBLOBs plugin = new PluginWithBLOBs();
|
||||
plugin.setId(UUID.randomUUID().toString());
|
||||
plugin.setCreateTime(System.currentTimeMillis());
|
||||
plugin.setUpdateTime(System.currentTimeMillis());
|
||||
plugin.setName(item.getName());
|
||||
plugin.setPluginId(resource.getPluginId());
|
||||
plugin.setScriptId(item.getId());
|
||||
plugin.setSourcePath(path);
|
||||
plugin.setFormOption(item.getFormOption());
|
||||
plugin.setFormScript(item.getFormScript());
|
||||
plugin.setClazzName(item.getClazzName());
|
||||
plugin.setSourceName(name);
|
||||
plugin.setJmeterClazz(item.getJmeterClazz());
|
||||
plugin.setExecEntry(resource.getEntry());
|
||||
plugin.setCreateUserId(SessionUtils.getUserId());
|
||||
pluginMapper.insert(plugin);
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isXpack(Class<?> aClass, Object instance) {
|
||||
try {
|
||||
Object verify = aClass.getDeclaredMethod("xpack").invoke(instance);
|
||||
|
@ -86,28 +36,6 @@ public class PluginService {
|
|||
}
|
||||
}
|
||||
|
||||
private List<PluginResourceDTO> getMethod(String path, String fileName) {
|
||||
List<PluginResourceDTO> resources = new LinkedList<>();
|
||||
this.loadJar(path);
|
||||
List<Class<?>> classes = CommonUtil.getSubClass(fileName);
|
||||
try {
|
||||
for (Class<?> aClass : classes) {
|
||||
Object instance = aClass.newInstance();
|
||||
Object pluginObj = aClass.getDeclaredMethod("init").invoke(instance);
|
||||
if (pluginObj != null) {
|
||||
PluginResourceDTO pluginResourceDTO = new PluginResourceDTO();
|
||||
BeanUtils.copyBean(pluginResourceDTO, (PluginResource) pluginObj);
|
||||
pluginResourceDTO.setEntry(aClass.getName());
|
||||
resources.add(pluginResourceDTO);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error("初始化脚本异常:" + e.getMessage());
|
||||
MSException.throwException("调用插件初始化脚本失败");
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
private boolean loadJar(String jarPath) {
|
||||
try {
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.api.dto.plan.TestPlanApiCaseBatchRequest;
|
|||
import io.metersphere.api.dto.plan.TestPlanApiCaseInfoDTO;
|
||||
import io.metersphere.api.exec.api.ApiCaseExecuteService;
|
||||
import io.metersphere.api.exec.api.ApiExecuteService;
|
||||
import io.metersphere.api.jmeter.JMeterService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
|
@ -88,12 +89,8 @@ public class TestPlanApiCaseService {
|
|||
private ApiExecuteService apiExecuteService;
|
||||
@Resource
|
||||
private TestPlanService testPlanService;
|
||||
|
||||
public TestPlanApiCase getInfo(String caseId, String testPlanId) {
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria().andApiCaseIdEqualTo(caseId).andTestPlanIdEqualTo(testPlanId);
|
||||
return testPlanApiCaseMapper.selectByExample(example).get(0);
|
||||
}
|
||||
@Resource
|
||||
private JMeterService jMeterService;
|
||||
|
||||
public List<TestPlanApiCaseDTO> list(ApiTestCaseRequest request) {
|
||||
request.setProjectId(null);
|
||||
|
@ -299,7 +296,7 @@ public class TestPlanApiCaseService {
|
|||
ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
|
||||
testCaseExample.createCriteria().andIdIn(nodes.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()));
|
||||
List<ApiTestCase> testCases = apiTestCaseMapper.selectByExample(testCaseExample);
|
||||
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(testCases)) {
|
||||
if (CollectionUtils.isNotEmpty(testCases)) {
|
||||
List<String> names = testCases.stream().map(ApiTestCase::getName).collect(Collectors.toList());
|
||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), testCases.get(0).getProjectId(), String.join(",", names), nodes.get(0).getCreateUser(), new LinkedList<>());
|
||||
return JSON.toJSONString(details);
|
||||
|
@ -316,6 +313,7 @@ public class TestPlanApiCaseService {
|
|||
*/
|
||||
public List<MsExecResponseDTO> run(BatchRunDefinitionRequest request) {
|
||||
if (request.getConfig() != null) {
|
||||
jMeterService.verifyPool(request.getProjectId(), request.getConfig());
|
||||
return testPlanApiCaseExecuteService.run(request);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.api.dto.automation.ApiScenarioReportResult;
|
|||
import io.metersphere.api.dto.automation.*;
|
||||
import io.metersphere.api.dto.plan.*;
|
||||
import io.metersphere.api.exec.scenario.ApiScenarioEnvService;
|
||||
import io.metersphere.api.jmeter.JMeterService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
|
||||
|
@ -103,6 +104,8 @@ public class TestPlanScenarioCaseService {
|
|||
private ApiScenarioModuleService apiScenarioModuleService;
|
||||
@Resource
|
||||
private TestPlanService testPlanService;
|
||||
@Resource
|
||||
private JMeterService jMeterService;
|
||||
|
||||
public List<ApiScenarioDTO> list(TestPlanScenarioRequest request) {
|
||||
request.setProjectId(null);
|
||||
|
@ -272,6 +275,8 @@ public class TestPlanScenarioCaseService {
|
|||
this.setScenarioEnv(new ArrayList<>(), planCaseIdList, testPlanScenarioRequest.getConfig());
|
||||
}
|
||||
}
|
||||
jMeterService.verifyPool(testPlanScenarioRequest.getProjectId(), testPlanScenarioRequest.getConfig());
|
||||
|
||||
planCaseIdList.forEach(item -> {
|
||||
idStr.append("\"").append(item).append("\"").append(",");
|
||||
});
|
||||
|
|
|
@ -2048,6 +2048,7 @@ public class ApiScenarioService {
|
|||
}
|
||||
|
||||
public List<MsExecResponseDTO> run(RunScenarioRequest request) {
|
||||
jMeterService.verifyPool(request.getProjectId(), request.getConfig());
|
||||
return apiScenarioExecuteService.run(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -624,7 +624,7 @@ export default {
|
|||
});
|
||||
},
|
||||
handleRunBatch(config) {
|
||||
let obj = {planIds: this.testPlanCaseIds, config: config, triggerMode: "BATCH"};
|
||||
let obj = {planIds: this.testPlanCaseIds, config: config, triggerMode: "BATCH",projectId: getCurrentProjectID()};
|
||||
testPlanApiCaseRun(obj)
|
||||
.then(() => {
|
||||
this.$message(this.$t('commons.run_message'));
|
||||
|
|
|
@ -470,6 +470,7 @@ export default {
|
|||
param.condition = selectParam.condition;
|
||||
param.triggerMode = "BATCH";
|
||||
param.requestOriginator = "TEST_PLAN";
|
||||
param.projectId = this.projectId;
|
||||
testPlanScenarioCaseRun(param)
|
||||
.then(() => {
|
||||
this.$message(this.$t('commons.run_message'));
|
||||
|
@ -485,6 +486,7 @@ export default {
|
|||
this.buildExecuteParam(param, row);
|
||||
param.triggerMode = "MANUAL";
|
||||
param.requestOriginator = "TEST_PLAN";
|
||||
param.projectId = this.projectId;
|
||||
param.config = {
|
||||
mode: "serial"
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue