From b902d8808c3135eb991d94cfe39d5b8bd605492b Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Tue, 29 Oct 2024 19:17:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84jmx=E8=A7=A3=E6=9E=90=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/api/spi/AbstractMsElementConverter.java | 2 +- .../api/dataimport/JmeterParserApiScenario.java | 13 +++++++------ .../api/parser/ms/MsTestElementParser.java | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractMsElementConverter.java b/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractMsElementConverter.java index accd26b234..3b7812b109 100644 --- a/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractMsElementConverter.java +++ b/backend/framework/plugin/plugin-api-sdk/src/main/java/io/metersphere/plugin/api/spi/AbstractMsElementConverter.java @@ -40,7 +40,7 @@ public abstract class AbstractMsElementConverter implemen if (currentHashtree == null) { return; } - for (Object key : currentHashtree.keySet()) { + for (Object key : currentHashtree.list()) { if (key instanceof TestElement testElement) { getConverterFunc.apply(testElement.getClass()).toMsElement(parentMsElement, testElement, currentHashtree); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/dataimport/JmeterParserApiScenario.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/dataimport/JmeterParserApiScenario.java index a0d4fcfef1..356a63beee 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/dataimport/JmeterParserApiScenario.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/dataimport/JmeterParserApiScenario.java @@ -17,7 +17,6 @@ import io.metersphere.api.dto.scenario.ApiScenarioImportDetail; import io.metersphere.api.dto.scenario.ApiScenarioImportRequest; import io.metersphere.api.dto.scenario.ApiScenarioStepRequest; import io.metersphere.api.parser.ApiScenarioImportParser; -import io.metersphere.api.parser.jmeter.xstream.MsSaveService; import io.metersphere.api.parser.ms.MsTestElementParser; import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement; @@ -28,7 +27,8 @@ import io.metersphere.system.uid.IDGenerator; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.jorphan.collections.HashTree; +import org.apache.jmeter.save.SaveService; +import org.apache.jorphan.collections.ListedHashTree; import java.io.InputStream; import java.lang.reflect.Field; @@ -43,8 +43,9 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser { @Override public ApiScenarioImportParseResult parse(InputStream inputSource, ApiScenarioImportRequest request) throws Exception { try { - Object scriptWrapper = MsSaveService.loadElement(inputSource); - HashTree hashTree = this.getHashTree(scriptWrapper); + Object scriptWrapper = SaveService.loadElement(inputSource); + + ListedHashTree hashTree = this.getHashTree(scriptWrapper); MsTestElementParser parser = new MsTestElementParser(); AbstractMsTestElement msTestElement = parser.parse(hashTree); Map polymorphicNameMap = parser.getPolymorphicNameMap(request.getProjectId()); @@ -190,10 +191,10 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser { } } - private HashTree getHashTree(Object scriptWrapper) throws Exception { + private ListedHashTree getHashTree(Object scriptWrapper) throws Exception { Field field = scriptWrapper.getClass().getDeclaredField("testPlan"); field.setAccessible(true); - return (HashTree) field.get(scriptWrapper); + return (ListedHashTree) field.get(scriptWrapper); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/MsTestElementParser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/MsTestElementParser.java index 134141cd1c..a17e255627 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/MsTestElementParser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/MsTestElementParser.java @@ -25,7 +25,7 @@ public class MsTestElementParser { public AbstractMsTestElement parse(HashTree hashTree) { MsScenario msScenario = new MsScenario(); - for (Object key : hashTree.keySet()) { + for (Object key : hashTree.list()) { if (key instanceof TestElement testElement) { MsElementConverterRegister.getConverter(testElement.getClass()).toMsElement(msScenario, testElement, hashTree); }