refactor(接口测试): jmx场景导入的部分细节调整
This commit is contained in:
parent
a9a4bb7203
commit
9f36f05452
|
@ -762,6 +762,7 @@
|
|||
SELECT id, name
|
||||
FROM api_scenario
|
||||
WHERE module_id = #{0}
|
||||
AND deleted = false
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.parser.api.dataimport;
|
||||
|
||||
import io.metersphere.api.constants.ApiScenarioStatus;
|
||||
import io.metersphere.api.constants.ApiScenarioStepRefType;
|
||||
import io.metersphere.api.constants.ApiScenarioStepType;
|
||||
import io.metersphere.api.dto.request.MsJMeterComponent;
|
||||
import io.metersphere.api.dto.request.controller.*;
|
||||
|
@ -51,6 +52,7 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser {
|
|||
apiScenarioDetail.setName(scenarioName);
|
||||
apiScenarioDetail.setPriority("P0");
|
||||
apiScenarioDetail.setStatus(ApiScenarioStatus.UNDERWAY.name());
|
||||
apiScenarioDetail.setGrouped(false);
|
||||
apiScenarioDetail.setDeleted(false);
|
||||
apiScenarioDetail.setLatest(true);
|
||||
apiScenarioDetail.setProjectId(projectId);
|
||||
|
@ -72,20 +74,26 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser {
|
|||
apiScenarioStep.setProjectId(projectId);
|
||||
apiScenarioStep.setName(msTestElement.getName());
|
||||
apiScenarioStep.setUniqueId(IDGenerator.nextStr());
|
||||
|
||||
msTestElement.setStepId(apiScenarioStep.getId());
|
||||
msTestElement.setProjectId(apiScenarioStep.getProjectId());
|
||||
byte[] stepBlobContent = null;
|
||||
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.setRefType(ApiScenarioStepRefType.DIRECT.name());
|
||||
msHTTPElement.setCustomizeRequest(true);
|
||||
stepBlobContent = JSON.toJSONString(msTestElement).getBytes();
|
||||
} else if (msTestElement instanceof AbstractMsProtocolTestElement) {
|
||||
} else if (msTestElement instanceof AbstractMsProtocolTestElement msProtocolTestElement) {
|
||||
apiScenarioStep.setStepType(ApiScenarioStepType.CUSTOM_REQUEST.name());
|
||||
msProtocolTestElement.setCustomizeRequest(true);
|
||||
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();
|
||||
} else if (msTestElement instanceof MsJMeterComponent) {
|
||||
apiScenarioStep.setStepType(this.getStepType(msTestElement));
|
||||
apiScenarioStep.setConfig("{}");
|
||||
apiScenarioStep.setConfig(new HashMap<>());
|
||||
apiScenarioStep.setRefType(ApiScenarioStepRefType.DIRECT.name());
|
||||
} else {
|
||||
apiScenarioStep.setStepType(this.getStepType(msTestElement));
|
||||
apiScenarioStep.setConfig(JSON.toJSONString(msTestElement));
|
||||
|
|
|
@ -54,18 +54,6 @@ public class MsTestElementParser {
|
|||
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) {
|
||||
ApiPluginService apiPluginService = CommonBeanFactory.getBean(ApiPluginService.class);
|
||||
assert apiPluginService != null;
|
||||
|
|
|
@ -519,11 +519,13 @@ public class ApiScenarioDataTransferService {
|
|||
if (modulePathMap.containsKey(modulePath)) {
|
||||
List<ApiScenario> existenceScenarios = extApiScenarioMapper.selectBaseInfoByModuleId(modulePathMap.get(modulePath).getId());
|
||||
Map<String, String> existenceNameIdMap = existenceScenarios.stream().collect(Collectors.toMap(ApiScenario::getName, ApiScenario::getId));
|
||||
String finalModulePath = modulePath;
|
||||
scenarios.forEach(scenario -> {
|
||||
if (existenceNameIdMap.containsKey(scenario.getName())) {
|
||||
scenario.setId(existenceNameIdMap.get(scenario.getName()));
|
||||
analysisResult.getUpdateApiScenarioData().add(scenario);
|
||||
} else {
|
||||
scenario.setModuleId(modulePathMap.get(finalModulePath).getId());
|
||||
analysisResult.getInsertApiScenarioData().add(scenario);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -262,6 +262,7 @@ export enum ScenarioStepType {
|
|||
LOOP_CONTROLLER = 'LOOP_CONTROLLER', // 循环控制器
|
||||
API = 'API', // 接口定义
|
||||
TEST_PLAN_API_CASE = 'TEST_PLAN_API_CASE', // 测试计划接口用例
|
||||
JMETER_COMPONENT = 'JMETER_COMPONENT', // Jmeter组件
|
||||
CUSTOM_REQUEST = 'CUSTOM_REQUEST', // 自定义请求
|
||||
API_SCENARIO = 'API_SCENARIO', // 场景
|
||||
IF_CONTROLLER = 'IF_CONTROLLER', // 条件控制器
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
[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.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(() => {
|
||||
|
|
|
@ -99,6 +99,7 @@ export default {
|
|||
'apiScenario.requestScenario': 'Request/Scenario',
|
||||
'apiScenario.importSystemApi': 'Import System Request',
|
||||
'apiScenario.customApi': 'Custom Request',
|
||||
'apiScenario.jmeterComponent': 'Unknown Component',
|
||||
'apiScenario.logicControl': 'Logic Control',
|
||||
'apiScenario.loopControl': 'Loop Controller',
|
||||
'apiScenario.tutorial': 'Tutorial',
|
||||
|
|
|
@ -108,6 +108,7 @@ export default {
|
|||
'apiScenario.requestScenario': '请求/场景',
|
||||
'apiScenario.importSystemApi': '导入系统请求',
|
||||
'apiScenario.customApi': '自定义请求',
|
||||
'apiScenario.jmeterComponent': '未知组件',
|
||||
'apiScenario.logicControl': '逻辑控制',
|
||||
'apiScenario.loopControl': '循环控制器',
|
||||
'apiScenario.tutorial': '使用教程',
|
||||
|
|
Loading…
Reference in New Issue