refactor(接口测试): jmx场景导入的部分细节调整

This commit is contained in:
Jianguo-Genius 2024-10-15 17:41:56 +08:00 committed by Craftsman
parent a9a4bb7203
commit 9f36f05452
8 changed files with 20 additions and 17 deletions

View File

@ -762,6 +762,7 @@
SELECT id, name SELECT id, name
FROM api_scenario FROM api_scenario
WHERE module_id = #{0} WHERE module_id = #{0}
AND deleted = false
</select> </select>
</mapper> </mapper>

View File

@ -1,6 +1,7 @@
package io.metersphere.api.parser.api.dataimport; package io.metersphere.api.parser.api.dataimport;
import io.metersphere.api.constants.ApiScenarioStatus; import io.metersphere.api.constants.ApiScenarioStatus;
import io.metersphere.api.constants.ApiScenarioStepRefType;
import io.metersphere.api.constants.ApiScenarioStepType; import io.metersphere.api.constants.ApiScenarioStepType;
import io.metersphere.api.dto.request.MsJMeterComponent; import io.metersphere.api.dto.request.MsJMeterComponent;
import io.metersphere.api.dto.request.controller.*; import io.metersphere.api.dto.request.controller.*;
@ -51,6 +52,7 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser {
apiScenarioDetail.setName(scenarioName); apiScenarioDetail.setName(scenarioName);
apiScenarioDetail.setPriority("P0"); apiScenarioDetail.setPriority("P0");
apiScenarioDetail.setStatus(ApiScenarioStatus.UNDERWAY.name()); apiScenarioDetail.setStatus(ApiScenarioStatus.UNDERWAY.name());
apiScenarioDetail.setGrouped(false);
apiScenarioDetail.setDeleted(false); apiScenarioDetail.setDeleted(false);
apiScenarioDetail.setLatest(true); apiScenarioDetail.setLatest(true);
apiScenarioDetail.setProjectId(projectId); apiScenarioDetail.setProjectId(projectId);
@ -72,20 +74,26 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser {
apiScenarioStep.setProjectId(projectId); apiScenarioStep.setProjectId(projectId);
apiScenarioStep.setName(msTestElement.getName()); apiScenarioStep.setName(msTestElement.getName());
apiScenarioStep.setUniqueId(IDGenerator.nextStr()); apiScenarioStep.setUniqueId(IDGenerator.nextStr());
msTestElement.setStepId(apiScenarioStep.getId());
msTestElement.setProjectId(apiScenarioStep.getProjectId());
byte[] stepBlobContent = null; byte[] stepBlobContent = null;
if (msTestElement instanceof MsHTTPElement msHTTPElement) { if (msTestElement instanceof MsHTTPElement msHTTPElement) {
apiScenarioStep.setConfig(JSON.toJSONString(new ProtocolConfig("HTTP", msHTTPElement.getMethod()))); apiScenarioStep.setConfig(new ProtocolConfig("HTTP", msHTTPElement.getMethod()));
apiScenarioStep.setStepType(ApiScenarioStepType.CUSTOM_REQUEST.name()); apiScenarioStep.setStepType(ApiScenarioStepType.CUSTOM_REQUEST.name());
apiScenarioStep.setRefType(ApiScenarioStepRefType.DIRECT.name());
msHTTPElement.setCustomizeRequest(true);
stepBlobContent = JSON.toJSONString(msTestElement).getBytes(); stepBlobContent = JSON.toJSONString(msTestElement).getBytes();
} else if (msTestElement instanceof AbstractMsProtocolTestElement) { } else if (msTestElement instanceof AbstractMsProtocolTestElement msProtocolTestElement) {
apiScenarioStep.setStepType(ApiScenarioStepType.CUSTOM_REQUEST.name()); apiScenarioStep.setStepType(ApiScenarioStepType.CUSTOM_REQUEST.name());
msProtocolTestElement.setCustomizeRequest(true);
String protocol = polymorphicNameMap.get(msTestElement.getClass().getSimpleName()); String protocol = polymorphicNameMap.get(msTestElement.getClass().getSimpleName());
apiScenarioStep.setConfig(JSON.toJSONString(new ProtocolConfig(protocol, protocol))); apiScenarioStep.setConfig(new ProtocolConfig(protocol, protocol));
apiScenarioStep.setRefType(ApiScenarioStepRefType.DIRECT.name());
stepBlobContent = JSON.toJSONString(msTestElement).getBytes(); stepBlobContent = JSON.toJSONString(msTestElement).getBytes();
} else if (msTestElement instanceof MsJMeterComponent) { } else if (msTestElement instanceof MsJMeterComponent) {
apiScenarioStep.setStepType(this.getStepType(msTestElement)); apiScenarioStep.setStepType(this.getStepType(msTestElement));
apiScenarioStep.setConfig("{}"); apiScenarioStep.setConfig(new HashMap<>());
apiScenarioStep.setRefType(ApiScenarioStepRefType.DIRECT.name());
} else { } else {
apiScenarioStep.setStepType(this.getStepType(msTestElement)); apiScenarioStep.setStepType(this.getStepType(msTestElement));
apiScenarioStep.setConfig(JSON.toJSONString(msTestElement)); apiScenarioStep.setConfig(JSON.toJSONString(msTestElement));

View File

@ -54,18 +54,6 @@ public class MsTestElementParser {
return result; return result;
} }
// public List<AbstractMsTestElement> getAbstractMsTestElement(AbstractMsTestElement msTestElement) {
// List<AbstractMsTestElement> result = new ArrayList<>();
// if (msTestElement instanceof AbstractMsProtocolTestElement abstractMsProtocolTestElement) {
// result.add(abstractMsProtocolTestElement);
// } else {
// for (AbstractMsTestElement child : msTestElement.getChildren()) {
// result.addAll(this.getAbstractMsTestElement(child));
// }
// }
// return result;
// }
public Map<String, String> getPolymorphicNameMap(String projectId) { public Map<String, String> getPolymorphicNameMap(String projectId) {
ApiPluginService apiPluginService = CommonBeanFactory.getBean(ApiPluginService.class); ApiPluginService apiPluginService = CommonBeanFactory.getBean(ApiPluginService.class);
assert apiPluginService != null; assert apiPluginService != null;

View File

@ -519,11 +519,13 @@ public class ApiScenarioDataTransferService {
if (modulePathMap.containsKey(modulePath)) { if (modulePathMap.containsKey(modulePath)) {
List<ApiScenario> existenceScenarios = extApiScenarioMapper.selectBaseInfoByModuleId(modulePathMap.get(modulePath).getId()); List<ApiScenario> existenceScenarios = extApiScenarioMapper.selectBaseInfoByModuleId(modulePathMap.get(modulePath).getId());
Map<String, String> existenceNameIdMap = existenceScenarios.stream().collect(Collectors.toMap(ApiScenario::getName, ApiScenario::getId)); Map<String, String> existenceNameIdMap = existenceScenarios.stream().collect(Collectors.toMap(ApiScenario::getName, ApiScenario::getId));
String finalModulePath = modulePath;
scenarios.forEach(scenario -> { scenarios.forEach(scenario -> {
if (existenceNameIdMap.containsKey(scenario.getName())) { if (existenceNameIdMap.containsKey(scenario.getName())) {
scenario.setId(existenceNameIdMap.get(scenario.getName())); scenario.setId(existenceNameIdMap.get(scenario.getName()));
analysisResult.getUpdateApiScenarioData().add(scenario); analysisResult.getUpdateApiScenarioData().add(scenario);
} else { } else {
scenario.setModuleId(modulePathMap.get(finalModulePath).getId());
analysisResult.getInsertApiScenarioData().add(scenario); analysisResult.getInsertApiScenarioData().add(scenario);
} }
}); });

View File

@ -262,6 +262,7 @@ export enum ScenarioStepType {
LOOP_CONTROLLER = 'LOOP_CONTROLLER', // 循环控制器 LOOP_CONTROLLER = 'LOOP_CONTROLLER', // 循环控制器
API = 'API', // 接口定义 API = 'API', // 接口定义
TEST_PLAN_API_CASE = 'TEST_PLAN_API_CASE', // 测试计划接口用例 TEST_PLAN_API_CASE = 'TEST_PLAN_API_CASE', // 测试计划接口用例
JMETER_COMPONENT = 'JMETER_COMPONENT', // Jmeter组件
CUSTOM_REQUEST = 'CUSTOM_REQUEST', // 自定义请求 CUSTOM_REQUEST = 'CUSTOM_REQUEST', // 自定义请求
API_SCENARIO = 'API_SCENARIO', // 场景 API_SCENARIO = 'API_SCENARIO', // 场景
IF_CONTROLLER = 'IF_CONTROLLER', // 条件控制器 IF_CONTROLLER = 'IF_CONTROLLER', // 条件控制器

View File

@ -32,6 +32,7 @@
[ScenarioStepType.ONCE_ONLY_CONTROLLER]: { label: 'apiScenario.onlyOnceControl', color: 'rgba(211, 68, 0, 1)' }, [ScenarioStepType.ONCE_ONLY_CONTROLLER]: { label: 'apiScenario.onlyOnceControl', color: 'rgba(211, 68, 0, 1)' },
[ScenarioStepType.SCRIPT]: { label: 'apiScenario.scriptOperation', color: 'rgba(20, 225, 198, 1)' }, [ScenarioStepType.SCRIPT]: { label: 'apiScenario.scriptOperation', color: 'rgba(20, 225, 198, 1)' },
[ScenarioStepType.CUSTOM_REQUEST]: { label: 'apiScenario.customApi', color: 'rgb(var(--link-4))' }, [ScenarioStepType.CUSTOM_REQUEST]: { label: 'apiScenario.customApi', color: 'rgb(var(--link-4))' },
[ScenarioStepType.JMETER_COMPONENT]: { label: 'apiScenario.jmeterComponent', color: 'rgba(211, 68, 0, 1)' },
}; };
const type = computed(() => { const type = computed(() => {

View File

@ -99,6 +99,7 @@ export default {
'apiScenario.requestScenario': 'Request/Scenario', 'apiScenario.requestScenario': 'Request/Scenario',
'apiScenario.importSystemApi': 'Import System Request', 'apiScenario.importSystemApi': 'Import System Request',
'apiScenario.customApi': 'Custom Request', 'apiScenario.customApi': 'Custom Request',
'apiScenario.jmeterComponent': 'Unknown Component',
'apiScenario.logicControl': 'Logic Control', 'apiScenario.logicControl': 'Logic Control',
'apiScenario.loopControl': 'Loop Controller', 'apiScenario.loopControl': 'Loop Controller',
'apiScenario.tutorial': 'Tutorial', 'apiScenario.tutorial': 'Tutorial',

View File

@ -108,6 +108,7 @@ export default {
'apiScenario.requestScenario': '请求/场景', 'apiScenario.requestScenario': '请求/场景',
'apiScenario.importSystemApi': '导入系统请求', 'apiScenario.importSystemApi': '导入系统请求',
'apiScenario.customApi': '自定义请求', 'apiScenario.customApi': '自定义请求',
'apiScenario.jmeterComponent': '未知组件',
'apiScenario.logicControl': '逻辑控制', 'apiScenario.logicControl': '逻辑控制',
'apiScenario.loopControl': '循环控制器', 'apiScenario.loopControl': '循环控制器',
'apiScenario.tutorial': '使用教程', 'apiScenario.tutorial': '使用教程',