refactor(接口测试): 重构jmx解析方式
This commit is contained in:
parent
b4c2825ca8
commit
b902d8808c
|
@ -40,7 +40,7 @@ public abstract class AbstractMsElementConverter<T extends TestElement> implemen
|
||||||
if (currentHashtree == null) {
|
if (currentHashtree == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Object key : currentHashtree.keySet()) {
|
for (Object key : currentHashtree.list()) {
|
||||||
if (key instanceof TestElement testElement) {
|
if (key instanceof TestElement testElement) {
|
||||||
getConverterFunc.apply(testElement.getClass()).toMsElement(parentMsElement, testElement, currentHashtree);
|
getConverterFunc.apply(testElement.getClass()).toMsElement(parentMsElement, testElement, currentHashtree);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import io.metersphere.api.dto.scenario.ApiScenarioImportDetail;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioImportRequest;
|
import io.metersphere.api.dto.scenario.ApiScenarioImportRequest;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioStepRequest;
|
import io.metersphere.api.dto.scenario.ApiScenarioStepRequest;
|
||||||
import io.metersphere.api.parser.ApiScenarioImportParser;
|
import io.metersphere.api.parser.ApiScenarioImportParser;
|
||||||
import io.metersphere.api.parser.jmeter.xstream.MsSaveService;
|
|
||||||
import io.metersphere.api.parser.ms.MsTestElementParser;
|
import io.metersphere.api.parser.ms.MsTestElementParser;
|
||||||
import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement;
|
import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement;
|
||||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
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.CollectionUtils;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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.io.InputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -43,8 +43,9 @@ public class JmeterParserApiScenario implements ApiScenarioImportParser {
|
||||||
@Override
|
@Override
|
||||||
public ApiScenarioImportParseResult parse(InputStream inputSource, ApiScenarioImportRequest request) throws Exception {
|
public ApiScenarioImportParseResult parse(InputStream inputSource, ApiScenarioImportRequest request) throws Exception {
|
||||||
try {
|
try {
|
||||||
Object scriptWrapper = MsSaveService.loadElement(inputSource);
|
Object scriptWrapper = SaveService.loadElement(inputSource);
|
||||||
HashTree hashTree = this.getHashTree(scriptWrapper);
|
|
||||||
|
ListedHashTree hashTree = this.getHashTree(scriptWrapper);
|
||||||
MsTestElementParser parser = new MsTestElementParser();
|
MsTestElementParser parser = new MsTestElementParser();
|
||||||
AbstractMsTestElement msTestElement = parser.parse(hashTree);
|
AbstractMsTestElement msTestElement = parser.parse(hashTree);
|
||||||
Map<String, String> polymorphicNameMap = parser.getPolymorphicNameMap(request.getProjectId());
|
Map<String, String> 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 field = scriptWrapper.getClass().getDeclaredField("testPlan");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (HashTree) field.get(scriptWrapper);
|
return (ListedHashTree) field.get(scriptWrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class MsTestElementParser {
|
||||||
|
|
||||||
public AbstractMsTestElement parse(HashTree hashTree) {
|
public AbstractMsTestElement parse(HashTree hashTree) {
|
||||||
MsScenario msScenario = new MsScenario();
|
MsScenario msScenario = new MsScenario();
|
||||||
for (Object key : hashTree.keySet()) {
|
for (Object key : hashTree.list()) {
|
||||||
if (key instanceof TestElement testElement) {
|
if (key instanceof TestElement testElement) {
|
||||||
MsElementConverterRegister.getConverter(testElement.getClass()).toMsElement(msScenario, testElement, hashTree);
|
MsElementConverterRegister.getConverter(testElement.getClass()).toMsElement(msScenario, testElement, hashTree);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue